From f750e6a9c2f8954aeea06eb7e11795d02875371d Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 1 Feb 2021 19:25:14 +0800 Subject: [PATCH 01/36] ExcelBO EmailBO --- pom.xml | 28 ++- ...\344\270\252\344\275\215\347\275\256.java" | 36 ++++ .../algorithm_practice/other/NthPrime.java | 23 -- src/main/java/common/bo/EmailBO.java | 29 +++ src/main/java/common/bo/excel/SheetBO.java | 32 +++ src/main/java/common/bo/excel/WorkBookBO.java | 87 ++++++++ src/main/java/common/model/Person.java | 15 ++ src/main/java/common/model/PersonDTO.java | 15 ++ src/main/java/common/util/CommonBeanUtil.java | 63 ++++++ src/main/java/common/util/EmailUtils.java | 79 +++++++ .../common/util/batchInsert/NameUtil.java | 84 ++++++++ .../common/util/batchInsert/RandomValue.java | 177 +++++++++++++++ ...1_\345\205\254\345\271\263\351\224\201.md" | 204 ++++++++++++++++++ ...36\345\205\254\345\271\263\351\224\201.md" | 52 +++++ ...36\345\205\254\345\271\263\351\224\201.md" | 0 .../README.md" | 17 +- src/main/resources/excel/report.xls | 0 .../CommonBeanUtilTest.java" | 43 ++++ .../\351\233\206\345\220\210/ListTest.java" | 25 ++- .../\351\233\206\345\220\210/MapTest.java" | 2 +- .../\351\233\206\345\220\210/SetTest.java" | 14 +- src/main/test/org/tianbin/temp/DataGen.java | 24 +++ src/main/test/org/tianbin/temp/ExcelGen.java | 69 ++++++ 23 files changed, 1081 insertions(+), 37 deletions(-) delete mode 100644 src/main/java/algorithm_practice/other/NthPrime.java create mode 100644 src/main/java/common/bo/EmailBO.java create mode 100644 src/main/java/common/bo/excel/SheetBO.java create mode 100644 src/main/java/common/bo/excel/WorkBookBO.java create mode 100644 src/main/java/common/model/PersonDTO.java create mode 100644 src/main/java/common/util/CommonBeanUtil.java create mode 100644 src/main/java/common/util/EmailUtils.java create mode 100644 src/main/java/common/util/batchInsert/NameUtil.java create mode 100644 src/main/java/common/util/batchInsert/RandomValue.java create mode 100644 "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" create mode 100644 "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" create mode 100644 "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" create mode 100644 src/main/resources/excel/report.xls create mode 100644 "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" create mode 100644 src/main/test/org/tianbin/temp/DataGen.java create mode 100644 src/main/test/org/tianbin/temp/ExcelGen.java diff --git a/pom.xml b/pom.xml index 50622b0e..05b2c08b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,31 @@ + + + io.github.biezhi + oh-my-email + 0.0.3 + + + + org.apache.poi + poi + 3.17 + + + + com.esotericsoftware + reflectasm + 1.11.9 + + + + org.springframework + spring-beans + 4.3.8.RELEASE + + cglib @@ -99,7 +124,8 @@ com.google.guava guava - 23.0 + 28.1-jre + compile diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" index 8a0b46a8..503cc43e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" @@ -40,7 +40,43 @@ public void testCase() { System.out.println(JSON.toJSONString(searchRange(nums2, target2))); } + /** + * 标准的二分查找 + */ public int[] searchRange(int[] nums, int target) { + int[] res = new int[]{-1, -1}; + if (nums.length == 0) { + return res; + } + + int left = 0; + int right = nums.length - 1; + + while (left <= right) { + int mid = left + (right - left) / 2; + + if (nums[mid] > target) { + right = mid - 1; + } else if (nums[mid] == target) { + res[0] = res[1] = mid; + while (res[0]-1 >= 0 && nums[res[0]-1] == target) { + res[0]--; + } + + while (res[1]+1 < nums.length && nums[res[1]+1] == target) { + res[1]++; + } + + return res; + } else { + left = mid + 1; + } + } + + return res; + } + + public int[] searchRange2(int[] nums, int target) { int lo = 0; int hi = nums.length - 1; int[] result = {-1, -1}; diff --git a/src/main/java/algorithm_practice/other/NthPrime.java b/src/main/java/algorithm_practice/other/NthPrime.java deleted file mode 100644 index 7a329e9b..00000000 --- a/src/main/java/algorithm_practice/other/NthPrime.java +++ /dev/null @@ -1,23 +0,0 @@ -package algorithm_practice.other; - -import junit.framework.TestCase; -import org.junit.Test; - -/* -求第N个质数,求第N个素数 - */ -public class NthPrime extends TestCase { - - @Test - public void testCase() { - int n = 6; - System.out.println(getNthPrime(n)); - } - - /* - - */ - private int getNthPrime(int n) { - return 0; - } -} diff --git a/src/main/java/common/bo/EmailBO.java b/src/main/java/common/bo/EmailBO.java new file mode 100644 index 00000000..704fe8ab --- /dev/null +++ b/src/main/java/common/bo/EmailBO.java @@ -0,0 +1,29 @@ +package common.bo; + +import lombok.AllArgsConstructor; +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.io.File; +import java.util.List; + +/** + * Created by nibnait on 2021/01/27 + */ +@Data +@AllArgsConstructor +@NoArgsConstructor +public class EmailBO { + + private String fromNickName; + + private String toAddress; + + private String ccAddress; + + private String subject; + + private String content; + + private List attachFiles; +} diff --git a/src/main/java/common/bo/excel/SheetBO.java b/src/main/java/common/bo/excel/SheetBO.java new file mode 100644 index 00000000..80d006e9 --- /dev/null +++ b/src/main/java/common/bo/excel/SheetBO.java @@ -0,0 +1,32 @@ +package common.bo.excel; + +import org.apache.poi.hssf.usermodel.HSSFCell; +import org.apache.poi.hssf.usermodel.HSSFRow; +import org.apache.poi.hssf.usermodel.HSSFSheet; + +import java.util.List; + +/** + * Created by nibnait on 2021/01/21 + */ +public class SheetBO { + + private HSSFSheet sheet; + private Integer rowIndex; + + public SheetBO(HSSFSheet sheet) { + this.sheet = sheet; + rowIndex = 0; + } + + public void appendRow(List row) { + HSSFRow hssfRow = sheet.createRow(rowIndex); + HSSFCell hssfCell; + rowIndex += 1; + for (int i = 0; i < row.size(); i++) { + hssfCell = hssfRow.createCell(i); + hssfCell.setCellValue(row.get(i)); + } + } + +} diff --git a/src/main/java/common/bo/excel/WorkBookBO.java b/src/main/java/common/bo/excel/WorkBookBO.java new file mode 100644 index 00000000..21a99377 --- /dev/null +++ b/src/main/java/common/bo/excel/WorkBookBO.java @@ -0,0 +1,87 @@ +package common.bo.excel; + + +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.apache.poi.hssf.usermodel.HSSFSheet; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.springframework.core.io.Resource; +import org.springframework.core.io.support.PathMatchingResourcePatternResolver; +import org.springframework.core.io.support.ResourcePatternResolver; + +import java.io.File; +import java.nio.file.Files; +import java.nio.file.Path; +import java.nio.file.Paths; +import java.util.ArrayList; +import java.util.List; + +/** + * Created by nibnait on 2021/01/21 + */ +@Data +@Slf4j +public class WorkBookBO { + + private HSSFWorkbook workbook; + + private List sheetList = new ArrayList<>(); + + public WorkBookBO() { + workbook = new HSSFWorkbook(); + sheetList.add(new SheetBO(workbook.createSheet("Sheet1"))); + } + + public WorkBookBO(int sheetSize, List> sheetTitle, String... sheetName) { + workbook = new HSSFWorkbook(); + if (CollectionUtils.isEmpty(sheetTitle) || sheetName == null + || sheetTitle.size() != sheetName.length) { + // 直接创建一个默认的sheet + sheetList.add(new SheetBO(workbook.createSheet("Sheet1"))); + return; + } + + for (int i = 0; i < sheetSize; i++) { + HSSFSheet sheet = workbook.createSheet(sheetName[i]); + SheetBO sheetBO = new SheetBO(sheet); + sheetBO.appendRow(sheetTitle.get(i)); + sheetList.add(sheetBO); + } + } + + /** + * 将 workbook 写成文件 + * @param sourceFileName resources/excel 目录下的文件名 + * @param targetFileName targetFileName 重命名文件(可以为空) + */ + public File writeToFile(String sourceFileName, String targetFileName) { + + if (StringUtils.isBlank(sourceFileName)) { + return null; + } + + File sourceFile = null; + String sourceFilePathName = "/excel/" + sourceFileName + ".xls"; + try { + ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); + Resource[] resources = resolver.getResources(sourceFilePathName); + sourceFile = resources[0].getFile(); + workbook.write(sourceFile); + workbook.close(); + resources = resolver.getResources(sourceFilePathName); + sourceFile = resources[0].getFile(); + + if (StringUtils.isNotBlank(targetFileName) && sourceFile != null) { + String path = sourceFile.getPath(); + Path copy = Files.copy(Paths.get(path), Paths.get(path.replaceAll(sourceFileName, targetFileName))); + return copy.toFile(); + } + } catch (Exception e) { + log.error("fail to write excel sourceFile", e); + } + + return sourceFile; + } +} diff --git a/src/main/java/common/model/Person.java b/src/main/java/common/model/Person.java index aeda0eff..057b5c4a 100644 --- a/src/main/java/common/model/Person.java +++ b/src/main/java/common/model/Person.java @@ -4,6 +4,8 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.Objects; + /** * 实体类 * Created by nibnait on 2020-02-24 @@ -16,4 +18,17 @@ public class Person { private String name; private Integer age; + @Override + public boolean equals(Object o) { + if (this == o) return true; + if (o == null || getClass() != o.getClass()) return false; + Person person = (Person) o; + return Objects.equals(name, person.name) && + Objects.equals(age, person.age); + } + + @Override + public int hashCode() { + return Objects.hash(name, age); + } } \ No newline at end of file diff --git a/src/main/java/common/model/PersonDTO.java b/src/main/java/common/model/PersonDTO.java new file mode 100644 index 00000000..3aa4109a --- /dev/null +++ b/src/main/java/common/model/PersonDTO.java @@ -0,0 +1,15 @@ +package common.model; + +import lombok.Data; + +/** + * 实体类 + * Created by nibnait on 2020-02-24 + */ +@Data +public class PersonDTO { + + private String name; + private Integer age; + +} \ No newline at end of file diff --git a/src/main/java/common/util/CommonBeanUtil.java b/src/main/java/common/util/CommonBeanUtil.java new file mode 100644 index 00000000..f7a82fa5 --- /dev/null +++ b/src/main/java/common/util/CommonBeanUtil.java @@ -0,0 +1,63 @@ +package common.util; + +import com.esotericsoftware.reflectasm.MethodAccess; +import org.apache.commons.lang3.StringUtils; +import org.springframework.beans.BeanUtils; + +import java.lang.reflect.Field; +import java.util.ArrayList; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.function.Supplier; + +/** + * Created by nibnait on 2020/12/31 + */ +public class CommonBeanUtil extends BeanUtils { + + private static final ConcurrentMap localCache = new ConcurrentHashMap<>(); + + public static MethodAccess get(Class clazz) { + if (localCache.containsKey(clazz)) { + return localCache.get(clazz); + } + + MethodAccess methodAccess = MethodAccess.get(clazz); + localCache.putIfAbsent(clazz, methodAccess); + return methodAccess; + } + + public static T copyProperties(S source, Supplier targetSupplier) { + T target = targetSupplier.get(); + if (source == null) { + return target; + } + + MethodAccess sourceMethodAccess = get(source.getClass()); + MethodAccess targetMethodAccess = get(target.getClass()); + Field[] declaredFields = source.getClass().getDeclaredFields(); + for (Field field : declaredFields) { + String name = field.getName(); + Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); + try { + targetMethodAccess.invoke(target, "set" + StringUtils.capitalize(name), value); + } catch (Exception e) { + // source 中未设置 get 方法的字段,会直接跳过 + // target 中没有 source 中的字段,也会直接跳过 + } + } + + return target; + } + + public static List copyListProperties(List sources, Supplier targetSupplier) { + List list = new ArrayList<>(sources.size()); + for (S source : sources) { + T target = copyProperties(source, targetSupplier); + list.add(target); + } + return list; + } + +} \ No newline at end of file diff --git a/src/main/java/common/util/EmailUtils.java b/src/main/java/common/util/EmailUtils.java new file mode 100644 index 00000000..4cdfe554 --- /dev/null +++ b/src/main/java/common/util/EmailUtils.java @@ -0,0 +1,79 @@ +package common.util; + +import common.bo.EmailBO; +import io.github.biezhi.ome.OhMyEmail; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.io.File; +import java.util.List; +import java.util.Properties; + +@Slf4j +public class EmailUtils { + + + private static final String COMP_EMAIL = "w@tianbin.org"; + private static final String COMP_PW = "xxx"; + + private static final String SENDER_NAME = "系统"; + + + public static void initEmailCfg(){ + Properties props = new Properties(); + props.setProperty("username", COMP_EMAIL); + props.setProperty("password", COMP_PW); + // 开启debug调试 + props.setProperty("mail.debug", "false"); //false + // 发送服务器需要身份验证 + props.setProperty("mail.smtp.auth", "true"); + // 设置邮件服务器主机名 + props.setProperty("mail.host", "smtp.partner.outlook.cn"); + props.setProperty("mail.smtp.host", "smtp.partner.outlook.cn"); + // 发送邮件协议名称 + props.setProperty("mail.transport.protocol", "smtp"); + props.setProperty("mail.smtp.port", "587"); + props.put("mail.smtp.starttls.enable", "true"); + + OhMyEmail.config(props); + } + + + public static void sendEmail(EmailBO emailBO) { + OhMyEmail.config(OhMyEmail.SMTP_ENT_QQ(false), COMP_EMAIL, COMP_PW); + + if (StringUtils.isBlank(emailBO.getToAddress()) || StringUtils.isBlank(emailBO.getSubject())) { + return; + } + + initEmailCfg(); + + String fromNickName = emailBO.getFromNickName(); + if (StringUtils.isBlank(fromNickName)) { + fromNickName = SENDER_NAME; + } + + try { + OhMyEmail ohMyEmail = OhMyEmail.subject(emailBO.getSubject()) + .from(fromNickName) + .to(emailBO.getToAddress()); + + if (StringUtils.isNotBlank(emailBO.getCcAddress())) { + ohMyEmail.cc(emailBO.getCcAddress()); + } + List files = emailBO.getAttachFiles(); + if(files != null && !files.isEmpty()){ + for(File file:files){ + ohMyEmail.attach(file); + } + } + + ohMyEmail.html(emailBO.getContent()); + ohMyEmail.send(); + } catch (Exception e) { + log.error("EmailUtils.sendEmailAttachFiles error ", e); + } + + } + +} diff --git a/src/main/java/common/util/batchInsert/NameUtil.java b/src/main/java/common/util/batchInsert/NameUtil.java new file mode 100644 index 00000000..f0bda852 --- /dev/null +++ b/src/main/java/common/util/batchInsert/NameUtil.java @@ -0,0 +1,84 @@ +package common.util.batchInsert; + +import java.io.UnsupportedEncodingException; +import java.util.Random; + +/** + * 随机生成姓名的工具类 + * Created by nibnait on 2020/11/29 + */ +public class NameUtil { + + /** + * 随机生成一个中文姓名 + * @return + */ + public static String getRandomName(int i){ + Random random=new Random(); + /* 598 百家姓 */ + /*String[] Surname= {"赵","钱","孙","李","周","吴","郑","王","冯","陈","褚","卫","蒋","沈","韩","杨","朱","秦","尤","许", + "何","吕","施","张","孔","曹","严","华","金","魏","陶","姜","戚","谢","邹","喻","柏","水","窦","章","云","苏","潘","葛","奚","范","彭","郎", + "鲁","韦","昌","马","苗","凤","花","方","俞","任","袁","柳","酆","鲍","史","唐","费","廉","岑","薛","雷","贺","倪","汤","滕","殷", + "罗","毕","郝","邬","安","常","乐","于","时","傅","皮","卞","齐","康","伍","余","元","卜","顾","孟","平","黄","和", + "穆","萧","尹","姚","邵","湛","汪","祁","毛","禹","狄","米","贝","明","臧","计","伏","成","戴","谈","宋","茅","庞","熊","纪","舒", + "屈","项","祝","董","梁","杜","阮","蓝","闵","席","季","麻","强","贾","路","娄","危","江","童","颜","郭","梅","盛","林","刁","钟", + "徐","邱","骆","高","夏","蔡","田","樊","胡","凌","霍","虞","万","支","柯","昝","管","卢","莫","经","房","裘","缪","干","解","应", + "宗","丁","宣","贲","邓","郁","单","杭","洪","包","诸","左","石","崔","吉","钮","龚","程","嵇","邢","滑","裴","陆","荣","翁","荀", + "羊","于","惠","甄","曲","家","封","芮","羿","储","靳","汲","邴","糜","松","井","段","富","巫","乌","焦","巴","弓","牧","隗","山", + "谷","车","侯","宓","蓬","全","郗","班","仰","秋","仲","伊","宫","宁","仇","栾","暴","甘","钭","厉","戎","祖","武","符","刘","景", + "詹","束","龙","叶","幸","司","韶","郜","黎","蓟","溥","印","宿","白","怀","蒲","邰","从","鄂","索","咸","籍","赖","卓","蔺","屠", + "蒙","池","乔","阴","郁","胥","能","苍","双","闻","莘","党","翟","谭","贡","劳","逄","姬","申","扶","堵","冉","宰","郦","雍","却", + "璩","桑","桂","濮","牛","寿","通","边","扈","燕","冀","浦","尚","农","温","别","庄","晏","柴","瞿","阎","充","慕","连","茹","习", + "宦","艾","鱼","容","向","古","易","慎","戈","廖","庾","终","暨","居","衡","步","都","耿","满","弘","匡","国","文","寇","广","禄", + "阙","东","欧","殳","沃","利","蔚","越","夔","隆","师","巩","厍","聂","晁","勾","敖","融","冷","訾","辛","阚","那","简","饶","空", + "曾","毋","沙","乜","养","鞠","须","丰","巢","关","蒯","相","查","后","荆","红","游","郏","竺","权","逯","盖","益","桓","公","仉", + "督","岳","帅","缑","亢","况","郈","有","琴","归","海","晋","楚","闫","法","汝","鄢","涂","钦","商","牟","佘","佴","伯","赏","墨", + "哈","谯","篁","年","爱","阳","佟","言","福","南","火","铁","迟","漆","官","冼","真","展","繁","檀","祭","密","敬","揭","舜","楼", + "疏","冒","浑","挚","胶","随","高","皋","原","种","练","弥","仓","眭","蹇","覃","阿","门","恽","来","綦","召","仪","风","介","巨", + "木","京","狐","郇","虎","枚","抗","达","杞","苌","折","麦","庆","过","竹","端","鲜","皇","亓","老","是","秘","畅","邝","还","宾", + "闾","辜","纵","侴","万俟","司马","上官","欧阳","夏侯","诸葛","闻人","东方","赫连","皇甫","羊舌","尉迟","公羊","澹台","公冶","宗正", + "濮阳","淳于","单于","太叔","申屠","公孙","仲孙","轩辕","令狐","钟离","宇文","长孙","慕容","鲜于","闾丘","司徒","司空","兀官","司寇", + "南门","呼延","子车","颛孙","端木","巫马","公西","漆雕","车正","壤驷","公良","拓跋","夹谷","宰父","谷梁","段干","百里","东郭","微生", + "梁丘","左丘","东门","西门","南宫","第五","公仪","公乘","太史","仲长","叔孙","屈突","尔朱","东乡","相里","胡母","司城","张廖","雍门", + "毋丘","贺兰","綦毋","屋庐","独孤","南郭","北宫","王孙"};*/ + + String[] Surname= {"黄","郑","孙","李","周","吴","刘","王","冯","陈","柏","卫","蒋","沈","韩","杨","朱","秦","欧阳","许"}; + + int index=random.nextInt(Surname.length-1); + String name =""; + name = Surname[index]; //获得一个随机的姓氏 + + /* 从常用字中选取一个或两个字作为名 */ + if(random.nextBoolean()){ + name+=getChinese()+getChinese(); + }else { + name+=getChinese(); + } + return name; + } + + /** + * 随机获取一个汉字 + * @return + */ + public static String getChinese() { + String str = null; + int highPos, lowPos; + Random random = new Random(); + highPos = (176 + Math.abs(random.nextInt(71)));//区码,0xA0打头,从第16区开始,即0xB0=11*16=176,16~55一级汉字,56~87二级汉字 + random=new Random(); + lowPos = 161 + Math.abs(random.nextInt(94));//位码,0xA0打头,范围第1~94列 + + byte[] bArr = new byte[2]; + bArr[0] = (new Integer(highPos)).byteValue(); + bArr[1] = (new Integer(lowPos)).byteValue(); + try { + str = new String(bArr, "GB2312"); //区位码组合成汉字 + } catch (UnsupportedEncodingException e) { + e.printStackTrace(); + } + return str; + } + +} + diff --git a/src/main/java/common/util/batchInsert/RandomValue.java b/src/main/java/common/util/batchInsert/RandomValue.java new file mode 100644 index 00000000..65590e93 --- /dev/null +++ b/src/main/java/common/util/batchInsert/RandomValue.java @@ -0,0 +1,177 @@ +package common.util.batchInsert; + +import java.io.File; +import java.io.FileOutputStream; +import java.nio.ByteBuffer; +import java.nio.channels.FileChannel; +import java.util.HashMap; +import java.util.Map; + +public class RandomValue { + + public static String base = "abcdefghijklmnopqrstuvwxyz0123456789"; + private static String firstName="赵钱孙李周吴郑王冯陈褚卫蒋沈韩杨朱秦尤许何吕施张孔曹严华金魏陶姜戚谢邹喻柏水窦章云苏潘葛奚范彭郎鲁韦昌马苗凤花方俞任袁柳酆鲍史唐费廉岑薛雷贺倪汤滕殷罗毕郝邬安常乐于时傅皮卞齐康伍余元卜顾孟平黄和穆萧尹姚邵湛汪祁毛禹狄米贝明臧计伏成戴谈宋茅庞熊纪舒屈项祝董梁杜阮蓝闵席季麻强贾路娄危江童颜郭梅盛林刁钟徐邱骆高夏蔡田樊胡凌霍虞万支柯咎管卢莫经房裘缪干解应宗宣丁贲邓郁单杭洪包诸左石崔吉钮龚程嵇邢滑裴陆荣翁荀羊於惠甄魏加封芮羿储靳汲邴糜松井段富巫乌焦巴弓牧隗山谷车侯宓蓬全郗班仰秋仲伊宫宁仇栾暴甘钭厉戎祖武符刘姜詹束龙叶幸司韶郜黎蓟薄印宿白怀蒲台从鄂索咸籍赖卓蔺屠蒙池乔阴郁胥能苍双闻莘党翟谭贡劳逄姬申扶堵冉宰郦雍却璩桑桂濮牛寿通边扈燕冀郏浦尚农温别庄晏柴瞿阎充慕连茹习宦艾鱼容向古易慎戈廖庚终暨居衡步都耿满弘匡国文寇广禄阙东殴殳沃利蔚越夔隆师巩厍聂晁勾敖融冷訾辛阚那简饶空曾毋沙乜养鞠须丰巢关蒯相查后江红游竺权逯盖益桓公万俟司马上官欧阳夏侯诸葛闻人东方赫连皇甫尉迟公羊澹台公冶宗政濮阳淳于仲孙太叔申屠公孙乐正轩辕令狐钟离闾丘长孙慕容鲜于宇文司徒司空亓官司寇仉督子车颛孙端木巫马公西漆雕乐正壤驷公良拓拔夹谷宰父谷粱晋楚阎法汝鄢涂钦段干百里东郭南门呼延归海羊舌微生岳帅缑亢况后有琴梁丘左丘东门西门商牟佘佴伯赏南宫墨哈谯笪年爱阳佟第五言福百家姓续"; + private static String girl="秀娟英华慧巧美娜静淑惠珠翠雅芝玉萍红娥玲芬芳燕彩春菊兰凤洁梅琳素云莲真环雪荣爱妹霞香月莺媛艳瑞凡佳嘉琼勤珍贞莉桂娣叶璧璐娅琦晶妍茜秋珊莎锦黛青倩婷姣婉娴瑾颖露瑶怡婵雁蓓纨仪荷丹蓉眉君琴蕊薇菁梦岚苑婕馨瑗琰韵融园艺咏卿聪澜纯毓悦昭冰爽琬茗羽希宁欣飘育滢馥筠柔竹霭凝晓欢霄枫芸菲寒伊亚宜可姬舒影荔枝思丽 晨花函妮蓓彤静漫呈碧" + + "梦雯昭冰娅楠月菲娅欣" + + "彦敏蕾雪初寒紫林欣美" + + "璐美妍阳花琛华初慧月" + + "欣初雪锦紫婷枫沛鑫雪" + + "晨漫娜婷初呈彦格雨萱" + + "柔菲彩玥梅阳莲婧淑家" + + "玥柔雪昭美静怡诗呈华" + + "淑沛采妍静昭玉祥梅怡" + + "橘萱锦月杉馨彩婧芙萱" + + "昭花彩姿慧雅格漫彩雪" + + "莲雅林怡彦枫初月璐楠" + + "雨初昭香克采梅梦莉美" + + "呈心帛静婧雪彩娜茜雅" + + "梦妍梦帆雪惠雪蔚云栀" + + "雅美琛枫灵初雅洁露娅" + + "彤漫旭枫锦娅婧漫凡雪" + + "文洁霞曦静芝凡怡桂岚" + + "茹冬芙锦帛锦楠桃曼璐" + + "花香寒媛冬优呈霞梅露" + + "函嘉薇娅梦漫华玥弦冰" + + "锦梦冬彬芝蕾琪美彩枫" + + "婷枫彬桂彩菡楠彤可锦" + + "茹彩祥枫妍初梅楠歆妮" + + "文彤莲静雪霞静馨华采" + + "香珍菲锦彩玲克婷可采" + + "璇昭呈婧香茜美晨彤枫" + + "冰莲家嘉玥锦舒梦蔚娜" + + "漫萱鹤涵美丽玉萱美彩" + + "玉彩彩昕梅初彩锦钰旭" + + "紫淑楠鑫桐曦玥倩初云" + + "惠萱春珠初雅鸿敏芙彩" + + "芙玥静梅彩蕾采玥菲美" + + "妍彩可玉桂橘嘉紫婷钰" + + "静桂薇桂桐鸿俊欣初芝" + + "香凡香欣采蔚栀璟昭梅" + + "雯雪雪婧枫梦雅馨静雅" + + "彩芳茹阳云薇莲曦婷阳" + + "鑫慧芳橘韵彦柏珊雨梅" + + "林琬妮倩美碧彩彩蓓沛" + + "正月芸晨初锦莲馨婷寒" + + "萱雪萱柏枫欣钰锦楠惠" + + "莲露蔚婷华香馨彦琬旭" + + "璐采玥婷家雯瑶雅妍雅" + + "菲函钰薇媛沛帆月初诗" + + "桂蕾华韵美玥文莲鹤柏" + + "依菡姿丽锦菡美梓雪蕾" + + "欢玉锦凌婷紫弦心彩嘉"; + private static String boy="加诚晨信振泽斌晨初骞然裕潍震运安畅驰骏材天晨谷骞延弘烁铭濡贤骏腾运运龙宇强涛帝宇胤鸿辰钊骞嘉谛华振驰辰年柔凯家康运星海礼骏允运良权初锋坤振福奇博俊皓祥运骏振胤辰锐起成凯韦福运信帝强驰楷腾礼星骏晨辰俊休栋骏颜良荣铭枫国骏柏奇运谛郁尧盛骏暄腾驰星辰星宇嘉星逸天震祯震振锟运骞康星槐震祜谷树林加星谛成福晨骏升荣振星嘉郁骏杰辰禧鹏祯鑫成振琛卓运哲运枫祯辰天钊强恒晨星轩龙邦文树梓驰材骏鹏信爵驰喆震盛骏博盛骏晨彬树翰柔祯驰振帆祥宇骏澄芃辰帆海诚宇祯逸韦泽嘉辰鹏睿梓胤轩运初驰振潍骏楷子栋树爵然博槐晓爵杞荣星骞振轩骏海骏年枫运骏栋睿骏运辰晨康星鸿芃翱柔安彬翱楷逸栋潍天骏弘奇骞年濡骏锦轩桀运日浩骏寅涛逸晨辰然锦骞星嘉骏宇辰佑星初树斌鸿骏皓骏良初逸杰骞杞福运运振良梓振振泽辰升翱宇伟康震晨祥星信阳振康辰泽潍平骏震博骏禧平子晨柏翰濡鸿文桀升郁邦鹤晖帆皓允凯峰吉博寅天骞佑升良栋伟刚勇毅俊峰强军平保东文辉力明永健世广志义兴良海山仁波宁贵福生龙元全国胜学祥才发武新利清飞彬富顺信子杰涛昌成康星光天达安岩中茂进林有坚和彪博诚先敬震振壮会思群豪心邦承乐绍功松善厚庆磊民友裕河哲江超浩亮政谦亨奇固之轮翰朗伯宏言若鸣朋斌梁栋维启克伦翔旭鹏泽晨辰士以建家致树炎德行时泰盛雄琛钧冠策腾楠榕风航弘"; + private static String[] road="重庆大厦,黑龙江路,十梅庵街,遵义路,湘潭街,瑞金广场,仙山街,仙山东路,仙山西大厦,白沙河路,赵红广场,机场路,民航街,长城南路,流亭立交桥,虹桥广场,长城大厦,礼阳路,风岗街,中川路,白塔广场,兴阳路,文阳街,绣城路,河城大厦,锦城广场,崇阳街,华城路,康城街,正阳路,和阳广场,中城路,江城大厦,顺城路,安城街,山城广场,春城街,国城路,泰城街,德阳路,明阳大厦,春阳路,艳阳街,秋阳路,硕阳街,青威高速,瑞阳街,丰海路,双元大厦,惜福镇街道,夏庄街道,古庙工业园,中山街,太平路,广西街,潍县广场,博山大厦,湖南路,济宁街,芝罘路,易州广场,荷泽四路,荷泽二街,荷泽一路,荷泽三大厦,观海二广场,广西支街,观海一路,济宁支街,莒县路,平度广场,明水路,蒙阴大厦,青岛路,湖北街,江宁广场,郯城街,天津路,保定街,安徽路,河北大厦,黄岛路,北京街,莘县路,济南街,宁阳广场,日照街,德县路,新泰大厦,荷泽路,山西广场,沂水路,肥城街,兰山路,四方街,平原广场,泗水大厦,浙江路,曲阜街,寿康路,河南广场,泰安路,大沽街,红山峡支路,西陵峡一大厦,台西纬一广场,台西纬四街,台西纬二路,西陵峡二街,西陵峡三路,台西纬三广场,台西纬五路,明月峡大厦,青铜峡路,台西二街,观音峡广场,瞿塘峡街,团岛二路,团岛一街,台西三路,台西一大厦,郓城南路,团岛三街,刘家峡路,西藏二街,西藏一广场,台西四街,三门峡路,城武支大厦,红山峡路,郓城北广场,龙羊峡路,西陵峡街,台西五路,团岛四街,石村广场,巫峡大厦,四川路,寿张街,嘉祥路,南村广场,范县路,西康街,云南路,巨野大厦,西江广场,鱼台街,单县路,定陶街,滕县路,钜野广场,观城路,汶上大厦,朝城路,滋阳街,邹县广场,濮县街,磁山路,汶水街,西藏路,城武大厦,团岛路,南阳街,广州路,东平街,枣庄广场,贵州街,费县路,南海大厦,登州路,文登广场,信号山支路,延安一街,信号山路,兴安支街,福山支广场,红岛支大厦,莱芜二路,吴县一街,金口三路,金口一广场,伏龙山路,鱼山支街,观象二路,吴县二大厦,莱芜一广场,金口二街,海阳路,龙口街,恒山路,鱼山广场,掖县路,福山大厦,红岛路,常州街,大学广场,龙华街,齐河路,莱阳街,黄县路,张店大厦,祚山路,苏州街,华山路,伏龙街,江苏广场,龙江街,王村路,琴屿大厦,齐东路,京山广场,龙山路,牟平街,延安三路,延吉街,南京广场,东海东大厦,银川西路,海口街,山东路,绍兴广场,芝泉路,东海中街,宁夏路,香港西大厦,隆德广场,扬州街,郧阳路,太平角一街,宁国二支路,太平角二广场,天台东一路,太平角三大厦,漳州路一路,漳州街二街,宁国一支广场,太平角六街,太平角四路,天台东二街,太平角五路,宁国三大厦,澳门三路,江西支街,澳门二路,宁国四街,大尧一广场,咸阳支街,洪泽湖路,吴兴二大厦,澄海三路,天台一广场,新湛二路,三明北街,新湛支路,湛山五街,泰州三广场,湛山四大厦,闽江三路,澳门四街,南海支路,吴兴三广场,三明南路,湛山二街,二轻新村镇,江南大厦,吴兴一广场,珠海二街,嘉峪关路,高邮湖街,湛山三路,澳门六广场,泰州二路,东海一大厦,天台二路,微山湖街,洞庭湖广场,珠海支街,福州南路,澄海二街,泰州四路,香港中大厦,澳门五路,新湛三街,澳门一路,正阳关街,宁武关广场,闽江四街,新湛一路,宁国一大厦,王家麦岛,澳门七广场,泰州一路,泰州六街,大尧二路,青大一街,闽江二广场,闽江一大厦,屏东支路,湛山一街,东海西路,徐家麦岛函谷关广场,大尧三路,晓望支街,秀湛二路,逍遥三大厦,澳门九广场,泰州五街,澄海一路,澳门八街,福州北路,珠海一广场,宁国二路,临淮关大厦,燕儿岛路,紫荆关街,武胜关广场,逍遥一街,秀湛四路,居庸关街,山海关路,鄱阳湖大厦,新湛路,漳州街,仙游路,花莲街,乐清广场,巢湖街,台南路,吴兴大厦,新田路,福清广场,澄海路,莆田街,海游路,镇江街,石岛广场,宜兴大厦,三明路,仰口街,沛县路,漳浦广场,大麦岛,台湾街,天台路,金湖大厦,高雄广场,海江街,岳阳路,善化街,荣成路,澳门广场,武昌路,闽江大厦,台北路,龙岩街,咸阳广场,宁德街,龙泉路,丽水街,海川路,彰化大厦,金田路,泰州街,太湖路,江西街,泰兴广场,青大街,金门路,南通大厦,旌德路,汇泉广场,宁国路,泉州街,如东路,奉化街,鹊山广场,莲岛大厦,华严路,嘉义街,古田路,南平广场,秀湛路,长汀街,湛山路,徐州大厦,丰县广场,汕头街,新竹路,黄海街,安庆路,基隆广场,韶关路,云霄大厦,新安路,仙居街,屏东广场,晓望街,海门路,珠海街,上杭路,永嘉大厦,漳平路,盐城街,新浦路,新昌街,高田广场,市场三街,金乡东路,市场二大厦,上海支路,李村支广场,惠民南路,市场纬街,长安南路,陵县支街,冠县支广场,小港一大厦,市场一路,小港二街,清平路,广东广场,新疆路,博平街,港通路,小港沿,福建广场,高唐街,茌平路,港青街,高密路,阳谷广场,平阴路,夏津大厦,邱县路,渤海街,恩县广场,旅顺街,堂邑路,李村街,即墨路,港华大厦,港环路,馆陶街,普集路,朝阳街,甘肃广场,港夏街,港联路,陵县大厦,上海路,宝山广场,武定路,长清街,长安路,惠民街,武城广场,聊城大厦,海泊路,沧口街,宁波路,胶州广场,莱州路,招远街,冠县路,六码头,金乡广场,禹城街,临清路,东阿街,吴淞路,大港沿,辽宁路,棣纬二大厦,大港纬一路,贮水山支街,无棣纬一广场,大港纬三街,大港纬五路,大港纬四街,大港纬二路,无棣二大厦,吉林支路,大港四街,普集支路,无棣三街,黄台支广场,大港三街,无棣一路,贮水山大厦,泰山支路,大港一广场,无棣四路,大连支街,大港二路,锦州支街,德平广场,高苑大厦,长山路,乐陵街,临邑路,嫩江广场,合江路,大连街,博兴路,蒲台大厦,黄台广场,城阳街,临淄路,安邱街,临朐路,青城广场,商河路,热河大厦,济阳路,承德街,淄川广场,辽北街,阳信路,益都街,松江路,流亭大厦,吉林路,恒台街,包头路,无棣街,铁山广场,锦州街,桓台路,兴安大厦,邹平路,胶东广场,章丘路,丹东街,华阳路,青海街,泰山广场,周村大厦,四平路,台东西七街,台东东二路,台东东七广场,台东西二路,东五街,云门二路,芙蓉山村,延安二广场,云门一街,台东四路,台东一街,台东二路,杭州支广场,内蒙古路,台东七大厦,台东六路,广饶支街,台东八广场,台东三街,四平支路,郭口东街,青海支路,沈阳支大厦,菜市二路,菜市一街,北仲三路,瑞云街,滨县广场,庆祥街,万寿路,大成大厦,芙蓉路,历城广场,大名路,昌平街,平定路,长兴街,浦口广场,诸城大厦,和兴路,德盛街,宁海路,威海广场,东山路,清和街,姜沟路,雒口大厦,松山广场,长春街,昆明路,顺兴街,利津路,阳明广场,人和路,郭口大厦,营口路,昌邑街,孟庄广场,丰盛街,埕口路,丹阳街,汉口路,洮南大厦,桑梓路,沾化街,山口路,沈阳街,南口广场,振兴街,通化路,福寺大厦,峄县路,寿光广场,曹县路,昌乐街,道口路,南九水街,台湛广场,东光大厦,驼峰路,太平山,标山路,云溪广场,太清路".split(","); + private static final String[] email_suffix="@gmail.com,@yahoo.com,@msn.com,@hotmail.com,@aol.com,@ask.com,@live.com,@qq.com,@0355.net,@163.com,@163.net,@263.net,@3721.net,@yeah.net,@googlemail.com,@126.com,@sina.com,@sohu.com,@yahoo.com.cn".split(","); + + public static int getNum(int start,int end) { + return (int)(Math.random()*(end-start+1)+start); + } + + /** + * 返回Email + * @param lMin 最小长度 + * @param lMax 最大长度 + * @return + */ + public static String getEmail(int lMin,int lMax) { + int length=getNum(lMin,lMax); + StringBuffer sb = new StringBuffer(); + for (int i = 0; i < length; i++) { + int number = (int)(Math.random()*base.length()); + sb.append(base.charAt(number)); + } + sb.append(email_suffix[(int)(Math.random()*email_suffix.length)]); + return sb.toString(); + } + + /** + * 返回手机号码 + */ + private static String[] telFirst="134,135,136,137,138,139,150,151,152,157,158,159,130,131,132,155,156,133,153".split(","); + private static String getTel() { + int index=getNum(0,telFirst.length-1); + String first=telFirst[index]; + String second=String.valueOf(getNum(1,888)+10000).substring(1); + String third=String.valueOf(getNum(1,9100)+10000).substring(1); + return first+second+third; + } + + /** + * 返回中文姓名 + */ + private static String name_sex = ""; + private static String getChineseName() { + int index=getNum(0, firstName.length()-1); + String first=firstName.substring(index, index+1); + int sex=getNum(0,1); + String str=boy; + int length=boy.length(); + if(sex==0){ + str=girl; + length=girl.length(); + name_sex = "女"; + }else { + name_sex="男"; + } + index=getNum(0,length-1); + String second=str.substring(index, index+1); + int hasThird=getNum(0,1); + String third=""; + if(hasThird==1){ + index=getNum(0,length-1); + third=str.substring(index, index+1); + } + return first+second+third; + } + + /** + * 返回地址 + * @return + */ + private static String getRoad() { + int index=getNum(0,road.length-1); + String first=road[index]; + String second=String.valueOf(getNum(11,150))+"号"; + String third="-"+getNum(1,20)+"-"+getNum(1,10); + return first+second+third; + } + + /** + * 数据封装 + * @return + */ + public static Map getAddress() { + Map map=new HashMap(); + map.put("name", getChineseName()); + map.put("gender", name_sex); + map.put("road", getRoad()); + map.put("phone", getTel()); + map.put("email", getEmail(6,9)); + return map; + } + + public static void main(String[] args) throws Exception{ + StringBuffer stringBuffer = new StringBuffer(); + for (int i = 0; i < 100; i++) { + Map address = getAddress(); + stringBuffer.append("insert into student(address,gender,name,phone,email) values"+"(" +"'"+ address.get("road")+"'" + "," +"'"+ address.get("gender")+"'" + ","+"'" + address.get("name") +"'"+ "," +"'"+ address.get("phone") +"'"+ "," +"'"+ address.get("email")+"'" + ");\r\n"); +// System.out.println(getEmailName(6,9)); + } + System.out.println(stringBuffer); + + +// File file = new File("/Users/nibnait/Desktop/student.sql"); +// if (!file.exists()) { +// file.createNewFile(); +// } +// FileOutputStream fos = new FileOutputStream(file); +// FileChannel channel = fos.getChannel(); +// ByteBuffer byteBuffer = ByteBuffer.allocateDirect(stringBuffer.length()); +// byteBuffer.put(stringBuffer.toString().getBytes()); +// byteBuffer.flip(); +// channel.write(byteBuffer); +// fos.write(stringBuffer.toString().getBytes()); + } + + +} diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" new file mode 100644 index 00000000..eb4a9840 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" @@ -0,0 +1,204 @@ + +## lock (sync.lock()) + +```java + final void lock() { + acquire(1); + } + + public final void acquire(int arg) { + // tryAcquire == true:获取锁成功。啥也不干 + // tryAcquire == false: 获取锁失败,addWaiter(),acquireQueued + if (!tryAcquire(arg) && + acquireQueued(addWaiter(Node.EXCLUSIVE), arg)) { + + selfInterrupt(); + } + } + + protected final boolean tryAcquire(int acquires) { + final Thread current = Thread.currentThread(); + int c = getState(); + if (c == 0) { + // c == 0 && 没有等待队列 && casState(0, 1)成功: + if (!hasQueuedPredecessors() && + compareAndSetState(0, acquires)) { + setExclusiveOwnerThread(current); + return true; + } + } else if (current == getExclusiveOwnerThread()) { + // 重入的情况:state+1 + int nextc = c + acquires; + if (nextc < 0) + throw new Error("Maximum lock count exceeded"); + setState(nextc); + return true; + } + return false; + } + + private Node addWaiter(Node mode) { + // Node.EXCLUSIVE = null; 独占锁 + Node node = new Node(Thread.currentThread(), mode); + + // tail != null,说明其他线程抢先casTail成功,当前node需要放到 tail的后面,重新casTail(tail, node) + Node pred = tail; + if (pred != null) { + node.prev = pred; + if (compareAndSetTail(pred, node)) { + pred.next = node; + return node; + } + } + + // 将node 链到 等待队列的末尾。 + enq(node); + return node; + } + + private Node enq(final Node node) { + for (;;) { + Node t = tail; + if (t == null) { + // 第一次进入for循环,将 head 和 tail 都指向 new Node() + if (compareAndSetHead(new Node())) + tail = head; + } else { + // 第二次进入for循环,node.prev = t, casTail(t, node), t.next = node + node.prev = t; + if (compareAndSetTail(t, node)) { + t.next = node; + return t; + } + } + } + } + + final boolean acquireQueued(final Node node, int arg) { + boolean failed = true; + try { + boolean interrupted = false; + for (;;) { + // p = node.prev + final Node p = node.predecessor(); + + // 如果 node.prev == head,重新 tryAcquire + if (p == head && tryAcquire(arg)) { + setHead(node); + p.next = null; // help GC + failed = false; + return interrupted; + } + + // 抢锁失败之后 判断是否要要阻塞 + if (shouldParkAfterFailedAcquire(p, node) && + parkAndCheckInterrupt()) + interrupted = true; + } + } finally { + if (failed) + cancelAcquire(node); + } + } + + private static boolean shouldParkAfterFailedAcquire(Node pred, Node node) { + int ws = pred.waitStatus; + if (ws == Node.SIGNAL) + /* + * pred.waitStatus == SIGNAL == -1,prev(前一个节点)已经被唤醒,所以node(当前节点)可以安全的被阻塞 + */ + return true; + if (ws > 0) { + /* + * prev节点已经被取消,需要去判断 prev.prev.waitStatus, + * 直到prev.waitStatus <= 0: prev.next = node; + * + * 即:循环清除掉所有已经取消的节点。 + */ + do { + node.prev = pred = pred.prev; + } while (pred.waitStatus > 0); + pred.next = node; + } else { + /* + * waitStatus must be 0 or PROPAGATE(-3). Indicate that we + * need a signal, but don't park yet. Caller will need to + * retry to make sure it cannot acquire before parking. + * + * casWaitStatus(prev, ws, SIGNAL) + * 死循环 将prev(前一个节点) 设为SIGNAL,直到设置成功,return true + */ + compareAndSetWaitStatus(pred, ws, Node.SIGNAL); + } + return false; + } + +``` + + +## unlock(sync.release(1)) + +```java + public void unlock() { + sync.release(1); + } + + public final boolean release(int arg) { + if (tryRelease(arg)) { + Node h = head; + if (h != null && h.waitStatus != 0) + unparkSuccessor(h); + return true; + } + return false; + } + + // 可重入锁 + protected final boolean tryRelease(int releases) { + int c = getState() - releases; + if (Thread.currentThread() != getExclusiveOwnerThread()) + throw new IllegalMonitorStateException(); + boolean free = false; + if (c == 0) { + free = true; + setExclusiveOwnerThread(null); + } + setState(c); + return free; + } + + /** + 1. 判断node.waitStatus + < 0: 直接将waitStatus 设为0 + 2. 尝试唤醒node = node.next + 如果node.next.waitStauts = 1(取消状态),则从 tail往前遍历 + unpark 从 tail往前 第一个非取消状态的线程。 + */ + private void unparkSuccessor(Node node) { + /* + * If status is negative (i.e., possibly needing signal) try + * to clear in anticipation of signalling. It is OK if this + * fails or if status is changed by waiting thread. + */ + int ws = node.waitStatus; + if (ws < 0) + compareAndSetWaitStatus(node, ws, 0); + + /* + * Thread to unpark is held in successor, which is normally + * just the next node. But if cancelled or apparently null, + * traverse backwards from tail to find the actual + * non-cancelled successor. + */ + Node s = node.next; + if (s == null || s.waitStatus > 0) { + s = null; + for (Node t = tail; t != null && t != node; t = t.prev) + if (t.waitStatus <= 0) + s = t; + } + if (s != null) + LockSupport.unpark(s.thread); + } + +``` \ No newline at end of file diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" new file mode 100644 index 00000000..0aa33ea1 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" @@ -0,0 +1,52 @@ + +## lock (sync.lock()) + +```java + final void lock() { + if (compareAndSetState(0, 1)) + setExclusiveOwnerThread(Thread.currentThread()); + else + acquire(1); + } + + public final void acquire(int arg) { + if (!tryAcquire(arg) && + acquireQueued(addWaiter(Node.EXCLUSIVE), arg)) + selfInterrupt(); + } + + protected final boolean tryAcquire(int acquires) { + return nonfairTryAcquire(acquires); + } + + final boolean nonfairTryAcquire(int acquires) { + final Thread current = Thread.currentThread(); + int c = getState(); + if (c == 0) { + // c == 0 && casState(0, 1) 成功 ==> 抢锁成功。否则直接入队。 + if (compareAndSetState(0, acquires)) { + setExclusiveOwnerThread(current); + return true; + } + } + else if (current == getExclusiveOwnerThread()) { + int nextc = c + acquires; + if (nextc < 0) // overflow + throw new Error("Maximum lock count exceeded"); + setState(nextc); + return true; + } + return false; + } + +``` + +## unlock(sync.release(1)) +```java + public void unlock() { + sync.release(1); + } + + 释放锁 没有公平 非公平之分。 + +``` \ No newline at end of file diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" new file mode 100644 index 00000000..e69de29b diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" index f0721870..346d3f27 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" @@ -11,27 +11,34 @@ - 悲观锁适合写操作多的场景,先加锁可以保证写操作时数据正确。 - 乐观锁适合读操作多的场景,不加锁的特点能够使其读操作的性能大幅提升。 -**1. 锁的实现** +### **1. 锁的实现** synchronized 是 JVM 实现的,而 ReentrantLock 是 JDK 实现的。 -**2. 性能** +### **2. 性能** 新版本 Java 对 synchronized 进行了很多优化,例如自旋锁等,synchronized 与 ReentrantLock 大致相同。 -**3. 等待可中断** +### **3. 等待可中断** 当持有锁的线程长期不释放锁的时候,正在等待的线程可以选择放弃等待,改为处理其他事情。 ReentrantLock 可中断,而 synchronized 不行。 -**4. 公平锁** +### **4. 公平锁** 公平锁是指多个线程在等待同一个锁时,必须按照申请锁的时间顺序来依次获得锁。 synchronized 中的锁是非公平的,ReentrantLock 默认情况下也是非公平的,但是也可以是公平的。 -**5. 锁绑定多个条件** +#### 源码阅读: + - [ReentrantLock 公平锁](../AQS源码阅读/ReentrantLock可重入锁_公平锁.md) + + - [ReentrantLock 非公平锁](../AQS源码阅读/ReentrantLock可重入锁_非公平锁.md) + - [synchronized 非公平锁](../AQS源码阅读/synchronized不可重入锁_非公平锁.md) + + +### **5. 锁绑定多个条件** 一个 ReentrantLock 可以同时绑定多个 Condition 对象。 diff --git a/src/main/resources/excel/report.xls b/src/main/resources/excel/report.xls new file mode 100644 index 00000000..e69de29b diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" new file mode 100644 index 00000000..a90aeb3d --- /dev/null +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" @@ -0,0 +1,43 @@ +package org.tianbin.java.反射; + +import com.alibaba.fastjson.JSON; +import common.model.Person; +import common.model.PersonDTO; +import common.util.CommonBeanUtil; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by nibnait on 2021/01/15 + */ +public class CommonBeanUtilTest { + + @Test + public void copyProperties() { + Person source = new Person(); + source.setName("111"); + source.setAge(22); + + PersonDTO personDTO = CommonBeanUtil.copyProperties(source, PersonDTO::new); + + System.out.println(JSON.toJSONString(personDTO)); + } + + @Test + public void copyListProperties() { + List personList = new ArrayList<>(); + Person p1 = new Person(); + p1.setName("111"); + p1.setAge(22); + personList.add(p1); + Person p2 = new Person(); + p2.setName("333"); + p2.setAge(44); + personList.add(p2); + + List personDTOList = CommonBeanUtil.copyListProperties(personList, PersonDTO::new); + System.out.println(JSON.toJSONString(personDTOList)); + } +} diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 98e27fb2..0e98c4dd 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -3,25 +3,38 @@ import com.alibaba.fastjson.JSONObject; import com.google.common.base.Functions; import com.google.common.collect.Lists; -import junit.framework.TestCase; +import common.util.CommonBeanUtil; import org.junit.Test; import java.util.ArrayList; +import java.util.Collections; import java.util.List; /* Created by nibnait on 2020-01-09 */ -public class ListTest extends TestCase { +public class ListTest { @Test - public void testCase02() { - List eveList = new ArrayList<>(); - List oddList = new ArrayList<>(); - + public void copyListProperties() { + List list = Lists.newArrayList(2,1,3); + System.out.println(list); + Collections.sort(list); + System.out.println(list); + } + @Test + public void testSubList() { + List list = Lists.newArrayList(1,2,3); + System.out.println(list.subList(0,0)); + } + @Test + public void sort() { + List list = Lists.newArrayList(2,3,1); + Collections.sort(list); + System.out.println(list); } diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" index 0593778f..ac8a9211 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" @@ -12,7 +12,7 @@ Created by nibnait on 2020-01-15 */ -public class MapTest extends TestCase { +public class MapTest { @Test diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" index f0afeb08..c5fa5dd7 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" @@ -1,10 +1,13 @@ package org.tianbin.java.集合; +import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import common.util.StringUtil; import junit.framework.TestCase; import org.apache.commons.collections4.CollectionUtils; import org.junit.Test; +import java.util.ArrayList; import java.util.Set; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -13,7 +16,16 @@ Created by nibnait on 2020-01-14 */ -public class SetTest extends TestCase { +public class SetTest { + + @Test + public void test01() { + ArrayList list1 = Lists.newArrayList(1, 2, 3); + ArrayList list2 = Lists.newArrayList(2, 3, 4); + + System.out.println(Lists.newArrayList(Sets.difference(Sets.newHashSet(list1), Sets.newHashSet(list2)))); + System.out.println(Lists.newArrayList(Sets.intersection(Sets.newHashSet(list1), Sets.newHashSet(list2)))); + } @Test public void testCase() { diff --git a/src/main/test/org/tianbin/temp/DataGen.java b/src/main/test/org/tianbin/temp/DataGen.java new file mode 100644 index 00000000..b87f2cd6 --- /dev/null +++ b/src/main/test/org/tianbin/temp/DataGen.java @@ -0,0 +1,24 @@ +package org.tianbin.temp; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/01/27 + */ +public class DataGen { + @Test + public void test() { + String ipIdStr = "3000001,3000002,3000003,3000004,3000005,3000006,3000007,3000008,3000009,3000010,3000011,3000012,3000013,3000014,3000015,3000016,3000017,3000018,3000019,3000020,3000021,3000022,3000023,3000024,3000025,3000026,3000027,3000028,3000029,3000030,3000031,3000032,3000033,3000034,3000035,3000036,3000037,3000038,3000039,3000040,3000041,3000042,3000043,3000044,3000045,3000046,3000047,3000048,3000049,3000050,3000051,3000052,3000053,3000054,3000055,3000056,3000057,3000058,3000059,3000060,3000061,3000062,3000063,3000064,3000065,3000066,3000067,3000068,3000069,3000070,3000071,3000072,3000073,3000074,3000075,3000076,3000077,3000078,3000079,3000080,3000081,3000082,3000083,3000084,3000085,3000086,3000087,3000088,3000089,3000090,3000091,3000092,3000093,3000094,3000095,3000096,3000097,3000098,3000099,3000100,3000101,3000102,3000103,3000104,3000105,3000106,3000107,3000108,3000109,3000110,3000111,3000112,3000113,3000114,3000115,3000116,3000117,3000118,3000119,3000120,3000121,3000122,3000123,3000124,3000125,3000126,3000127,3000128,3000129,3000130,3000131,3000132,3000133,3000134,3000135,3000136,3000137,3000138,3000139,3000140,3000141,3000142,3000143,3000144,3000145,3000146,3000147,3000148,3000149,3000150,3000151,3000152,3000153,3000154,3000155,3000156,3000157,3000158,3000159,3000160,3000161,3000162,3000163,3000164,3000165,3000166,3000167,3000168,3000169,3000170,3000171,3000172,3000173,3000174,3000175,3000176,3000177,3000178,3000179,3000180,3000181,3000182,3000183,3000184,3000185,3000186,3000187,3000188,3000189,3000190,3000191,3000192,3000193,3000194,3000195,3000196,3000197,3000198,3000199,3000200,3000201,3000202,3000203,3000204,3000205,3000206,3000207,3000208,3000209,3000210,3000211,3000212,3000213,3000214,3000215,3000216,3000217,3000218,3000219,3000220,3000221,3000222,3000223,3000224,3000225,3000226,3000227,3000228,3000229,3000230,3000231,3000232,3000233,3000234,3000235,3000236,3000237,3000238,3000239,3000240,3000241,3000242,3000243,3000244,3000245,3000246,3000247,3000248,3000249,3000250,3000251,3000252,3000253,3000254,3000255,3000256,3000257,3000258,3000259,3000260,3000261,3000262,3000263,3000264,3000265,3000266,3000267,3000268,3000269,3000270,3000271,3000272,3000273,3000274,3000275,3000276,3000277,3000278,3000279,3000280,3000281,3000282,3000283,3000284,3000285,3000286,3000287,3000288,3000289,3000290,3000291,3000292,3000293,3000294,3000295,3000296,3000297,3000298,3000299,3000300,3000301,3000302,3000303,3000304,3000305,3000306,3000307,3000308,3000309,3000310,3000311,3000312,3000313,3000314,3000315,3000316,3000317,3000318,3000319,3000320,3000321,3000322,3000323,3000324,3000325,3000326,3000327,3000328,3000329,3000330,3000331,3000332,3000333,3000334,3000335,3000336,3000337,3000338,3000339,3000340,3000341,3000342,3000343,3000344,3000345,3000346,3000347,3000348,3000349,3000350,3000351,3000352,3000353,3000354,3000355,3000356,3000357,3000358,3000359,3000360,3000361,3000362,3000363,3000364,3000365,3000366,3000367,3000368,3000369,3000370,3000371,3000372,3000373,3000374,3000375,3000376,3000377,3000378,3000379,3000380,3000381,3000382,3000383,3000384,3000385,3000386,3000387,3000388,3000389,3000390,3000391,3000392,3000393,3000394,3000395,3000396,3000397,3000398,3000399,3000400,3000401,3000402,3000403,3000404,3000405,3000406,3000407,3000408,3000409,3000410,3000411,3000412,3000413,3000414,3000415,3000416,3000417,3000418,3000419,3000420,3000421,3000422,3000423,3000424,3000425,3000426,3000427,3000428,3000429,3000430,3000431,3000432,3000433,3000434,3000435,3000436,3000437,3000438,3000439,3000440,3000441,3000442,3000443,3000444,3000445,3000446,3000447,3000448,3000449,3000450,3000451,3000452,3000453,3000454,3000455,3000456,3000457,3000458,3000459,3000460,3000461,3000462,3000463,3000464,3000465,3000466,3000467,3000468,3000469,3000470,3000471,3000472,3000473,3000474,3000475,3000476,3000477,3000478,3000479,3000480,3000481,3000482,3000483,3000484,3000485,3000486,3000487,3000488,3000489,3000490,3000491,3000492,3000493,3000494,3000495,3000496,3000497,3000498,3000499,3000500,3000501,3000502,3000503,3000504,3000505,3000506,3000507,3000508,3000509,3000510,3000511,3000512,3000513,3000514,3000515,3000516,3000517,3000518,3000519,3000520,3000521,3000522,3000523,3000524,3000525,3000526,3000527,3000528,3000529,3000530,3000531,3000532,3000533,3000534,3000535,3000536,3000537,3000538,3000539,3000540,3000541,3000542,3000543,3000544,3000545,3000546,3000547,3000548,3000549,3000550,3000551,3000552,3000553,3000554,3000555,3000556,3000557,3000558,3000559,3000560,3000561,3000562,3000563,3000564,3000565,3000566,3000567,3000568,3000569,3000570,3000571,3000572,3000573,3000574,3000575,3000576,3000577,3000578,3000579,3000580,3000581,3000582,3000583,3000584,3000585,3000586,3000587,3000588,3000589,3000590,3000591,3000592,3000593,3000594,3000595,3000596,3000597,3000598,3100002,3100005,3100007,3100009,3100011,3100013,3100015,3100018,3100020,3100022,3100024,3100026,3100028,3100031,3100033,3100034,3100036,3100037,3100039,3100041,3100043,3100045,3100047,3100049,3100052,3100054,3100056,3100058,3100060,3100062,3100064,3100066,3100069,3100071,3100073,3100075,3100077,3100079,3100082,3100084,3100087,3100089,3100091,3100093,3100095,3100097,3100099,3100101,3100103,3100105,3100107,3100109,3100112,3100114,3100116,3100118,3100120,3100122,3100124,3100126,3100128,3100130,3100132,3100134,3100136,3100138,3100140,3100142,3100144,3100146,3100149,3100151,3100154,3100156,3100158,3100160,3100162,3100164,3100166,3100168,3100170,3100172,3100174,3100176,3100178,3100180,3100183,3100185,3100187,3100189,3100191,3100193,3100195,3100197,3100199,3100201,3100203,3100205,3100207,3100209,3100211,3100213,3100215,3100217,3100219,3100221,3100223,3100225,3100227,3100229,3100231,3100234,3100236,3100257,3100259,3100261,3100264,3100266,3100272,3100274,3100276,3100278,3100280,3100282,3100284,3100286,3100293,3100295,3100297,3100300,3100302,3100304,3100307,3100309,3100311,3100314,3100317,3100319,3100321,3100323,3100325,3100327,3100329,3100331,3100333,3100335,3100337,3100339,3100341,3100343,3100345,3100347,3100350,3100353,3100355,3100357,3100359,3100361,3100363,3100365,3100367,3100369,3100371,3100373,3100375,3100377,3100379,3100381,3100383,3100385,3100387,3100389,3100391,3100393,3100395,3100398,3100401,3100403,3100405,3100407,3100410,3100412,3100414,3100416,3100418,3100420,3100422,3100424,3100427,3100429,3100431,3100433,3100435,3100437,3100439,3100441,3100444,3100446,3100448,3100450,3100452,3100454,3100456,3100458,3100460,3100462,3100465,3100471,3100473,3100475,3100477,3100479,3100481,3100483,3100485,3100487,3100489,3100491,3100493,3100495,3100497,3100499,3100501,3100503,3100506,3100508,3100510,3100512,3100515,3100517,3100519,3100521,3100523,3100525,3100527,3100529,3100532,3100533,3100565,3100568,3100570,3100572,3100574,3100598,3100606,3100608,3100610,3100612,3100614,3100616,3100618,3100620,3100622,3100624,3100626,3100628,3100631,3100633,3100635,3100637,3100639,3100642,3100644,3100646,3100648,3100650,3100652,3100654,3100656,3100658,3100660,3100662,3100666,3100673,3100675,3100679,3100681,3100683,3100685,3100687,3100689,3100691,3100693,3100695,3100697,3100699,3100702,3100705,3100707,3100709,3100711,3100720,3100722,3100724,3100726,3100728,3100730,3100732,3100734,3100736,3100738,3100740,3100743,3100745,3100747,3100748,3100750,3100752,3100754,3100757,3100759,3100761,3100763,3100765,3100767,3100769,3100771,3100773,3100775,3100778,3100780,3100781,3100784,3100786,3100788"; + String[] split = ipIdStr.split(","); + for (String ipId : split) { + System.out.println(ipId + ",10" + ",0"); + System.out.println(ipId + ",10" + ",10"); + System.out.println(ipId + ",10" + ",20"); + System.out.println(ipId + ",10" + ",30"); + System.out.println(ipId + ",10" + ",40"); + System.out.println(ipId + ",10" + ",50"); + System.out.println(ipId + ",10" + ",60"); + System.out.println(ipId + ",10" + ",70"); + } + } +} diff --git a/src/main/test/org/tianbin/temp/ExcelGen.java b/src/main/test/org/tianbin/temp/ExcelGen.java new file mode 100644 index 00000000..848dc2f1 --- /dev/null +++ b/src/main/test/org/tianbin/temp/ExcelGen.java @@ -0,0 +1,69 @@ +package org.tianbin.temp; + +import com.google.common.collect.Lists; +import common.bo.EmailBO; +import common.util.EmailUtils; +import common.bo.excel.SheetBO; +import common.bo.excel.WorkBookBO; +import org.apache.commons.lang3.StringUtils; +import org.junit.Test; + +import java.io.File; +import java.time.LocalDateTime; +import java.time.format.DateTimeFormatter; + +/** + * Created by nibnait on 2021/01/21 + */ +public class ExcelGen { + + @Test + public void test() { + System.out.println(StringUtils.isBlank(" ")); + } + + private static final String DELAY_DELIVERY_REPORT_FILE_NAME = "报表-%s"; + public static final String DATE_TIME_FORMAT = "yyyyMMdd-HHmm"; + + @Test + public void excelGen() { + + String targetFileName = String.format(DELAY_DELIVERY_REPORT_FILE_NAME, + getNowDateTime(DATE_TIME_FORMAT)); + + WorkBookBO workBookBO = new WorkBookBO(); + SheetBO sheet = workBookBO.getSheetList().get(0); + + xiegehanshu(sheet); + + File delay_delivery_report = workBookBO.writeToFile("report", targetFileName); + + System.out.println(delay_delivery_report.getName()); + + EmailUtils.sendEmail(new EmailBO("111", + "tianbin@bilibili.com", + null, + "222", + getEmailContent(), + Lists.newArrayList(delay_delivery_report))); + } + + public static String getNowDateTime(String dateFormat) { + return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateFormat)); + } + + + private void xiegehanshu(SheetBO sheet) { + sheet.appendRow(Lists.newArrayList("123", "234")); + } + + private String getEmailContent() { + StringBuilder content = new StringBuilder("

Hi All:

"); + content.append("    "); + content.append("2021年1月21日"); + content.append(" 报表如下,请核实:"); + content.append("
"); + content.append("
"); + return content.toString(); + } +} From 228935359c08385e6ff78ee3dd9143c73998810c Mon Sep 17 00:00:00 2001 From: tianbin Date: Tue, 13 Jul 2021 10:40:16 +0800 Subject: [PATCH 02/36] CompareUtil --- pom.xml | 21 ++ ...350\275\254\351\223\276\350\241\2502.java" | 2 +- ...\345\205\245\346\216\222\345\272\217.java" | 2 +- ...\345\272\217\351\223\276\350\241\250.java" | 2 +- ...\350\275\254\351\223\276\350\241\250.java" | 2 +- ...\345\201\266\351\223\276\350\241\250.java" | 2 +- .../java/common/bo/compare/CompareBO.java | 56 +++++ .../common/bo/compare/CompareResultDTO.java | 37 +++ src/main/java/common/model/Person.java | 9 + src/main/java/common/model/PersonDTO.java | 5 +- src/main/java/common/util/CommonBeanUtil.java | 83 ++++++- src/main/java/common/util/CompareUtil.java | 18 -- src/main/java/common/util/DateTimeUtil.java | 125 ++++++++-- .../java/common/util/compare/CompareUtil.java | 40 ++++ .../common/util/compare/JacksonUtils.java | 219 ++++++++++++++++++ .../java/common/util/compare/JsonUtils.java | 211 +++++++++++++++++ .../CompareUtil.java" | 77 ++++-- .../java/\345\217\215\345\260\204/Main.java" | 101 +++++--- .../BigDecimalTest.java" | 46 +++- .../DoubleTest.java" | 49 ++++ .../IntegerTest.java" | 40 ++++ .../StringTest.java" | 9 + .../threadpool/b1_FutureTaskDemo.java" | 6 +- .../b2_CompletableFutureDemo2.java" | 78 +++++++ .../List\347\261\273.java" | 2 +- .../Map\347\261\273.java" | 2 +- .../test/common/util/DateTimeUtilTest.java | 16 ++ src/main/test/org/tianbin/Main.java | 4 +- .../org/tianbin/{temp => excel}/ExcelGen.java | 2 +- .../test/org/tianbin/excel/ExcelRead.java | 10 + .../test/org/tianbin/java/ObjectTest.java | 19 ++ .../test/org/tianbin/java/SwitchCaseTest.java | 28 +++ .../CommonBeanUtilTest.java" | 24 +- ...\350\203\275\346\265\213\350\257\225.java" | 125 ++++++++++ .../java/\345\217\215\345\260\204/README.md" | 0 .../ListStreamTest.java" | 47 ++++ .../\351\233\206\345\220\210/ListTest.java" | 1 - 37 files changed, 1411 insertions(+), 109 deletions(-) create mode 100644 src/main/java/common/bo/compare/CompareBO.java create mode 100644 src/main/java/common/bo/compare/CompareResultDTO.java delete mode 100644 src/main/java/common/util/CompareUtil.java create mode 100644 src/main/java/common/util/compare/CompareUtil.java create mode 100644 src/main/java/common/util/compare/JacksonUtils.java create mode 100644 src/main/java/common/util/compare/JsonUtils.java create mode 100644 "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" create mode 100644 "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" create mode 100644 "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" rename "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" => "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" (95%) rename "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" => "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" (96%) create mode 100644 src/main/test/common/util/DateTimeUtilTest.java rename src/main/test/org/tianbin/{temp => excel}/ExcelGen.java (98%) create mode 100644 src/main/test/org/tianbin/excel/ExcelRead.java create mode 100644 src/main/test/org/tianbin/java/ObjectTest.java create mode 100644 src/main/test/org/tianbin/java/SwitchCaseTest.java create mode 100644 "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" create mode 100644 "src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" create mode 100644 "src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" diff --git a/pom.xml b/pom.xml index 05b2c08b..b69e97fd 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,11 @@ + + cn.hutool + hutool-all + 5.4.5 + io.github.biezhi @@ -128,6 +133,22 @@ compile + + com.json.comparison + comparison-core + 1.2 + + + com.fasterxml.jackson.core + jackson-core + 2.11.2 + + + com.fasterxml.jackson.core + jackson-databind + 2.11.2 + + diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index 3f9c3794..9b508125 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index 824370cd..5ffe8174 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 9ffa6b9e..3ade1f19 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index 2580b991..c7b3a761 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index b87313cc..a69f20ca 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code300; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git a/src/main/java/common/bo/compare/CompareBO.java b/src/main/java/common/bo/compare/CompareBO.java new file mode 100644 index 00000000..4b7d7160 --- /dev/null +++ b/src/main/java/common/bo/compare/CompareBO.java @@ -0,0 +1,56 @@ +package common.bo.compare; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created by nibnait on 2021/06/23 + */ +@Data +public class CompareBO { + + /** + * 当前对比的字段 + */ + private String currentField; + + /** + * 排除字段 + */ + private Set excludeFields = new HashSet<>(); + + /** + * 聚焦字段 + */ + private Set focusFields = new HashSet<>(); + + /** + * 系统默认优化项: pageInfo + */ + private Set optimizations = new LinkedHashSet<>(Collections.singletonList(OptimizationType.IGNORE_NEW_FIELDS)); + + @AllArgsConstructor + public enum OptimizationType { + /** + * 优化类型 + */ + PAGE_HELPER("pageHelper 分页插件"), + IGNORE_NEW_FIELDS("比对时忽略新增字段"), + IGNORE_MISSING_FIELDS("比对时忽略丢失字段"), + ; + + String desc; + } + + public static CompareBO newNoOptimizeCompareBO() { + CompareBO compareBO = new CompareBO(); + compareBO.setOptimizations(new LinkedHashSet<>()); + return compareBO; + } + +} diff --git a/src/main/java/common/bo/compare/CompareResultDTO.java b/src/main/java/common/bo/compare/CompareResultDTO.java new file mode 100644 index 00000000..768c685e --- /dev/null +++ b/src/main/java/common/bo/compare/CompareResultDTO.java @@ -0,0 +1,37 @@ +package common.bo.compare; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Created by nibnait on 2021/06/23 + */ +@Data +@NoArgsConstructor +public class CompareResultDTO { + + private boolean isMatch; + + private List modifiedFields; + + private List missingFields; + + private List newFields; + + private String message; + + @Data + public static class FieldComparison { + private String field; + + private Object expected; + + private Object actual; + } + + public CompareResultDTO(boolean isMatch) { + this.isMatch = isMatch; + } +} diff --git a/src/main/java/common/model/Person.java b/src/main/java/common/model/Person.java index 057b5c4a..f784f512 100644 --- a/src/main/java/common/model/Person.java +++ b/src/main/java/common/model/Person.java @@ -17,6 +17,15 @@ public class Person { private String name; private Integer age; + private Byte gender; + private String phone; + private Boolean isBigBoolean; + private boolean isSmallBoolean; + + public Person(String name, Integer age) { + this.name = name; + this.age = age; + } @Override public boolean equals(Object o) { diff --git a/src/main/java/common/model/PersonDTO.java b/src/main/java/common/model/PersonDTO.java index 3aa4109a..3376e85a 100644 --- a/src/main/java/common/model/PersonDTO.java +++ b/src/main/java/common/model/PersonDTO.java @@ -11,5 +11,8 @@ public class PersonDTO { private String name; private Integer age; - + private Byte gender; + private String phone; + private Boolean isBigBoolean; + private boolean isSmallBoolean; } \ No newline at end of file diff --git a/src/main/java/common/util/CommonBeanUtil.java b/src/main/java/common/util/CommonBeanUtil.java index f7a82fa5..8881ddc1 100644 --- a/src/main/java/common/util/CommonBeanUtil.java +++ b/src/main/java/common/util/CommonBeanUtil.java @@ -1,6 +1,7 @@ package common.util; import com.esotericsoftware.reflectasm.MethodAccess; +import net.sf.cglib.beans.BeanCopier; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -16,7 +17,48 @@ */ public class CommonBeanUtil extends BeanUtils { + public static T copyProperties_BeanCopier(F source, Supplier targetSupplier) { + T target = targetSupplier.get(); + + BeanCopier copier = BeanCopier.create(source.getClass(), target.getClass(), false); + copier.copy(source, target, null); + + return target; + } + + public static T copyProperties_BeanUtils(F source, Supplier targetSupplier) { + T target = targetSupplier.get(); + + BeanUtils.copyProperties(source, target); + + return target; + } + + public static T copyProperties_fieldGetSet(F source, Supplier targetSupplier) { + T target = targetSupplier.get(); + + if (source == null) { + return null; + } + Field[] fromDeclaredFields = source.getClass().getDeclaredFields(); + + for (Field field : fromDeclaredFields) { + try { + field.setAccessible(true); + + Object value = field.get(source); + field.set(target, value); + } catch (Exception e) { + // source 中未设置 get 方法的字段,会直接跳过 + // target 中没有 source 中的字段,也会直接跳过 + } + } + + return target; + } + private static final ConcurrentMap localCache = new ConcurrentHashMap<>(); + private static final ConcurrentMap localCacheFields = new ConcurrentHashMap<>(); public static MethodAccess get(Class clazz) { if (localCache.containsKey(clazz)) { @@ -28,7 +70,17 @@ public static MethodAccess get(Class clazz) { return methodAccess; } - public static T copyProperties(S source, Supplier targetSupplier) { + public static Field[] getFields(Class clazz) { + if (localCacheFields.containsKey(clazz)) { + return localCacheFields.get(clazz); + } + + Field[] declaredFields = clazz.getDeclaredFields(); + localCacheFields.putIfAbsent(clazz, declaredFields); + return declaredFields; + } + + public static T copyProperties_methodInvoke(S source, Supplier targetSupplier) { T target = targetSupplier.get(); if (source == null) { return target; @@ -38,9 +90,32 @@ public static T copyProperties(S source, Supplier targetSupplier) { MethodAccess targetMethodAccess = get(target.getClass()); Field[] declaredFields = source.getClass().getDeclaredFields(); for (Field field : declaredFields) { - String name = field.getName(); - Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); try { + String name = field.getName(); + Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); + targetMethodAccess.invoke(target, "set" + StringUtils.capitalize(name), value); + } catch (Exception e) { + // source 中未设置 get 方法的字段,会直接跳过 + // target 中没有 source 中的字段,也会直接跳过 + } + } + + return target; + } + + public static T copyProperties_methodInvoke_V2(S source, Supplier targetSupplier) { + T target = targetSupplier.get(); + if (source == null) { + return target; + } + + MethodAccess sourceMethodAccess = get(source.getClass()); + MethodAccess targetMethodAccess = get(target.getClass()); + Field[] declaredFields = getFields(source.getClass()); + for (Field field : declaredFields) { + try { + String name = field.getName(); + Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); targetMethodAccess.invoke(target, "set" + StringUtils.capitalize(name), value); } catch (Exception e) { // source 中未设置 get 方法的字段,会直接跳过 @@ -54,7 +129,7 @@ public static T copyProperties(S source, Supplier targetSupplier) { public static List copyListProperties(List sources, Supplier targetSupplier) { List list = new ArrayList<>(sources.size()); for (S source : sources) { - T target = copyProperties(source, targetSupplier); + T target = copyProperties_methodInvoke(source, targetSupplier); list.add(target); } return list; diff --git a/src/main/java/common/util/CompareUtil.java b/src/main/java/common/util/CompareUtil.java deleted file mode 100644 index 4e0c0c3b..00000000 --- a/src/main/java/common/util/CompareUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package common.util; - -import common.datastruct.ListNode; - -/** - * Created by nibnait on 2020/11/20 - */ -public class CompareUtil { - - public static boolean compareListNode(ListNode left, ListNode right) { - while (left != null && right != null && left.val == right.val) { - left = left.next; - right = right.next; - } - return left == right; - } - -} diff --git a/src/main/java/common/util/DateTimeUtil.java b/src/main/java/common/util/DateTimeUtil.java index e10073df..e007da4d 100644 --- a/src/main/java/common/util/DateTimeUtil.java +++ b/src/main/java/common/util/DateTimeUtil.java @@ -1,6 +1,10 @@ package common.util; +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import java.text.DateFormat; import java.text.ParseException; @@ -8,6 +12,7 @@ import java.time.*; import java.time.format.DateTimeFormatter; import java.util.Date; +import java.util.List; public class DateTimeUtil { @@ -108,9 +113,9 @@ public static String localDateTimeToString(LocalDateTime localDateTime, String d } /** - * Date - * LocalDate ==> java.util.Date - * LocalDateTime ( Date.from(ZonedDateTime.toInstant) ) + * Date + * LocalDate ==> java.util.Date + * LocalDateTime ( Date.from(ZonedDateTime.toInstant) ) */ public static Date toUtilDate(Object date) { if (date == null) { @@ -140,8 +145,8 @@ public static Date toUtilDate(Object date) { /** * Date ==> LocalDate - * .toIns - * (ZonedDateTime) + * .toIns + * (ZonedDateTime) */ public static LocalDate dateToLocalDate(Date date) { ZonedDateTime zonedDateTime = date.toInstant().atZone(defaultZoneId); @@ -150,14 +155,13 @@ public static LocalDate dateToLocalDate(Date date) { /** * Date ==> LocalDateTime - * (ZonedDateTime) + * (ZonedDateTime) */ public static LocalDateTime dateToLocalDateTime(Date date) { ZonedDateTime zonedDateTime = date.toInstant().atZone(defaultZoneId); return zonedDateTime.toLocalDateTime(); } - public static final String LONG_TIME_VALID = "长期有效"; /** * 获取当前时间戳 */ @@ -165,24 +169,41 @@ public static Long getTimeInMillis() { return System.currentTimeMillis(); } + /** + * LocalDateTime ==> 秒timestamp + */ + public static Long LocalDateTimeToSecond() { + return LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); + } + + /** + * LocalDateTime ==> 毫秒timestamp + */ + public static Long LocalDateTimeToMillSecond() { + return LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } + + public static final String LONG_TIME_VALID = "长期有效"; + /** * 判断是否在有效期内 + * * @param expireDate * @return */ public static boolean isValidDate(String expireDate) { - if(StringUtils.isBlank(expireDate)){ + if (StringUtils.isBlank(expireDate)) { return false; } - if(LONG_TIME_VALID.equals(expireDate)){ + if (LONG_TIME_VALID.equals(expireDate)) { return true; } - try{ + try { LocalDate expireLocalDate = DateTimeUtil.string2Date(expireDate); - if(LocalDate.now().compareTo(expireLocalDate) < 0){ + if (LocalDate.now().compareTo(expireLocalDate) < 0) { return true; } - }catch (Exception e){ + } catch (Exception e) { return false; } return false; @@ -190,6 +211,7 @@ public static boolean isValidDate(String expireDate) { /** * 比较两个日期相差多少天 + * * @param startTime * @param endTime * @return @@ -198,8 +220,83 @@ public static Long durationDays(LocalDateTime startTime, LocalDateTime endTime) return Duration.between(startTime, endTime).toDays(); } + public static Long durationMillis(LocalDateTime startTime, LocalDateTime endTime) { + return Duration.between(startTime, endTime).toMillis(); + } + + /** + * 校验时期合法性 + */ + public static boolean isDateValid(List date) { + boolean isvalid = true; + if (CollectionUtils.isEmpty(date)) { + return false; + } + + try { + if (date.size() == 1) { + return NumberUtils.isParsable(date.get(0)); + } + if (date.size() == 2) { + LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), 1); + } + if (date.size() == 3) { + if (NumberUtils.isParsable(date.get(2))) { + LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), Integer.parseInt(date.get(2))); + } else { + LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), 1); + if (!Lists.newArrayList("上旬", "中上旬", "中旬", "中下旬", "下旬").contains(date.get(2))) { + isvalid = false; + } + } + } + if (date.size() > 3) { + isvalid = false; + } + } catch (Exception e) { + isvalid = false; + } + return isvalid; + } + public static void main(String[] args) { - String s = localDateTimeToString(LocalDateTime.now(), TIME_MILLISECOND_FORMAT); - System.out.println(s); + List date = Lists.newArrayList("2020", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2021", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2022", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2023", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2019", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2024", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2024", "04", "31"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2024", "05", "31"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02", "上旬"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02", "xx"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02", "中旬", "lj"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); } } diff --git a/src/main/java/common/util/compare/CompareUtil.java b/src/main/java/common/util/compare/CompareUtil.java new file mode 100644 index 00000000..129bea67 --- /dev/null +++ b/src/main/java/common/util/compare/CompareUtil.java @@ -0,0 +1,40 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Sets; +import common.bo.compare.CompareBO; +import common.bo.compare.CompareResultDTO; +import common.datastruct.ListNode; +import lombok.extern.slf4j.Slf4j; + +import java.util.Set; + +/** + * Created by nibnait on 2020/11/20 + */ +@Slf4j +public class CompareUtil { + + public static boolean compareListNode(ListNode left, ListNode right) { + while (left != null && right != null && left.val == right.val) { + left = left.next; + right = right.next; + } + return left == right; + } + + public static boolean match(T actual, T expect) { + return match(actual, expect, Sets.newHashSet()); + } + + public static boolean match(T actual, T expect, Set excludeFields) { + CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); + compareBO.setExcludeFields(excludeFields); + + CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); + if (!compareResultDTO.isMatch()) { + log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); + } + return compareResultDTO.isMatch(); + } +} diff --git a/src/main/java/common/util/compare/JacksonUtils.java b/src/main/java/common/util/compare/JacksonUtils.java new file mode 100644 index 00000000..af9bb61c --- /dev/null +++ b/src/main/java/common/util/compare/JacksonUtils.java @@ -0,0 +1,219 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class JacksonUtils { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + private static final String SEPARATOR = ":"; + public static final String ARRAY_SIGN = "*"; + public static final String MINUS_SIGN = "\"-\""; + public static final String ARRAY_SIGN_REPLACE = "#"; + public static final String PLACEHOLDER_SIGN = "{}"; + private static final String BLANK_REPLACE = " "; + private static final String EMPTY = ""; + + static { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + MAPPER.setDateFormat(dateFormat); + MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + } + + public static String replace(String json, String path, Object value) { + if (StringUtils.isBlank(path)) { + return json; + } + // 使用 # 替换, 否则会因为正则导致替换失败 + path = path.replace(ARRAY_SIGN, ARRAY_SIGN_REPLACE); + // 判断是否多级路径 + int lastNodeIndex = path.lastIndexOf(SEPARATOR); + if (lastNodeIndex == -1) { + return replaceField(json, path, path, value); + } + // 判断是否需要循环解析 + if (!path.contains(ARRAY_SIGN_REPLACE)) { + return replaceField(json, path, path.substring(lastNodeIndex + 1), value); + } + // 需要循环解析, 递归 + String prePath = path.substring(0, getArraySignIndex(path)); + String prePathValue = focus(json, prePath); + JsonNode prePathJsonNode = json2Node(prePathValue); + for (int i = 0; i < prePathJsonNode.size(); i++) { + json = replace(json, path.replaceFirst(ARRAY_SIGN_REPLACE, i + ""), value); + } + return json; + } + + private static int getArraySignIndex(String path) { + return path.indexOf(ARRAY_SIGN_REPLACE) == 0 ? 0 : path.indexOf(ARRAY_SIGN_REPLACE) - 1; + } + + public static String focus(String json, String path) { + if (StringUtils.isBlank(path)) { + return json; + } + // 使用 # 替换, 否则会因为正则导致替换失败 + path = path.replace(ARRAY_SIGN, ARRAY_SIGN_REPLACE); + // 判断是否多级路径 + int lastNodeIndex = path.lastIndexOf(SEPARATOR); + if (lastNodeIndex == -1) { + return focusField(json, path); + } + // 判断是否需要循环解析 + if (!path.contains(ARRAY_SIGN_REPLACE)) { + return focusField(json, path); + } + // 需要循环解析, 递归 + List result = new ArrayList<>(); + String prePath = path.substring(0, getArraySignIndex(path)); + String prePathValue = focus(json, prePath); + JsonNode prePathJsonNode = json2Node(prePathValue); + + if (prePathJsonNode == null) { + return MINUS_SIGN; + } + + for (int i = 0; i < prePathJsonNode.size(); i++) { + String str = focus(json, path.replaceFirst(ARRAY_SIGN_REPLACE, i + "")); + result.add(str); + } + Object[] objects = result.toArray(); + // 自然排序 + Arrays.sort(objects); + return JSON.toJSONString(objects).replaceAll(BLANK_REPLACE, EMPTY); + } + + private static String focusField(String json, String path) { + JsonNode jsonNode = json2Node(json); + String[] paths = path.split(SEPARATOR); + for (String fieldName : paths) { + if (jsonNode == null) { + continue; + } + if (jsonNode.isArray()) { + jsonNode = jsonNode.get(Integer.parseInt(fieldName)); + } else { + jsonNode = jsonNode.get(fieldName); + } + } + return node2Json(jsonNode); + } + + private static String replaceField(String json, String path, String key, Object value) { + if (StringUtils.isBlank(path)) { + return json; + } + JsonNode jsonNode = json2Node(json); + JsonNode temp = jsonNode; + String[] paths = path.split(SEPARATOR); + for (String fieldName : paths) { + if (temp == null) { + continue; + } + // 找到 key + if (fieldName.equals(key)) { + if (temp.isArray()) { + JsonNode removeJsonNode = ((ArrayNode) temp).remove(Integer.parseInt(fieldName)); + if (value != null && removeJsonNode != null) { + Class valueClazz = value.getClass(); + if (valueClazz == String.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (String) value); + } else if (valueClazz == Boolean.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Boolean) value); + } else if (valueClazz == Short.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Short) value); + } else if (valueClazz == Integer.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Integer) value); + } else if (valueClazz == Double.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Double) value); + } else if (valueClazz == Long.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Long) value); + } else if (valueClazz == Float.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Float) value); + } else if (valueClazz == BigDecimal.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (BigDecimal) value); + } + } + } else { + JsonNode removeJsonNode = ((ObjectNode) temp).remove(fieldName); + if (value != null && removeJsonNode != null) { + Class valueClazz = value.getClass(); + if (valueClazz == String.class) { + ((ObjectNode) temp).put(fieldName, (String) value); + } else if (valueClazz == Boolean.class) { + ((ObjectNode) temp).put(fieldName, (Boolean) value); + } else if (valueClazz == Short.class) { + ((ObjectNode) temp).put(fieldName, (Short) value); + } else if (valueClazz == Integer.class) { + ((ObjectNode) temp).put(fieldName, (Integer) value); + } else if (valueClazz == Double.class) { + ((ObjectNode) temp).put(fieldName, (Double) value); + } else if (valueClazz == Long.class) { + ((ObjectNode) temp).put(fieldName, (Long) value); + } else if (valueClazz == Float.class) { + ((ObjectNode) temp).put(fieldName, (Float) value); + } else if (valueClazz == BigDecimal.class) { + ((ObjectNode) temp).put(fieldName, (BigDecimal) value); + } + } + } + continue; + } + if (temp.isArray()) { + temp = temp.get(Integer.parseInt(fieldName)); + } else { + temp = temp.get(fieldName); + } + } + return node2Json(jsonNode); + } + + private static String node2Json(JsonNode jsonNode) { + if (jsonNode == null) { + return null; + } + String value = jsonNode.asText(); + if (StringUtils.isBlank(value)) { + value = jsonNode.toString(); + } + return value; + } + + private static JsonNode json2Node(String json) { + if (StringUtils.isBlank(json)) { + return null; + } + + JsonNode tempNode = null; + try { + tempNode = MAPPER.readTree(json); + } catch (Exception e) { + log.error("json2Node error json {}", json, e); + } + return tempNode; + } + + public static boolean isJson(String json) { + try { + MAPPER.readTree(json); + } catch (Exception e) { + return false; + } + return true; + } + +} diff --git a/src/main/java/common/util/compare/JsonUtils.java b/src/main/java/common/util/compare/JsonUtils.java new file mode 100644 index 00000000..0a1d715b --- /dev/null +++ b/src/main/java/common/util/compare/JsonUtils.java @@ -0,0 +1,211 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.google.common.collect.Lists; +import com.json.comparison.JsonCompare; +import com.json.comparison.JsonComparisonResult; +import com.json.comparison.comprator.model.api.FieldComparison; +import common.bo.compare.CompareBO; +import common.bo.compare.CompareResultDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.helpers.MessageFormatter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Slf4j +public class JsonUtils { + + public static CompareResultDTO diffStr(String actualStr, String expectStr, CompareBO compareBO) { + // 判断是不是标准 json, 是 json 则不转, 否则会发生转义 + if (!JacksonUtils.isJson(actualStr)) { + try { + actualStr = JSON.toJSONString(JSON.parseObject(actualStr), SerializerFeature.WriteMapNullValue); + } catch (Exception e) { + // ignore + } + } + if (!JacksonUtils.isJson(expectStr)) { + try { + expectStr = JSON.toJSONString(JSON.parseObject(expectStr), SerializerFeature.WriteMapNullValue); + } catch (Exception e) { + // ignore + } + } + return diffStr0(actualStr, expectStr, compareBO); + } + + private static CompareResultDTO diffStr0(String actualStr, String expectStr, CompareBO compareBO) { + CompareResultDTO compareResultDTO = new CompareResultDTO(); + compareResultDTO.setMatch(true); + + // 如果不是 json 数据, 直接当成字符串匹配 + if (!JacksonUtils.isJson(actualStr) || !JacksonUtils.isJson(expectStr)) { + compareResultDTO.setMatch(actualStr.equals(expectStr)); + } + Set optimizations = compareBO.getOptimizations(); + Set focusFields = compareBO.getFocusFields(); + Set excludeFields = compareBO.getExcludeFields(); + // 1. 系统默认优化项: 如果开启了则添加到聚焦字段 + for (CompareBO.OptimizationType optimization : optimizations) { + // 如果是分页插件, 则只关注 data:list 数据内容 + if (optimization == CompareBO.OptimizationType.PAGE_HELPER) { + // 判断是否满足条件, 以是否包含 navigatePages、pageSize 为标准 + if (expectStr.contains("navigatePages") && expectStr.contains("pageSize")) { + focusFields.add("list"); + } + } + } + // 2. 排除字段: 如果有先把指定字段移除 + if (excludeFields.size() > 0) { + for (String excludeField : excludeFields) { + actualStr = JacksonUtils.replace(actualStr, excludeField, null); + expectStr = JacksonUtils.replace(expectStr, excludeField, null); + } + } + // 3. 无聚焦字段: 直接匹配字符串 + if (focusFields.size() <= 0) { + return jsonEqual(actualStr, expectStr, compareBO); + } + // 4. 有聚焦字段: 取出依次比较 + ArrayList modifiedFields = Lists.newArrayList(); + ArrayList missingFields = Lists.newArrayList(); + ArrayList newFields = Lists.newArrayList(); + for (String focusField : focusFields) { + String actualValue = JacksonUtils.focus(actualStr, focusField); + String expectValue = JacksonUtils.focus(expectStr, focusField); + + compareBO.setCurrentField(focusField); + CompareResultDTO currentFieldCompareResult = jsonEqual(actualValue, expectValue, compareBO); + + if (!currentFieldCompareResult.isMatch()) { + compareResultDTO.setMatch(false); + } + modifiedFields.addAll(currentFieldCompareResult.getModifiedFields()); + missingFields.addAll(currentFieldCompareResult.getMissingFields()); + newFields.addAll(currentFieldCompareResult.getNewFields()); + } + // 所有聚焦字段比较完后, 直接返回 true + compareResultDTO.setModifiedFields(modifiedFields); + compareResultDTO.setMissingFields(missingFields); + compareResultDTO.setNewFields(newFields); + + return compareResultDTO; + } + + public static CompareResultDTO jsonEqual(String actual, String expect, CompareBO compareBO) { + // 5. 先用 json 判断是否相等 + JsonComparisonResult comparisonResult = compare(actual, expect, compareBO); + + CompareResultDTO compareResultDTO = new CompareResultDTO(false); + if (comparisonResult == null) { + return compareResultDTO; + } + + compareResultDTO.setMatch(comparisonResult.isMatch()); + compareResultDTO.setModifiedFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getModifiedFields())); + compareResultDTO.setMissingFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getMissingFields())); + compareResultDTO.setNewFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getNewFields())); + + // 如果全部比对成功, 直接返回 true + if (comparisonResult.isMatch()) { + compareResultDTO.setMatch(true); + } + // 6. 如果有修改字段, 直接返回失败 + if (CollectionUtils.isNotEmpty(comparisonResult.getModifiedFields())) { + compareResultDTO.setMatch(false); + return compareResultDTO; + } + // 7. 程序走到这里, 表明有两种情况, 一种是新增了字段, 一种是丢失了字段, 所以需要判断是否开启了忽略功能 + // 7.1 如果全部开启, 直接返回 true + if (compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_NEW_FIELDS) && + compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_MISSING_FIELDS)) { + compareResultDTO.setMatch(true); + } + // 7.2 只开启忽略新增字段, 那么只需要判断是否有丢失字段即可 + else if (compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_NEW_FIELDS)) { + compareResultDTO.setMatch(CollectionUtils.isEmpty(comparisonResult.getMissingFields())); + } + // 7.3 只开启忽略丢失字段, 那么只需要判断新增字段即可 + else { + compareResultDTO.setMatch(CollectionUtils.isEmpty(comparisonResult.getNewFields())); + } + + return compareResultDTO; + } + + private static JsonComparisonResult compare(String actual, String expect, CompareBO compareBO) { + JsonComparisonResult comparisonResult = null; + try { + comparisonResult = JsonCompare.builder().build().compare(expect, actual); + } catch (Exception e) { + log.error("JsonUtils.jsonEqual error", e); + } + + if (comparisonResult == null || !comparisonResult.isMatch()) { + log.info("JsonUtils.jsonEqual false compareBO:{}", JSON.toJSONString(compareBO)); + log.info("JsonUtils.jsonEqual false actual:{}", actual); + log.info("JsonUtils.jsonEqual false expect:{}", expect); + } + return comparisonResult; + } + + private static List getFieldComparisonList(String currentField, Collection modifiedFieldList) { + return modifiedFieldList.stream() + .map(comparison -> convertToFieldComparison(currentField, comparison)) + .collect(Collectors.toList()); + } + + private static CompareResultDTO.FieldComparison convertToFieldComparison(String currentField, FieldComparison comparison) { + CompareResultDTO.FieldComparison fieldComparison = new CompareResultDTO.FieldComparison(); + + try { + Integer[] indexArray = getIndexArray(comparison.getField()); + currentField = currentField.replace(JacksonUtils.ARRAY_SIGN, JacksonUtils.PLACEHOLDER_SIGN); + fieldComparison.setField(MessageFormatter.arrayFormat(currentField, indexArray).getMessage()); + } catch (Exception e) { + if (StringUtils.isBlank(currentField)) { + currentField = comparison.getField(); + } + if ("list".equals(currentField)) { + currentField = currentField + comparison.getField(); + } + fieldComparison.setField(currentField); + } + + fieldComparison.setExpected(comparison.getExpected()); + fieldComparison.setActual(comparison.getActual()); + return fieldComparison; + } + + private static Integer[] getIndexArray(String field) { + JSONArray jsonArray; + try { + jsonArray = JSON.parseArray(field); + Integer[] indexArray = new Integer[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + indexArray[i] = (int) jsonArray.get(i); + } + return indexArray; + } catch (Exception e) { + field = "[" + field + "]"; + jsonArray = JSON.parseArray(field); + Integer[] indexArray = new Integer[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + JSONArray arr = (JSONArray) jsonArray.get(i); + indexArray[i] = (int) arr.get(0); + } + return indexArray; + } + + + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" index beae8474..18a925e0 100644 --- "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" +++ "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" @@ -1,50 +1,85 @@ package org.tianbin.java.反射; -import java.beans.IntrospectionException; +import cn.hutool.log.Log; +import cn.hutool.log.LogFactory; +import com.alibaba.fastjson.JSON; +import org.apache.commons.collections4.MapUtils; +import org.springframework.beans.BeanUtils; + import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.List; import java.util.Map; /** * Created by nibnait on 2020/11/11 */ +@Deprecated public class CompareUtil { - public static void compare(Object thisObj, Object thatObj, Map errorMap) { + private static final Log log = LogFactory.get(CompareUtil.class); + + /** + * 返回 true/false + * @param whiteFiledList 不需要核对的字段 + */ + public static boolean compareBool(Object leftObj, Object rightObj, List whiteFiledList) { + Map errorMap = compare(leftObj, rightObj, whiteFiledList); + + if (MapUtils.isNotEmpty(errorMap)) { + log.info("CompareUtils.errorMap: {}, leftObj: {}, rightObj: {}", + JSON.toJSONString(errorMap), + JSON.toJSONString(leftObj), JSON.toJSONString(rightObj)); + } + return MapUtils.isEmpty(errorMap); + } + /** + * 返回 errorMap + * @param whiteFiledList 不需要核对的字段 + */ + public static Map compare(Object leftObj, Object rightObj, List whiteFiledList) { + Map errorMap = new HashMap<>(); try { - Class clazz = thisObj.getClass(); - Field[] fields = clazz.getDeclaredFields(); + PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(leftObj.getClass()); + + if (propertyDescriptors == null || propertyDescriptors.length <= 1) { + return errorMap; + } + + for (int i = 1; i < propertyDescriptors.length; i++) { + PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; + String fieldName = propertyDescriptor.getName(); - for (Field field : fields) { - if (field.getModifiers() != Modifier.PRIVATE) { + if (whiteFiledList.contains(fieldName)) { continue; } - // 排除静态字段 - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), clazz); // 获得get方法 - Method getMethod = propertyDescriptor.getReadMethod(); + Method readMethod = propertyDescriptor.getReadMethod(); + + if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { + readMethod.setAccessible(true); + } - Object leftProperty = getMethod.invoke(thisObj); - Object rightProperty = getMethod.invoke(thatObj); + Object leftProperty = readMethod.invoke(leftObj); + Object rightProperty = readMethod.invoke(rightObj); boolean pass = compareObject(leftProperty, rightProperty); if (!pass) { - addToErrMap(errorMap, leftProperty, rightProperty, thisObj.getClass().getSimpleName(), getMethod.getName()); + addToErrMap(errorMap, leftProperty, rightProperty, leftObj.getClass().getSimpleName(), fieldName); } + } - } catch (IntrospectionException e) { - errorMap.put("比对", "核对发生IntrospectionException异常"); - } catch (IllegalAccessException e) { - errorMap.put("比对", "核对发生IllegalAccessException异常"); - } catch (InvocationTargetException e) { - errorMap.put("比对", "核对发生InvocationTargetException异常"); + + } catch (Exception e) { + log.error(e, "CompareUtils error " + e.getMessage()); + errorMap.put("比对", "核对发生异常"); } + return errorMap; } private static void addToErrMap(Map errorMap, Object leftProperty, Object rightProperty, String className, String fieldName) { @@ -66,7 +101,7 @@ private static boolean compareObject(Object thisObj, Object thatObj) { return false; } - if (thisObj == null && thatObj == null) { + if (thisObj == null) { return true; } diff --git "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" index f263cd93..83c22cf4 100644 --- "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" +++ "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" @@ -1,12 +1,17 @@ package org.tianbin.java.反射; import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import common.model.Person; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.junit.Test; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -17,30 +22,72 @@ public class Main { @Test public void test01() { Order left = getLeftValue(); - Order right = getRightValue(); - Map errorMap = new HashMap<>(); - left.compareTo(right, errorMap); + Map errorMap = CompareUtil.compare(left, right, Lists.newArrayList("testByte")); System.out.println(JSON.toJSONString(errorMap)); } - private Order getRightValue() { - Order order = new Order(2, "456"); - Map detailJson = new HashMap<>(); - + private Order getLeftValue() { + Order order = new Order(); + order.setOrderId(0L); + order.setTestInteger(0); + order.setTestLong(0L); + order.setTestByte((byte)0); + order.setTestDouble(0.0D); + order.setTestFloat(1.0F); + order.setPrice(BigDecimal.valueOf(0)); + order.setPhone(""); + Map detailJson = new HashMap<>(); + detailJson.put("1", "1"); order.setDetailJson(detailJson); + + ArrayList personList = Lists.newArrayList(); + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone(""); + person.setIsBigBoolean(false); + person.setSmallBoolean(false); + personList.add(person); + order.setPersonList(personList); + + order.setIsBigBoolean(true); + order.setSmallBoolean(true); return order; } - private Order getLeftValue() { - Order order = new Order(1, "123"); - Map detailJson = new HashMap<>(); - + private Order getRightValue() { + Order order = new Order(); + order.setOrderId(1L); + order.setTestInteger(1); + order.setTestLong(1L); + order.setTestByte((byte)1); + order.setTestDouble(0.1D); + order.setTestFloat(1.0F); + order.setPrice(BigDecimal.valueOf(1)); + order.setPhone(""); + Map detailJson = new HashMap<>(); + detailJson.put("1", "2"); order.setDetailJson(detailJson); + + ArrayList personList = Lists.newArrayList(); + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone(""); + person.setIsBigBoolean(true); + person.setSmallBoolean(true); + personList.add(person); + order.setPersonList(personList); + + order.setIsBigBoolean(false); + order.setSmallBoolean(false); return order; } @@ -50,32 +97,18 @@ private Order getLeftValue() { @AllArgsConstructor class Order { private long orderId; + private Integer testInteger; + private Long testLong; + private Byte testByte; + private Double testDouble; + private Float testFloat; + private BigDecimal price; private String phone; - private Map detailJson; + private List personList; + private Boolean isBigBoolean; + private boolean isSmallBoolean; - public Order(long orderId, String phone) { - this.orderId = orderId; - this.phone = phone; - } - - public boolean compareTo(Object that, Map errorMap) { - if (that == null) { - errorMap.put("比对", "当前右值为空"); - } - - if (!(that instanceof Order)) { - errorMap.put("比对", "右值类型不对"); - } - - // 校验 本次比对是否跳过 - // 初始化白名单 - // 初始化黑名单 - - CompareUtil.compare(this, that, errorMap); - - return errorMap.size() == 0; - } } diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" index ec2df820..055d4f0c 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" @@ -3,6 +3,7 @@ import org.junit.Test; import java.math.BigDecimal; +import java.math.RoundingMode; /** * Created by nibnait on 2020/11/11 @@ -10,14 +11,53 @@ public class BigDecimalTest { @Test - public void testCase() { + public void test04() { + int i = 1; + BigDecimal bigDecimal1 = new BigDecimal(i); + System.out.println(bigDecimal1); + + double d = 1.83; + BigDecimal bigDecimal2 = new BigDecimal(d); + System.out.println(bigDecimal2); + + BigDecimal divide = bigDecimal2.divide(BigDecimal.valueOf(2), 2, RoundingMode.HALF_UP); + System.out.println(divide); + } + + @Test + public void test03() { + Double d1 = 1.0; + System.out.println("d1 = " + BigDecimal.valueOf(d1).stripTrailingZeros()); + Double d2 = 1.00; + System.out.println("d2 = " + BigDecimal.valueOf(d2).stripTrailingZeros()); + Double d3 = 1.000; + System.out.println("d3 = " + BigDecimal.valueOf(d3).stripTrailingZeros()); + Double d4 = 1.001; + System.out.println("d4 = " + BigDecimal.valueOf(d4).stripTrailingZeros()); + Double d5 = 1.01; + System.out.println("d5 = " + BigDecimal.valueOf(d5).stripTrailingZeros()); + Double d6 = 1.11; + System.out.println("d6 = " + BigDecimal.valueOf(d6).stripTrailingZeros()); + } + + @Test + public void test02() { + System.out.println(BigDecimal.valueOf(getInt())); + } + + private Integer getInt() { + return null; + } + + @Test + public void test01() { double value = 100.2; BigDecimal bigDecimal = new BigDecimal(value); BigDecimal bigDecimal1 = BigDecimal.valueOf(value); - System.out.println(bigDecimal); - System.out.println(bigDecimal1); + System.out.println("new " + bigDecimal); + System.out.println("valueOf " + bigDecimal1); } } diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" new file mode 100644 index 00000000..9853dd51 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" @@ -0,0 +1,49 @@ +package org.tianbin.java.基本数据类型; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/06/02 + */ +public class DoubleTest { + + @Test + public void test01() { + String s = "19.9"; + Double d = Double.valueOf(s); + System.out.println(d); + } + + @Test + public void test02() { + double d = 19.9; + + double v = d * 100; + System.out.println(v); + + int i = (int)v; + System.out.println(i); + + int d1 = 1989; + double d2 = (double) d1 / 100; + System.out.println(d2); + + d1 = 1990; + d2 = (double) d1 / 100; + System.out.println(d2); + + } + + @Test + public void test03() { + double d = 19.9; + + double v = d * 0.5; + System.out.println(v); + + int i = (int)v; + System.out.println(i); + + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" new file mode 100644 index 00000000..309433da --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" @@ -0,0 +1,40 @@ +package org.tianbin.java.基本数据类型; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/03/18 + */ +public class IntegerTest { + + @Test + public void testCompareTo() { + Integer old = 110; + Integer newI = 11110; + System.out.println(newI - old); + + old = 122222; + newI = 2222; + System.out.println(newI - old); + + old = 77777; + newI = 77777; + System.out.println(newI - old); + } + + @Test + public void test02() { + int i1 = 166; + System.out.println(i1 / 100); + int i2 = 133; + System.out.println(i2 / 100); + } + + @Test + public void test01() { + String s = "xxx"; + int i = Integer.parseInt(s); + System.out.println(i); + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" index 56ac012a..b10fad13 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import junit.framework.TestCase; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import java.util.Stack; @@ -12,6 +13,12 @@ */ public class StringTest extends TestCase { + @Test + public void testStringUtils() { + StringUtils.isEmpty(""); + StringUtils.isBlank(""); + } + @Test public void testGetLong() { String str = "{\"bizNo\":\"111\"}"; @@ -32,6 +39,8 @@ public void testCase() { public void testSubString() { String str = "123"; System.out.println(str.substring(0, str.length() - 1)); + + //output: 12 } @Test diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" index e7ac4fd0..36c390c1 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" @@ -21,11 +21,11 @@ public class b1_FutureTaskDemo extends TestCase { 烧水泡茶 分工: T1: 洗水壶(1min) --> 烧开水(15min) --> 泡茶 /\ - T2: 洗茶壶(1min) | + T2: 洗茶壶(1min) | | | - 洗茶杯(2min) | + 洗茶杯(2min) | | | - 拿茶叶(1min)———————— + 拿茶叶(1min)————————- */ @Test diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" new file mode 100644 index 00000000..eb2d6ec3 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" @@ -0,0 +1,78 @@ +package org.tianbin.java.并发.threadpool; + +import junit.framework.TestCase; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static common.util.SystemUtil.sleep; + +/** + * 任务之间有聚合关系:CompletableFuture + * + * T3需要等待T1 和 T2 执行完,在开始执行 + * + * Created by nibnait on 2019-09-01 + */ +public class b2_CompletableFutureDemo2 extends TestCase { + + /** + * T1:洗水壶(1min) --> 烧开水(15min) + * T2:洗茶壶(1min) --> 洗茶杯(2min) --> 拿茶叶(1min) + *

+ * T3:泡茶 + */ + @Test + public void testMain() { + //任务1:洗水壶->烧开水 +// CompletableFuture f1 = CompletableFuture.runAsync( +// () -> { +// System.out.println("T1:洗水壶..."); +// sleep(1, TimeUnit.SECONDS); +// System.out.println("T1:烧开水..."); +// sleep(15, TimeUnit.SECONDS); +// }); + + //任务2:洗茶壶->洗茶杯->拿茶叶 + CompletableFuture f1 = CompletableFuture.supplyAsync( + () -> { + System.out.println("T2:洗茶壶..."); + sleep(1, TimeUnit.SECONDS); + System.out.println("T2:洗茶杯..."); + sleep(2, TimeUnit.SECONDS); + System.out.println("T2:拿茶叶..."); + sleep(20, TimeUnit.SECONDS); + return "⻰井"; + }); + + String taskId = "123"; + Integer time = 10; + TimeUnit timeUnit = TimeUnit.MINUTES; + + try { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + executorService.execute(() -> getF1Return(f1, taskId, time, timeUnit)); + + } catch (Exception e) { + + } + + + System.out.println("end"); + sleep(10, TimeUnit.MINUTES); + } + + private String getF1Return(CompletableFuture f1, String taskId, Integer time, TimeUnit timeUnit) { + try { + String s = f1.get(); + System.out.println(s + " ... " + taskId); + } catch (Exception e) { + + } + return taskId; + } + +} diff --git "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" rename to "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" index 375668f2..c20781f5 100644 --- "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" +++ "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" @@ -7,7 +7,7 @@ * @author nibnait * @version $Id: List.java, v 0.1 2019-08-15 上午10:58 nibnait Exp $$ */ -public class List { +public class List类 { public static void main(String[] args) { Queue queue; diff --git "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" rename to "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" index d616f0ad..cdb2e63e 100644 --- "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" +++ "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" @@ -8,7 +8,7 @@ * @author nibnait * @version $Id: Map.java, v 0.1 2019-08-12 下午2:16 nibnait Exp $$ */ -public class Map { +public class Map类 { public static void main(String[] args) { Hashtable hashtable; diff --git a/src/main/test/common/util/DateTimeUtilTest.java b/src/main/test/common/util/DateTimeUtilTest.java new file mode 100644 index 00000000..2c0f3af1 --- /dev/null +++ b/src/main/test/common/util/DateTimeUtilTest.java @@ -0,0 +1,16 @@ +package common.util; + +import org.junit.Test; + +import java.util.Date; + +/** + * Created by nibnait on 2021/04/07 + */ +public class DateTimeUtilTest { + @Test + public void test01() { + Date date = new Date(); + System.out.println(date.getTime()); + } +} diff --git a/src/main/test/org/tianbin/Main.java b/src/main/test/org/tianbin/Main.java index 5dbb0d3a..2c45612f 100644 --- a/src/main/test/org/tianbin/Main.java +++ b/src/main/test/org/tianbin/Main.java @@ -8,7 +8,9 @@ public class Main extends TestCase { public static void main(String[] args) { - System.out.println(9/2); + Byte b = 1; + Byte i = null; + System.out.println(b.equals(i)); } } \ No newline at end of file diff --git a/src/main/test/org/tianbin/temp/ExcelGen.java b/src/main/test/org/tianbin/excel/ExcelGen.java similarity index 98% rename from src/main/test/org/tianbin/temp/ExcelGen.java rename to src/main/test/org/tianbin/excel/ExcelGen.java index 848dc2f1..a40e2512 100644 --- a/src/main/test/org/tianbin/temp/ExcelGen.java +++ b/src/main/test/org/tianbin/excel/ExcelGen.java @@ -1,4 +1,4 @@ -package org.tianbin.temp; +package org.tianbin.excel; import com.google.common.collect.Lists; import common.bo.EmailBO; diff --git a/src/main/test/org/tianbin/excel/ExcelRead.java b/src/main/test/org/tianbin/excel/ExcelRead.java new file mode 100644 index 00000000..a8c1d99d --- /dev/null +++ b/src/main/test/org/tianbin/excel/ExcelRead.java @@ -0,0 +1,10 @@ +package org.tianbin.excel; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/03/26 + */ +public class ExcelRead { + +} diff --git a/src/main/test/org/tianbin/java/ObjectTest.java b/src/main/test/org/tianbin/java/ObjectTest.java new file mode 100644 index 00000000..1d174137 --- /dev/null +++ b/src/main/test/org/tianbin/java/ObjectTest.java @@ -0,0 +1,19 @@ +package org.tianbin.java; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/04/01 + */ +public class ObjectTest { + + @Test + public void testEquals() { + Byte saleType = null; + Byte saleType1 = 1; + + boolean equals = saleType1.equals(saleType); + System.out.println(equals); + + } +} diff --git a/src/main/test/org/tianbin/java/SwitchCaseTest.java b/src/main/test/org/tianbin/java/SwitchCaseTest.java new file mode 100644 index 00000000..60b209de --- /dev/null +++ b/src/main/test/org/tianbin/java/SwitchCaseTest.java @@ -0,0 +1,28 @@ +package org.tianbin.java; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/07/13 + */ +public class SwitchCaseTest { + + @Test + public void test01() { + + int i = 1; + + switch (i) { + case 1: + System.out.println("1:" + i); +// break; + case 2: + System.out.println("2:" + i); +// break; + default: + System.out.println("default:" + i); + } + + } + +} diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" index a90aeb3d..00e1b69f 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" @@ -4,6 +4,7 @@ import common.model.Person; import common.model.PersonDTO; import common.util.CommonBeanUtil; +import net.sf.cglib.beans.BeanCopier; import org.junit.Test; import java.util.ArrayList; @@ -14,13 +15,34 @@ */ public class CommonBeanUtilTest { + @Test + public void testBeanCopier() { + Person person = new Person(); + person.setName("123"); + person.setAge(1); + person.setGender((byte)2); + person.setPhone("13288889999"); + person.setIsBigBoolean(true); + person.setSmallBoolean(true); + + person.getIsBigBoolean(); + + person.isSmallBoolean(); + + BeanCopier beanCopier = BeanCopier.create(Person.class, PersonDTO.class, false); + PersonDTO personDTO = new PersonDTO(); + beanCopier.copy(person, personDTO, null); + + System.out.println(JSON.toJSONString(personDTO)); + } + @Test public void copyProperties() { Person source = new Person(); source.setName("111"); source.setAge(22); - PersonDTO personDTO = CommonBeanUtil.copyProperties(source, PersonDTO::new); + PersonDTO personDTO = CommonBeanUtil.copyProperties_methodInvoke(source, PersonDTO::new); System.out.println(JSON.toJSONString(personDTO)); } diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" new file mode 100644 index 00000000..05d24757 --- /dev/null +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" @@ -0,0 +1,125 @@ +package org.tianbin.java.反射; + +import common.model.Person; +import common.model.PersonDTO; +import common.util.CommonBeanUtil; +import common.util.DateTimeUtil; +import org.junit.Test; + +import java.time.LocalDateTime; + +/** + * Created by nibnait on 2021/03/23 + */ +public class CopyProperties_性能测试 { + + private static final int cycleTimes = 10000000; + + @Test + public void main() { + test_BeanCopier(); + test_BeanUtils(); +// test_fieldGetSet(); +// test_methodInvoke(); +// test_methodInvoke_V2(); + + + /* + copyProperties_BeanCopier 960ms + copyProperties_BeanUtils 2158ms + copyProperties_fieldGetSet 130803ms + copyProperties_methodInvoke 45393ms + copyProperties_methodInvoke_V2 49951ms + */ + } + + @Test + public void test_BeanCopier() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_BeanCopier(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_BeanCopier " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_BeanUtils() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_BeanUtils(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_BeanUtils " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_fieldGetSet() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_fieldGetSet(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_fieldGetSet " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_methodInvoke() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_methodInvoke(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_methodInvoke " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_methodInvoke_V2() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_methodInvoke_V2(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_methodInvoke_V2 " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } +} diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" new file mode 100644 index 00000000..e69de29b diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" new file mode 100644 index 00000000..24053c3c --- /dev/null +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" @@ -0,0 +1,47 @@ +package org.tianbin.java.集合; + +import common.model.Person; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by nibnait on 2021/05/20 + */ +public class ListStreamTest { + + @Test + public void test01() { + + + List personList = new ArrayList<>(); + + Person p1 = new Person(); + p1.setAge(1); + personList.add(p1); + Person p3 = new Person(); + p3.setAge(3); + personList.add(p3); + Person p2 = new Person(); + p2.setAge(2); + personList.add(p2); + + + System.out.println(personList); + List collect = personList.stream() + .sorted(Comparator.comparing(Person::getAge)) + .map(Person::getAge) + .collect(Collectors.toList()); + System.out.println(collect); + + List collectReversed = personList.stream() + .sorted(Comparator.comparing(Person::getAge).reversed()) + .map(Person::getAge) + .collect(Collectors.toList()); + System.out.println(collectReversed); + } + +} diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 0e98c4dd..a6ca459a 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -3,7 +3,6 @@ import com.alibaba.fastjson.JSONObject; import com.google.common.base.Functions; import com.google.common.collect.Lists; -import common.util.CommonBeanUtil; import org.junit.Test; import java.util.ArrayList; From 7be72766d56b7fdd206351fd9df8fc84613b7f2e Mon Sep 17 00:00:00 2001 From: tianbin Date: Tue, 13 Jul 2021 10:40:16 +0800 Subject: [PATCH 03/36] CompareUtil --- pom.xml | 23 +- ...350\275\254\351\223\276\350\241\2502.java" | 2 +- ...\345\205\245\346\216\222\345\272\217.java" | 2 +- ...\345\272\217\351\223\276\350\241\250.java" | 2 +- ...\350\275\254\351\223\276\350\241\250.java" | 2 +- ...\345\201\266\351\223\276\350\241\250.java" | 2 +- .../java/common/bo/compare/CompareBO.java | 56 ++++ .../common/bo/compare/CompareResultDTO.java | 37 +++ src/main/java/common/model/Person.java | 9 + src/main/java/common/model/PersonDTO.java | 5 +- src/main/java/common/util/CommonBeanUtil.java | 83 +++++- src/main/java/common/util/CompareUtil.java | 18 -- src/main/java/common/util/DateTimeUtil.java | 125 ++++++++- .../java/common/util/compare/CompareUtil.java | 61 +++++ .../common/util/compare/JacksonUtils.java | 219 ++++++++++++++++ .../java/common/util/compare/JsonUtils.java | 242 ++++++++++++++++++ .../CompareUtil.java" | 77 ++++-- .../java/\345\217\215\345\260\204/Main.java" | 101 +++++--- .../BigDecimalTest.java" | 46 +++- .../DoubleTest.java" | 49 ++++ .../IntegerTest.java" | 40 +++ .../StringTest.java" | 9 + .../threadpool/b1_FutureTaskDemo.java" | 6 +- .../b2_CompletableFutureDemo2.java" | 78 ++++++ .../List\347\261\273.java" | 2 +- .../Map\347\261\273.java" | 2 +- .../test/common/util/DateTimeUtilTest.java | 16 ++ src/main/test/org/tianbin/Main.java | 4 +- .../org/tianbin/{temp => excel}/ExcelGen.java | 2 +- .../test/org/tianbin/excel/ExcelRead.java | 10 + .../test/org/tianbin/java/ObjectTest.java | 19 ++ .../test/org/tianbin/java/SwitchCaseTest.java | 29 +++ .../CommonBeanUtilTest.java" | 24 +- ...\350\203\275\346\265\213\350\257\225.java" | 125 +++++++++ .../java/\345\217\215\345\260\204/README.md" | 0 .../ListStreamTest.java" | 47 ++++ .../\351\233\206\345\220\210/ListTest.java" | 23 +- .../test/org/tianbin/temp/JsonParseTest.java | 7 + 38 files changed, 1494 insertions(+), 110 deletions(-) create mode 100644 src/main/java/common/bo/compare/CompareBO.java create mode 100644 src/main/java/common/bo/compare/CompareResultDTO.java delete mode 100644 src/main/java/common/util/CompareUtil.java create mode 100644 src/main/java/common/util/compare/CompareUtil.java create mode 100644 src/main/java/common/util/compare/JacksonUtils.java create mode 100644 src/main/java/common/util/compare/JsonUtils.java create mode 100644 "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" create mode 100644 "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" create mode 100644 "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" rename "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" => "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" (95%) rename "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" => "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" (96%) create mode 100644 src/main/test/common/util/DateTimeUtilTest.java rename src/main/test/org/tianbin/{temp => excel}/ExcelGen.java (98%) create mode 100644 src/main/test/org/tianbin/excel/ExcelRead.java create mode 100644 src/main/test/org/tianbin/java/ObjectTest.java create mode 100644 src/main/test/org/tianbin/java/SwitchCaseTest.java create mode 100644 "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" create mode 100644 "src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" create mode 100644 "src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" diff --git a/pom.xml b/pom.xml index 05b2c08b..8d854c0b 100644 --- a/pom.xml +++ b/pom.xml @@ -20,6 +20,11 @@ + + cn.hutool + hutool-all + 5.4.5 + io.github.biezhi @@ -124,10 +129,26 @@ com.google.guava guava - 28.1-jre + 30.0-jre compile + + com.json.comparison + comparison-core + 1.2 + + + com.fasterxml.jackson.core + jackson-core + 2.11.2 + + + com.fasterxml.jackson.core + jackson-databind + 2.11.2 + + diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index 3f9c3794..9b508125 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index 824370cd..5ffe8174 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 9ffa6b9e..3ade1f19 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index 2580b991..c7b3a761 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index b87313cc..a69f20ca 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code300; import common.datastruct.ListNode; -import common.util.CompareUtil; +import common.util.compare.CompareUtil; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git a/src/main/java/common/bo/compare/CompareBO.java b/src/main/java/common/bo/compare/CompareBO.java new file mode 100644 index 00000000..4b7d7160 --- /dev/null +++ b/src/main/java/common/bo/compare/CompareBO.java @@ -0,0 +1,56 @@ +package common.bo.compare; + +import lombok.AllArgsConstructor; +import lombok.Data; + +import java.util.Collections; +import java.util.HashSet; +import java.util.LinkedHashSet; +import java.util.Set; + +/** + * Created by nibnait on 2021/06/23 + */ +@Data +public class CompareBO { + + /** + * 当前对比的字段 + */ + private String currentField; + + /** + * 排除字段 + */ + private Set excludeFields = new HashSet<>(); + + /** + * 聚焦字段 + */ + private Set focusFields = new HashSet<>(); + + /** + * 系统默认优化项: pageInfo + */ + private Set optimizations = new LinkedHashSet<>(Collections.singletonList(OptimizationType.IGNORE_NEW_FIELDS)); + + @AllArgsConstructor + public enum OptimizationType { + /** + * 优化类型 + */ + PAGE_HELPER("pageHelper 分页插件"), + IGNORE_NEW_FIELDS("比对时忽略新增字段"), + IGNORE_MISSING_FIELDS("比对时忽略丢失字段"), + ; + + String desc; + } + + public static CompareBO newNoOptimizeCompareBO() { + CompareBO compareBO = new CompareBO(); + compareBO.setOptimizations(new LinkedHashSet<>()); + return compareBO; + } + +} diff --git a/src/main/java/common/bo/compare/CompareResultDTO.java b/src/main/java/common/bo/compare/CompareResultDTO.java new file mode 100644 index 00000000..768c685e --- /dev/null +++ b/src/main/java/common/bo/compare/CompareResultDTO.java @@ -0,0 +1,37 @@ +package common.bo.compare; + +import lombok.Data; +import lombok.NoArgsConstructor; + +import java.util.List; + +/** + * Created by nibnait on 2021/06/23 + */ +@Data +@NoArgsConstructor +public class CompareResultDTO { + + private boolean isMatch; + + private List modifiedFields; + + private List missingFields; + + private List newFields; + + private String message; + + @Data + public static class FieldComparison { + private String field; + + private Object expected; + + private Object actual; + } + + public CompareResultDTO(boolean isMatch) { + this.isMatch = isMatch; + } +} diff --git a/src/main/java/common/model/Person.java b/src/main/java/common/model/Person.java index 057b5c4a..f784f512 100644 --- a/src/main/java/common/model/Person.java +++ b/src/main/java/common/model/Person.java @@ -17,6 +17,15 @@ public class Person { private String name; private Integer age; + private Byte gender; + private String phone; + private Boolean isBigBoolean; + private boolean isSmallBoolean; + + public Person(String name, Integer age) { + this.name = name; + this.age = age; + } @Override public boolean equals(Object o) { diff --git a/src/main/java/common/model/PersonDTO.java b/src/main/java/common/model/PersonDTO.java index 3aa4109a..3376e85a 100644 --- a/src/main/java/common/model/PersonDTO.java +++ b/src/main/java/common/model/PersonDTO.java @@ -11,5 +11,8 @@ public class PersonDTO { private String name; private Integer age; - + private Byte gender; + private String phone; + private Boolean isBigBoolean; + private boolean isSmallBoolean; } \ No newline at end of file diff --git a/src/main/java/common/util/CommonBeanUtil.java b/src/main/java/common/util/CommonBeanUtil.java index f7a82fa5..8881ddc1 100644 --- a/src/main/java/common/util/CommonBeanUtil.java +++ b/src/main/java/common/util/CommonBeanUtil.java @@ -1,6 +1,7 @@ package common.util; import com.esotericsoftware.reflectasm.MethodAccess; +import net.sf.cglib.beans.BeanCopier; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -16,7 +17,48 @@ */ public class CommonBeanUtil extends BeanUtils { + public static T copyProperties_BeanCopier(F source, Supplier targetSupplier) { + T target = targetSupplier.get(); + + BeanCopier copier = BeanCopier.create(source.getClass(), target.getClass(), false); + copier.copy(source, target, null); + + return target; + } + + public static T copyProperties_BeanUtils(F source, Supplier targetSupplier) { + T target = targetSupplier.get(); + + BeanUtils.copyProperties(source, target); + + return target; + } + + public static T copyProperties_fieldGetSet(F source, Supplier targetSupplier) { + T target = targetSupplier.get(); + + if (source == null) { + return null; + } + Field[] fromDeclaredFields = source.getClass().getDeclaredFields(); + + for (Field field : fromDeclaredFields) { + try { + field.setAccessible(true); + + Object value = field.get(source); + field.set(target, value); + } catch (Exception e) { + // source 中未设置 get 方法的字段,会直接跳过 + // target 中没有 source 中的字段,也会直接跳过 + } + } + + return target; + } + private static final ConcurrentMap localCache = new ConcurrentHashMap<>(); + private static final ConcurrentMap localCacheFields = new ConcurrentHashMap<>(); public static MethodAccess get(Class clazz) { if (localCache.containsKey(clazz)) { @@ -28,7 +70,17 @@ public static MethodAccess get(Class clazz) { return methodAccess; } - public static T copyProperties(S source, Supplier targetSupplier) { + public static Field[] getFields(Class clazz) { + if (localCacheFields.containsKey(clazz)) { + return localCacheFields.get(clazz); + } + + Field[] declaredFields = clazz.getDeclaredFields(); + localCacheFields.putIfAbsent(clazz, declaredFields); + return declaredFields; + } + + public static T copyProperties_methodInvoke(S source, Supplier targetSupplier) { T target = targetSupplier.get(); if (source == null) { return target; @@ -38,9 +90,32 @@ public static T copyProperties(S source, Supplier targetSupplier) { MethodAccess targetMethodAccess = get(target.getClass()); Field[] declaredFields = source.getClass().getDeclaredFields(); for (Field field : declaredFields) { - String name = field.getName(); - Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); try { + String name = field.getName(); + Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); + targetMethodAccess.invoke(target, "set" + StringUtils.capitalize(name), value); + } catch (Exception e) { + // source 中未设置 get 方法的字段,会直接跳过 + // target 中没有 source 中的字段,也会直接跳过 + } + } + + return target; + } + + public static T copyProperties_methodInvoke_V2(S source, Supplier targetSupplier) { + T target = targetSupplier.get(); + if (source == null) { + return target; + } + + MethodAccess sourceMethodAccess = get(source.getClass()); + MethodAccess targetMethodAccess = get(target.getClass()); + Field[] declaredFields = getFields(source.getClass()); + for (Field field : declaredFields) { + try { + String name = field.getName(); + Object value = sourceMethodAccess.invoke(source, "get" + StringUtils.capitalize(name), null); targetMethodAccess.invoke(target, "set" + StringUtils.capitalize(name), value); } catch (Exception e) { // source 中未设置 get 方法的字段,会直接跳过 @@ -54,7 +129,7 @@ public static T copyProperties(S source, Supplier targetSupplier) { public static List copyListProperties(List sources, Supplier targetSupplier) { List list = new ArrayList<>(sources.size()); for (S source : sources) { - T target = copyProperties(source, targetSupplier); + T target = copyProperties_methodInvoke(source, targetSupplier); list.add(target); } return list; diff --git a/src/main/java/common/util/CompareUtil.java b/src/main/java/common/util/CompareUtil.java deleted file mode 100644 index 4e0c0c3b..00000000 --- a/src/main/java/common/util/CompareUtil.java +++ /dev/null @@ -1,18 +0,0 @@ -package common.util; - -import common.datastruct.ListNode; - -/** - * Created by nibnait on 2020/11/20 - */ -public class CompareUtil { - - public static boolean compareListNode(ListNode left, ListNode right) { - while (left != null && right != null && left.val == right.val) { - left = left.next; - right = right.next; - } - return left == right; - } - -} diff --git a/src/main/java/common/util/DateTimeUtil.java b/src/main/java/common/util/DateTimeUtil.java index e10073df..e007da4d 100644 --- a/src/main/java/common/util/DateTimeUtil.java +++ b/src/main/java/common/util/DateTimeUtil.java @@ -1,6 +1,10 @@ package common.util; +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; +import org.apache.commons.lang3.math.NumberUtils; import java.text.DateFormat; import java.text.ParseException; @@ -8,6 +12,7 @@ import java.time.*; import java.time.format.DateTimeFormatter; import java.util.Date; +import java.util.List; public class DateTimeUtil { @@ -108,9 +113,9 @@ public static String localDateTimeToString(LocalDateTime localDateTime, String d } /** - * Date - * LocalDate ==> java.util.Date - * LocalDateTime ( Date.from(ZonedDateTime.toInstant) ) + * Date + * LocalDate ==> java.util.Date + * LocalDateTime ( Date.from(ZonedDateTime.toInstant) ) */ public static Date toUtilDate(Object date) { if (date == null) { @@ -140,8 +145,8 @@ public static Date toUtilDate(Object date) { /** * Date ==> LocalDate - * .toIns - * (ZonedDateTime) + * .toIns + * (ZonedDateTime) */ public static LocalDate dateToLocalDate(Date date) { ZonedDateTime zonedDateTime = date.toInstant().atZone(defaultZoneId); @@ -150,14 +155,13 @@ public static LocalDate dateToLocalDate(Date date) { /** * Date ==> LocalDateTime - * (ZonedDateTime) + * (ZonedDateTime) */ public static LocalDateTime dateToLocalDateTime(Date date) { ZonedDateTime zonedDateTime = date.toInstant().atZone(defaultZoneId); return zonedDateTime.toLocalDateTime(); } - public static final String LONG_TIME_VALID = "长期有效"; /** * 获取当前时间戳 */ @@ -165,24 +169,41 @@ public static Long getTimeInMillis() { return System.currentTimeMillis(); } + /** + * LocalDateTime ==> 秒timestamp + */ + public static Long LocalDateTimeToSecond() { + return LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); + } + + /** + * LocalDateTime ==> 毫秒timestamp + */ + public static Long LocalDateTimeToMillSecond() { + return LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); + } + + public static final String LONG_TIME_VALID = "长期有效"; + /** * 判断是否在有效期内 + * * @param expireDate * @return */ public static boolean isValidDate(String expireDate) { - if(StringUtils.isBlank(expireDate)){ + if (StringUtils.isBlank(expireDate)) { return false; } - if(LONG_TIME_VALID.equals(expireDate)){ + if (LONG_TIME_VALID.equals(expireDate)) { return true; } - try{ + try { LocalDate expireLocalDate = DateTimeUtil.string2Date(expireDate); - if(LocalDate.now().compareTo(expireLocalDate) < 0){ + if (LocalDate.now().compareTo(expireLocalDate) < 0) { return true; } - }catch (Exception e){ + } catch (Exception e) { return false; } return false; @@ -190,6 +211,7 @@ public static boolean isValidDate(String expireDate) { /** * 比较两个日期相差多少天 + * * @param startTime * @param endTime * @return @@ -198,8 +220,83 @@ public static Long durationDays(LocalDateTime startTime, LocalDateTime endTime) return Duration.between(startTime, endTime).toDays(); } + public static Long durationMillis(LocalDateTime startTime, LocalDateTime endTime) { + return Duration.between(startTime, endTime).toMillis(); + } + + /** + * 校验时期合法性 + */ + public static boolean isDateValid(List date) { + boolean isvalid = true; + if (CollectionUtils.isEmpty(date)) { + return false; + } + + try { + if (date.size() == 1) { + return NumberUtils.isParsable(date.get(0)); + } + if (date.size() == 2) { + LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), 1); + } + if (date.size() == 3) { + if (NumberUtils.isParsable(date.get(2))) { + LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), Integer.parseInt(date.get(2))); + } else { + LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), 1); + if (!Lists.newArrayList("上旬", "中上旬", "中旬", "中下旬", "下旬").contains(date.get(2))) { + isvalid = false; + } + } + } + if (date.size() > 3) { + isvalid = false; + } + } catch (Exception e) { + isvalid = false; + } + return isvalid; + } + public static void main(String[] args) { - String s = localDateTimeToString(LocalDateTime.now(), TIME_MILLISECOND_FORMAT); - System.out.println(s); + List date = Lists.newArrayList("2020", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2021", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2022", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2023", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2019", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2024", "02", "29"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2024", "04", "31"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2024", "05", "31"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02", "上旬"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02", "xx"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); + + date = Lists.newArrayList("2020", "02", "中旬", "lj"); + System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); } } diff --git a/src/main/java/common/util/compare/CompareUtil.java b/src/main/java/common/util/compare/CompareUtil.java new file mode 100644 index 00000000..4bb72a24 --- /dev/null +++ b/src/main/java/common/util/compare/CompareUtil.java @@ -0,0 +1,61 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Sets; +import common.bo.compare.CompareBO; +import common.bo.compare.CompareResultDTO; +import common.datastruct.ListNode; +import lombok.extern.slf4j.Slf4j; + +import java.util.Set; + +/** + * Created by nibnait on 2020/11/20 + */ +@Slf4j +public class CompareUtil { + + public static boolean compareListNode(ListNode left, ListNode right) { + while (left != null && right != null && left.val == right.val) { + left = left.next; + right = right.next; + } + return left == right; + } + + public static boolean match(T actual, T expect) { + return match(actual, expect, Sets.newHashSet()); + } + + public static boolean match(T actual, T expect, Set excludeFields) { + CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); + compareBO.setExcludeFields(excludeFields); + + CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); + if (!compareResultDTO.isMatch()) { + log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); + } + return compareResultDTO.isMatch(); + } + + public static boolean compareObject(Object expectObj, Object actualObj) { + + if ((expectObj == null && actualObj != null) || (expectObj != null && actualObj == null)) { + return false; + } + + if (expectObj == null) { + return true; + } + + if (!expectObj.getClass().equals(actualObj.getClass())) { + return false; + } + + if (expectObj instanceof Number && expectObj instanceof Comparable) { + return ((Comparable) expectObj).compareTo(actualObj) == 0; + } + + return expectObj.equals(actualObj); + } +} diff --git a/src/main/java/common/util/compare/JacksonUtils.java b/src/main/java/common/util/compare/JacksonUtils.java new file mode 100644 index 00000000..af9bb61c --- /dev/null +++ b/src/main/java/common/util/compare/JacksonUtils.java @@ -0,0 +1,219 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.ArrayNode; +import com.fasterxml.jackson.databind.node.ObjectNode; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; + +import java.math.BigDecimal; +import java.text.SimpleDateFormat; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +@Slf4j +public class JacksonUtils { + + private static final ObjectMapper MAPPER = new ObjectMapper(); + private static final String SEPARATOR = ":"; + public static final String ARRAY_SIGN = "*"; + public static final String MINUS_SIGN = "\"-\""; + public static final String ARRAY_SIGN_REPLACE = "#"; + public static final String PLACEHOLDER_SIGN = "{}"; + private static final String BLANK_REPLACE = " "; + private static final String EMPTY = ""; + + static { + SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); + MAPPER.setDateFormat(dateFormat); + MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); + } + + public static String replace(String json, String path, Object value) { + if (StringUtils.isBlank(path)) { + return json; + } + // 使用 # 替换, 否则会因为正则导致替换失败 + path = path.replace(ARRAY_SIGN, ARRAY_SIGN_REPLACE); + // 判断是否多级路径 + int lastNodeIndex = path.lastIndexOf(SEPARATOR); + if (lastNodeIndex == -1) { + return replaceField(json, path, path, value); + } + // 判断是否需要循环解析 + if (!path.contains(ARRAY_SIGN_REPLACE)) { + return replaceField(json, path, path.substring(lastNodeIndex + 1), value); + } + // 需要循环解析, 递归 + String prePath = path.substring(0, getArraySignIndex(path)); + String prePathValue = focus(json, prePath); + JsonNode prePathJsonNode = json2Node(prePathValue); + for (int i = 0; i < prePathJsonNode.size(); i++) { + json = replace(json, path.replaceFirst(ARRAY_SIGN_REPLACE, i + ""), value); + } + return json; + } + + private static int getArraySignIndex(String path) { + return path.indexOf(ARRAY_SIGN_REPLACE) == 0 ? 0 : path.indexOf(ARRAY_SIGN_REPLACE) - 1; + } + + public static String focus(String json, String path) { + if (StringUtils.isBlank(path)) { + return json; + } + // 使用 # 替换, 否则会因为正则导致替换失败 + path = path.replace(ARRAY_SIGN, ARRAY_SIGN_REPLACE); + // 判断是否多级路径 + int lastNodeIndex = path.lastIndexOf(SEPARATOR); + if (lastNodeIndex == -1) { + return focusField(json, path); + } + // 判断是否需要循环解析 + if (!path.contains(ARRAY_SIGN_REPLACE)) { + return focusField(json, path); + } + // 需要循环解析, 递归 + List result = new ArrayList<>(); + String prePath = path.substring(0, getArraySignIndex(path)); + String prePathValue = focus(json, prePath); + JsonNode prePathJsonNode = json2Node(prePathValue); + + if (prePathJsonNode == null) { + return MINUS_SIGN; + } + + for (int i = 0; i < prePathJsonNode.size(); i++) { + String str = focus(json, path.replaceFirst(ARRAY_SIGN_REPLACE, i + "")); + result.add(str); + } + Object[] objects = result.toArray(); + // 自然排序 + Arrays.sort(objects); + return JSON.toJSONString(objects).replaceAll(BLANK_REPLACE, EMPTY); + } + + private static String focusField(String json, String path) { + JsonNode jsonNode = json2Node(json); + String[] paths = path.split(SEPARATOR); + for (String fieldName : paths) { + if (jsonNode == null) { + continue; + } + if (jsonNode.isArray()) { + jsonNode = jsonNode.get(Integer.parseInt(fieldName)); + } else { + jsonNode = jsonNode.get(fieldName); + } + } + return node2Json(jsonNode); + } + + private static String replaceField(String json, String path, String key, Object value) { + if (StringUtils.isBlank(path)) { + return json; + } + JsonNode jsonNode = json2Node(json); + JsonNode temp = jsonNode; + String[] paths = path.split(SEPARATOR); + for (String fieldName : paths) { + if (temp == null) { + continue; + } + // 找到 key + if (fieldName.equals(key)) { + if (temp.isArray()) { + JsonNode removeJsonNode = ((ArrayNode) temp).remove(Integer.parseInt(fieldName)); + if (value != null && removeJsonNode != null) { + Class valueClazz = value.getClass(); + if (valueClazz == String.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (String) value); + } else if (valueClazz == Boolean.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Boolean) value); + } else if (valueClazz == Short.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Short) value); + } else if (valueClazz == Integer.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Integer) value); + } else if (valueClazz == Double.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Double) value); + } else if (valueClazz == Long.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Long) value); + } else if (valueClazz == Float.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Float) value); + } else if (valueClazz == BigDecimal.class) { + ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (BigDecimal) value); + } + } + } else { + JsonNode removeJsonNode = ((ObjectNode) temp).remove(fieldName); + if (value != null && removeJsonNode != null) { + Class valueClazz = value.getClass(); + if (valueClazz == String.class) { + ((ObjectNode) temp).put(fieldName, (String) value); + } else if (valueClazz == Boolean.class) { + ((ObjectNode) temp).put(fieldName, (Boolean) value); + } else if (valueClazz == Short.class) { + ((ObjectNode) temp).put(fieldName, (Short) value); + } else if (valueClazz == Integer.class) { + ((ObjectNode) temp).put(fieldName, (Integer) value); + } else if (valueClazz == Double.class) { + ((ObjectNode) temp).put(fieldName, (Double) value); + } else if (valueClazz == Long.class) { + ((ObjectNode) temp).put(fieldName, (Long) value); + } else if (valueClazz == Float.class) { + ((ObjectNode) temp).put(fieldName, (Float) value); + } else if (valueClazz == BigDecimal.class) { + ((ObjectNode) temp).put(fieldName, (BigDecimal) value); + } + } + } + continue; + } + if (temp.isArray()) { + temp = temp.get(Integer.parseInt(fieldName)); + } else { + temp = temp.get(fieldName); + } + } + return node2Json(jsonNode); + } + + private static String node2Json(JsonNode jsonNode) { + if (jsonNode == null) { + return null; + } + String value = jsonNode.asText(); + if (StringUtils.isBlank(value)) { + value = jsonNode.toString(); + } + return value; + } + + private static JsonNode json2Node(String json) { + if (StringUtils.isBlank(json)) { + return null; + } + + JsonNode tempNode = null; + try { + tempNode = MAPPER.readTree(json); + } catch (Exception e) { + log.error("json2Node error json {}", json, e); + } + return tempNode; + } + + public static boolean isJson(String json) { + try { + MAPPER.readTree(json); + } catch (Exception e) { + return false; + } + return true; + } + +} diff --git a/src/main/java/common/util/compare/JsonUtils.java b/src/main/java/common/util/compare/JsonUtils.java new file mode 100644 index 00000000..a877abc8 --- /dev/null +++ b/src/main/java/common/util/compare/JsonUtils.java @@ -0,0 +1,242 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson.JSONArray; +import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson.serializer.SerializerFeature; +import com.google.common.collect.Lists; +import com.json.comparison.JsonCompare; +import com.json.comparison.JsonComparisonResult; +import com.json.comparison.comprator.model.api.FieldComparison; +import common.bo.compare.CompareBO; +import common.bo.compare.CompareResultDTO; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.helpers.MessageFormatter; + +import java.util.ArrayList; +import java.util.Collection; +import java.util.List; +import java.util.Set; +import java.util.stream.Collectors; + +@Slf4j +public class JsonUtils { + + public static CompareResultDTO diffJsonObject(JSONObject actualObject, JSONObject expectObject, Set focusFields) { + CompareResultDTO compareResultDTO = new CompareResultDTO(); + if (CollectionUtils.isEmpty(focusFields)) { + compareResultDTO.setMatch(true); + return compareResultDTO; + } + + List modifiedFields = Lists.newArrayList(); + for (String key : focusFields) { + String actual = actualObject.getString(key); + String expect = expectObject.getString(key); + if (!CompareUtil.compareObject(expect, actual)) { + addModifyFields(key, actual, expect, modifiedFields); + } + } + + compareResultDTO.setMatch(CollectionUtils.isEmpty(modifiedFields)); + compareResultDTO.setModifiedFields(modifiedFields); + return compareResultDTO; + } + + private static void addModifyFields(String key, String actual, String expect, List modifiedFields) { + CompareResultDTO.FieldComparison comparison = new CompareResultDTO.FieldComparison(); + comparison.setField(key); + comparison.setExpected(expect); + comparison.setActual(actual); + + modifiedFields.add(comparison); + } + + public static CompareResultDTO diffStr(String actualStr, String expectStr, CompareBO compareBO) { + // 判断是不是标准 json, 是 json 则不转, 否则会发生转义 + if (!JacksonUtils.isJson(actualStr)) { + try { + actualStr = JSON.toJSONString(JSON.parseObject(actualStr), SerializerFeature.WriteMapNullValue); + } catch (Exception e) { + // ignore + } + } + if (!JacksonUtils.isJson(expectStr)) { + try { + expectStr = JSON.toJSONString(JSON.parseObject(expectStr), SerializerFeature.WriteMapNullValue); + } catch (Exception e) { + // ignore + } + } + return diffStr0(actualStr, expectStr, compareBO); + } + + private static CompareResultDTO diffStr0(String actualStr, String expectStr, CompareBO compareBO) { + CompareResultDTO compareResultDTO = new CompareResultDTO(); + compareResultDTO.setMatch(true); + + // 如果不是 json 数据, 直接当成字符串匹配 + if (!JacksonUtils.isJson(actualStr) || !JacksonUtils.isJson(expectStr)) { + compareResultDTO.setMatch(actualStr.equals(expectStr)); + } + Set optimizations = compareBO.getOptimizations(); + Set focusFields = compareBO.getFocusFields(); + Set excludeFields = compareBO.getExcludeFields(); + // 1. 系统默认优化项: 如果开启了则添加到聚焦字段 + for (CompareBO.OptimizationType optimization : optimizations) { + // 如果是分页插件, 则只关注 data:list 数据内容 + if (optimization == CompareBO.OptimizationType.PAGE_HELPER) { + // 判断是否满足条件, 以是否包含 navigatePages、pageSize 为标准 + if (expectStr.contains("navigatePages") && expectStr.contains("pageSize")) { + focusFields.add("list"); + } + } + } + // 2. 排除字段: 如果有先把指定字段移除 + if (excludeFields.size() > 0) { + for (String excludeField : excludeFields) { + actualStr = JacksonUtils.replace(actualStr, excludeField, null); + expectStr = JacksonUtils.replace(expectStr, excludeField, null); + } + } + // 3. 无聚焦字段: 直接匹配字符串 + if (focusFields.size() <= 0) { + return jsonEqual(actualStr, expectStr, compareBO); + } + // 4. 有聚焦字段: 取出依次比较 + ArrayList modifiedFields = Lists.newArrayList(); + ArrayList missingFields = Lists.newArrayList(); + ArrayList newFields = Lists.newArrayList(); + for (String focusField : focusFields) { + String actualValue = JacksonUtils.focus(actualStr, focusField); + String expectValue = JacksonUtils.focus(expectStr, focusField); + + compareBO.setCurrentField(focusField); + CompareResultDTO currentFieldCompareResult = jsonEqual(actualValue, expectValue, compareBO); + + if (!currentFieldCompareResult.isMatch()) { + compareResultDTO.setMatch(false); + } + modifiedFields.addAll(currentFieldCompareResult.getModifiedFields()); + missingFields.addAll(currentFieldCompareResult.getMissingFields()); + newFields.addAll(currentFieldCompareResult.getNewFields()); + } + // 所有聚焦字段比较完后, 直接返回 true + compareResultDTO.setModifiedFields(modifiedFields); + compareResultDTO.setMissingFields(missingFields); + compareResultDTO.setNewFields(newFields); + + return compareResultDTO; + } + + public static CompareResultDTO jsonEqual(String actual, String expect, CompareBO compareBO) { + // 5. 先用 json 判断是否相等 + JsonComparisonResult comparisonResult = compare(actual, expect, compareBO); + + CompareResultDTO compareResultDTO = new CompareResultDTO(false); + if (comparisonResult == null) { + return compareResultDTO; + } + + compareResultDTO.setMatch(comparisonResult.isMatch()); + compareResultDTO.setModifiedFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getModifiedFields())); + compareResultDTO.setMissingFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getMissingFields())); + compareResultDTO.setNewFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getNewFields())); + + // 如果全部比对成功, 直接返回 true + if (comparisonResult.isMatch()) { + compareResultDTO.setMatch(true); + } + // 6. 如果有修改字段, 直接返回失败 + if (CollectionUtils.isNotEmpty(comparisonResult.getModifiedFields())) { + compareResultDTO.setMatch(false); + return compareResultDTO; + } + // 7. 程序走到这里, 表明有两种情况, 一种是新增了字段, 一种是丢失了字段, 所以需要判断是否开启了忽略功能 + // 7.1 如果全部开启, 直接返回 true + if (compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_NEW_FIELDS) && + compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_MISSING_FIELDS)) { + compareResultDTO.setMatch(true); + } + // 7.2 只开启忽略新增字段, 那么只需要判断是否有丢失字段即可 + else if (compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_NEW_FIELDS)) { + compareResultDTO.setMatch(CollectionUtils.isEmpty(comparisonResult.getMissingFields())); + } + // 7.3 只开启忽略丢失字段, 那么只需要判断新增字段即可 + else { + compareResultDTO.setMatch(CollectionUtils.isEmpty(comparisonResult.getNewFields())); + } + + return compareResultDTO; + } + + private static JsonComparisonResult compare(String actual, String expect, CompareBO compareBO) { + JsonComparisonResult comparisonResult = null; + try { + comparisonResult = JsonCompare.builder().build().compare(expect, actual); + } catch (Exception e) { + log.error("JsonUtils.jsonEqual error", e); + } + + if (comparisonResult == null || !comparisonResult.isMatch()) { + log.info("JsonUtils.jsonEqual false compareBO:{}", JSON.toJSONString(compareBO)); + log.info("JsonUtils.jsonEqual false actual:{}", actual); + log.info("JsonUtils.jsonEqual false expect:{}", expect); + } + return comparisonResult; + } + + private static List getFieldComparisonList(String currentField, Collection modifiedFieldList) { + return modifiedFieldList.stream() + .map(comparison -> convertToFieldComparison(currentField, comparison)) + .collect(Collectors.toList()); + } + + private static CompareResultDTO.FieldComparison convertToFieldComparison(String currentField, FieldComparison comparison) { + CompareResultDTO.FieldComparison fieldComparison = new CompareResultDTO.FieldComparison(); + + try { + Integer[] indexArray = getIndexArray(comparison.getField()); + currentField = currentField.replace(JacksonUtils.ARRAY_SIGN, JacksonUtils.PLACEHOLDER_SIGN); + fieldComparison.setField(MessageFormatter.arrayFormat(currentField, indexArray).getMessage()); + } catch (Exception e) { + if (StringUtils.isBlank(currentField)) { + currentField = comparison.getField(); + } + if ("list".equals(currentField)) { + currentField = currentField + comparison.getField(); + } + fieldComparison.setField(currentField); + } + + fieldComparison.setExpected(comparison.getExpected()); + fieldComparison.setActual(comparison.getActual()); + return fieldComparison; + } + + private static Integer[] getIndexArray(String field) { + JSONArray jsonArray; + try { + jsonArray = JSON.parseArray(field); + Integer[] indexArray = new Integer[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + indexArray[i] = (int) jsonArray.get(i); + } + return indexArray; + } catch (Exception e) { + field = "[" + field + "]"; + jsonArray = JSON.parseArray(field); + Integer[] indexArray = new Integer[jsonArray.size()]; + for (int i = 0; i < jsonArray.size(); i++) { + JSONArray arr = (JSONArray) jsonArray.get(i); + indexArray[i] = (int) arr.get(0); + } + return indexArray; + } + + + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" index beae8474..18a925e0 100644 --- "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" +++ "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" @@ -1,50 +1,85 @@ package org.tianbin.java.反射; -import java.beans.IntrospectionException; +import cn.hutool.log.Log; +import cn.hutool.log.LogFactory; +import com.alibaba.fastjson.JSON; +import org.apache.commons.collections4.MapUtils; +import org.springframework.beans.BeanUtils; + import java.beans.PropertyDescriptor; -import java.lang.reflect.Field; -import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; import java.lang.reflect.Modifier; +import java.util.HashMap; +import java.util.List; import java.util.Map; /** * Created by nibnait on 2020/11/11 */ +@Deprecated public class CompareUtil { - public static void compare(Object thisObj, Object thatObj, Map errorMap) { + private static final Log log = LogFactory.get(CompareUtil.class); + + /** + * 返回 true/false + * @param whiteFiledList 不需要核对的字段 + */ + public static boolean compareBool(Object leftObj, Object rightObj, List whiteFiledList) { + Map errorMap = compare(leftObj, rightObj, whiteFiledList); + + if (MapUtils.isNotEmpty(errorMap)) { + log.info("CompareUtils.errorMap: {}, leftObj: {}, rightObj: {}", + JSON.toJSONString(errorMap), + JSON.toJSONString(leftObj), JSON.toJSONString(rightObj)); + } + return MapUtils.isEmpty(errorMap); + } + /** + * 返回 errorMap + * @param whiteFiledList 不需要核对的字段 + */ + public static Map compare(Object leftObj, Object rightObj, List whiteFiledList) { + Map errorMap = new HashMap<>(); try { - Class clazz = thisObj.getClass(); - Field[] fields = clazz.getDeclaredFields(); + PropertyDescriptor[] propertyDescriptors = BeanUtils.getPropertyDescriptors(leftObj.getClass()); + + if (propertyDescriptors == null || propertyDescriptors.length <= 1) { + return errorMap; + } + + for (int i = 1; i < propertyDescriptors.length; i++) { + PropertyDescriptor propertyDescriptor = propertyDescriptors[i]; + String fieldName = propertyDescriptor.getName(); - for (Field field : fields) { - if (field.getModifiers() != Modifier.PRIVATE) { + if (whiteFiledList.contains(fieldName)) { continue; } - // 排除静态字段 - PropertyDescriptor propertyDescriptor = new PropertyDescriptor(field.getName(), clazz); // 获得get方法 - Method getMethod = propertyDescriptor.getReadMethod(); + Method readMethod = propertyDescriptor.getReadMethod(); + + if (!Modifier.isPublic(readMethod.getDeclaringClass().getModifiers())) { + readMethod.setAccessible(true); + } - Object leftProperty = getMethod.invoke(thisObj); - Object rightProperty = getMethod.invoke(thatObj); + Object leftProperty = readMethod.invoke(leftObj); + Object rightProperty = readMethod.invoke(rightObj); boolean pass = compareObject(leftProperty, rightProperty); if (!pass) { - addToErrMap(errorMap, leftProperty, rightProperty, thisObj.getClass().getSimpleName(), getMethod.getName()); + addToErrMap(errorMap, leftProperty, rightProperty, leftObj.getClass().getSimpleName(), fieldName); } + } - } catch (IntrospectionException e) { - errorMap.put("比对", "核对发生IntrospectionException异常"); - } catch (IllegalAccessException e) { - errorMap.put("比对", "核对发生IllegalAccessException异常"); - } catch (InvocationTargetException e) { - errorMap.put("比对", "核对发生InvocationTargetException异常"); + + } catch (Exception e) { + log.error(e, "CompareUtils error " + e.getMessage()); + errorMap.put("比对", "核对发生异常"); } + return errorMap; } private static void addToErrMap(Map errorMap, Object leftProperty, Object rightProperty, String className, String fieldName) { @@ -66,7 +101,7 @@ private static boolean compareObject(Object thisObj, Object thatObj) { return false; } - if (thisObj == null && thatObj == null) { + if (thisObj == null) { return true; } diff --git "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" index f263cd93..83c22cf4 100644 --- "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" +++ "b/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" @@ -1,12 +1,17 @@ package org.tianbin.java.反射; import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import common.model.Person; import lombok.AllArgsConstructor; import lombok.Data; import lombok.NoArgsConstructor; import org.junit.Test; +import java.math.BigDecimal; +import java.util.ArrayList; import java.util.HashMap; +import java.util.List; import java.util.Map; /** @@ -17,30 +22,72 @@ public class Main { @Test public void test01() { Order left = getLeftValue(); - Order right = getRightValue(); - Map errorMap = new HashMap<>(); - left.compareTo(right, errorMap); + Map errorMap = CompareUtil.compare(left, right, Lists.newArrayList("testByte")); System.out.println(JSON.toJSONString(errorMap)); } - private Order getRightValue() { - Order order = new Order(2, "456"); - Map detailJson = new HashMap<>(); - + private Order getLeftValue() { + Order order = new Order(); + order.setOrderId(0L); + order.setTestInteger(0); + order.setTestLong(0L); + order.setTestByte((byte)0); + order.setTestDouble(0.0D); + order.setTestFloat(1.0F); + order.setPrice(BigDecimal.valueOf(0)); + order.setPhone(""); + Map detailJson = new HashMap<>(); + detailJson.put("1", "1"); order.setDetailJson(detailJson); + + ArrayList personList = Lists.newArrayList(); + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone(""); + person.setIsBigBoolean(false); + person.setSmallBoolean(false); + personList.add(person); + order.setPersonList(personList); + + order.setIsBigBoolean(true); + order.setSmallBoolean(true); return order; } - private Order getLeftValue() { - Order order = new Order(1, "123"); - Map detailJson = new HashMap<>(); - + private Order getRightValue() { + Order order = new Order(); + order.setOrderId(1L); + order.setTestInteger(1); + order.setTestLong(1L); + order.setTestByte((byte)1); + order.setTestDouble(0.1D); + order.setTestFloat(1.0F); + order.setPrice(BigDecimal.valueOf(1)); + order.setPhone(""); + Map detailJson = new HashMap<>(); + detailJson.put("1", "2"); order.setDetailJson(detailJson); + + ArrayList personList = Lists.newArrayList(); + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone(""); + person.setIsBigBoolean(true); + person.setSmallBoolean(true); + personList.add(person); + order.setPersonList(personList); + + order.setIsBigBoolean(false); + order.setSmallBoolean(false); return order; } @@ -50,32 +97,18 @@ private Order getLeftValue() { @AllArgsConstructor class Order { private long orderId; + private Integer testInteger; + private Long testLong; + private Byte testByte; + private Double testDouble; + private Float testFloat; + private BigDecimal price; private String phone; - private Map detailJson; + private List personList; + private Boolean isBigBoolean; + private boolean isSmallBoolean; - public Order(long orderId, String phone) { - this.orderId = orderId; - this.phone = phone; - } - - public boolean compareTo(Object that, Map errorMap) { - if (that == null) { - errorMap.put("比对", "当前右值为空"); - } - - if (!(that instanceof Order)) { - errorMap.put("比对", "右值类型不对"); - } - - // 校验 本次比对是否跳过 - // 初始化白名单 - // 初始化黑名单 - - CompareUtil.compare(this, that, errorMap); - - return errorMap.size() == 0; - } } diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" index ec2df820..055d4f0c 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" @@ -3,6 +3,7 @@ import org.junit.Test; import java.math.BigDecimal; +import java.math.RoundingMode; /** * Created by nibnait on 2020/11/11 @@ -10,14 +11,53 @@ public class BigDecimalTest { @Test - public void testCase() { + public void test04() { + int i = 1; + BigDecimal bigDecimal1 = new BigDecimal(i); + System.out.println(bigDecimal1); + + double d = 1.83; + BigDecimal bigDecimal2 = new BigDecimal(d); + System.out.println(bigDecimal2); + + BigDecimal divide = bigDecimal2.divide(BigDecimal.valueOf(2), 2, RoundingMode.HALF_UP); + System.out.println(divide); + } + + @Test + public void test03() { + Double d1 = 1.0; + System.out.println("d1 = " + BigDecimal.valueOf(d1).stripTrailingZeros()); + Double d2 = 1.00; + System.out.println("d2 = " + BigDecimal.valueOf(d2).stripTrailingZeros()); + Double d3 = 1.000; + System.out.println("d3 = " + BigDecimal.valueOf(d3).stripTrailingZeros()); + Double d4 = 1.001; + System.out.println("d4 = " + BigDecimal.valueOf(d4).stripTrailingZeros()); + Double d5 = 1.01; + System.out.println("d5 = " + BigDecimal.valueOf(d5).stripTrailingZeros()); + Double d6 = 1.11; + System.out.println("d6 = " + BigDecimal.valueOf(d6).stripTrailingZeros()); + } + + @Test + public void test02() { + System.out.println(BigDecimal.valueOf(getInt())); + } + + private Integer getInt() { + return null; + } + + @Test + public void test01() { double value = 100.2; BigDecimal bigDecimal = new BigDecimal(value); BigDecimal bigDecimal1 = BigDecimal.valueOf(value); - System.out.println(bigDecimal); - System.out.println(bigDecimal1); + System.out.println("new " + bigDecimal); + System.out.println("valueOf " + bigDecimal1); } } diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" new file mode 100644 index 00000000..9853dd51 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" @@ -0,0 +1,49 @@ +package org.tianbin.java.基本数据类型; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/06/02 + */ +public class DoubleTest { + + @Test + public void test01() { + String s = "19.9"; + Double d = Double.valueOf(s); + System.out.println(d); + } + + @Test + public void test02() { + double d = 19.9; + + double v = d * 100; + System.out.println(v); + + int i = (int)v; + System.out.println(i); + + int d1 = 1989; + double d2 = (double) d1 / 100; + System.out.println(d2); + + d1 = 1990; + d2 = (double) d1 / 100; + System.out.println(d2); + + } + + @Test + public void test03() { + double d = 19.9; + + double v = d * 0.5; + System.out.println(v); + + int i = (int)v; + System.out.println(i); + + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" new file mode 100644 index 00000000..309433da --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" @@ -0,0 +1,40 @@ +package org.tianbin.java.基本数据类型; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/03/18 + */ +public class IntegerTest { + + @Test + public void testCompareTo() { + Integer old = 110; + Integer newI = 11110; + System.out.println(newI - old); + + old = 122222; + newI = 2222; + System.out.println(newI - old); + + old = 77777; + newI = 77777; + System.out.println(newI - old); + } + + @Test + public void test02() { + int i1 = 166; + System.out.println(i1 / 100); + int i2 = 133; + System.out.println(i2 / 100); + } + + @Test + public void test01() { + String s = "xxx"; + int i = Integer.parseInt(s); + System.out.println(i); + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" index 56ac012a..b10fad13 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" @@ -3,6 +3,7 @@ import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import junit.framework.TestCase; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import java.util.Stack; @@ -12,6 +13,12 @@ */ public class StringTest extends TestCase { + @Test + public void testStringUtils() { + StringUtils.isEmpty(""); + StringUtils.isBlank(""); + } + @Test public void testGetLong() { String str = "{\"bizNo\":\"111\"}"; @@ -32,6 +39,8 @@ public void testCase() { public void testSubString() { String str = "123"; System.out.println(str.substring(0, str.length() - 1)); + + //output: 12 } @Test diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" index e7ac4fd0..36c390c1 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" @@ -21,11 +21,11 @@ public class b1_FutureTaskDemo extends TestCase { 烧水泡茶 分工: T1: 洗水壶(1min) --> 烧开水(15min) --> 泡茶 /\ - T2: 洗茶壶(1min) | + T2: 洗茶壶(1min) | | | - 洗茶杯(2min) | + 洗茶杯(2min) | | | - 拿茶叶(1min)———————— + 拿茶叶(1min)————————- */ @Test diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" new file mode 100644 index 00000000..eb2d6ec3 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" @@ -0,0 +1,78 @@ +package org.tianbin.java.并发.threadpool; + +import junit.framework.TestCase; +import org.junit.Test; + +import java.util.concurrent.CompletableFuture; +import java.util.concurrent.ExecutorService; +import java.util.concurrent.Executors; +import java.util.concurrent.TimeUnit; + +import static common.util.SystemUtil.sleep; + +/** + * 任务之间有聚合关系:CompletableFuture + * + * T3需要等待T1 和 T2 执行完,在开始执行 + * + * Created by nibnait on 2019-09-01 + */ +public class b2_CompletableFutureDemo2 extends TestCase { + + /** + * T1:洗水壶(1min) --> 烧开水(15min) + * T2:洗茶壶(1min) --> 洗茶杯(2min) --> 拿茶叶(1min) + *

+ * T3:泡茶 + */ + @Test + public void testMain() { + //任务1:洗水壶->烧开水 +// CompletableFuture f1 = CompletableFuture.runAsync( +// () -> { +// System.out.println("T1:洗水壶..."); +// sleep(1, TimeUnit.SECONDS); +// System.out.println("T1:烧开水..."); +// sleep(15, TimeUnit.SECONDS); +// }); + + //任务2:洗茶壶->洗茶杯->拿茶叶 + CompletableFuture f1 = CompletableFuture.supplyAsync( + () -> { + System.out.println("T2:洗茶壶..."); + sleep(1, TimeUnit.SECONDS); + System.out.println("T2:洗茶杯..."); + sleep(2, TimeUnit.SECONDS); + System.out.println("T2:拿茶叶..."); + sleep(20, TimeUnit.SECONDS); + return "⻰井"; + }); + + String taskId = "123"; + Integer time = 10; + TimeUnit timeUnit = TimeUnit.MINUTES; + + try { + ExecutorService executorService = Executors.newSingleThreadExecutor(); + executorService.execute(() -> getF1Return(f1, taskId, time, timeUnit)); + + } catch (Exception e) { + + } + + + System.out.println("end"); + sleep(10, TimeUnit.MINUTES); + } + + private String getF1Return(CompletableFuture f1, String taskId, Integer time, TimeUnit timeUnit) { + try { + String s = f1.get(); + System.out.println(s + " ... " + taskId); + } catch (Exception e) { + + } + return taskId; + } + +} diff --git "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" rename to "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" index 375668f2..c20781f5 100644 --- "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List.java" +++ "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" @@ -7,7 +7,7 @@ * @author nibnait * @version $Id: List.java, v 0.1 2019-08-15 上午10:58 nibnait Exp $$ */ -public class List { +public class List类 { public static void main(String[] args) { Queue queue; diff --git "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" rename to "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" index d616f0ad..cdb2e63e 100644 --- "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map.java" +++ "b/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" @@ -8,7 +8,7 @@ * @author nibnait * @version $Id: Map.java, v 0.1 2019-08-12 下午2:16 nibnait Exp $$ */ -public class Map { +public class Map类 { public static void main(String[] args) { Hashtable hashtable; diff --git a/src/main/test/common/util/DateTimeUtilTest.java b/src/main/test/common/util/DateTimeUtilTest.java new file mode 100644 index 00000000..2c0f3af1 --- /dev/null +++ b/src/main/test/common/util/DateTimeUtilTest.java @@ -0,0 +1,16 @@ +package common.util; + +import org.junit.Test; + +import java.util.Date; + +/** + * Created by nibnait on 2021/04/07 + */ +public class DateTimeUtilTest { + @Test + public void test01() { + Date date = new Date(); + System.out.println(date.getTime()); + } +} diff --git a/src/main/test/org/tianbin/Main.java b/src/main/test/org/tianbin/Main.java index 5dbb0d3a..2c45612f 100644 --- a/src/main/test/org/tianbin/Main.java +++ b/src/main/test/org/tianbin/Main.java @@ -8,7 +8,9 @@ public class Main extends TestCase { public static void main(String[] args) { - System.out.println(9/2); + Byte b = 1; + Byte i = null; + System.out.println(b.equals(i)); } } \ No newline at end of file diff --git a/src/main/test/org/tianbin/temp/ExcelGen.java b/src/main/test/org/tianbin/excel/ExcelGen.java similarity index 98% rename from src/main/test/org/tianbin/temp/ExcelGen.java rename to src/main/test/org/tianbin/excel/ExcelGen.java index 848dc2f1..a40e2512 100644 --- a/src/main/test/org/tianbin/temp/ExcelGen.java +++ b/src/main/test/org/tianbin/excel/ExcelGen.java @@ -1,4 +1,4 @@ -package org.tianbin.temp; +package org.tianbin.excel; import com.google.common.collect.Lists; import common.bo.EmailBO; diff --git a/src/main/test/org/tianbin/excel/ExcelRead.java b/src/main/test/org/tianbin/excel/ExcelRead.java new file mode 100644 index 00000000..a8c1d99d --- /dev/null +++ b/src/main/test/org/tianbin/excel/ExcelRead.java @@ -0,0 +1,10 @@ +package org.tianbin.excel; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/03/26 + */ +public class ExcelRead { + +} diff --git a/src/main/test/org/tianbin/java/ObjectTest.java b/src/main/test/org/tianbin/java/ObjectTest.java new file mode 100644 index 00000000..1d174137 --- /dev/null +++ b/src/main/test/org/tianbin/java/ObjectTest.java @@ -0,0 +1,19 @@ +package org.tianbin.java; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/04/01 + */ +public class ObjectTest { + + @Test + public void testEquals() { + Byte saleType = null; + Byte saleType1 = 1; + + boolean equals = saleType1.equals(saleType); + System.out.println(equals); + + } +} diff --git a/src/main/test/org/tianbin/java/SwitchCaseTest.java b/src/main/test/org/tianbin/java/SwitchCaseTest.java new file mode 100644 index 00000000..f801b6ca --- /dev/null +++ b/src/main/test/org/tianbin/java/SwitchCaseTest.java @@ -0,0 +1,29 @@ +package org.tianbin.java; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/07/13 + */ +public class SwitchCaseTest { + + @Test + public void test01() { + +// Integer i = 1; + Integer i = null; + + switch (i) { + case 1: + System.out.println("1:" + i); +// break; + case 2: + System.out.println("2:" + i); +// break; + default: + System.out.println("default:" + i); + } + + } + +} diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" index a90aeb3d..00e1b69f 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" @@ -4,6 +4,7 @@ import common.model.Person; import common.model.PersonDTO; import common.util.CommonBeanUtil; +import net.sf.cglib.beans.BeanCopier; import org.junit.Test; import java.util.ArrayList; @@ -14,13 +15,34 @@ */ public class CommonBeanUtilTest { + @Test + public void testBeanCopier() { + Person person = new Person(); + person.setName("123"); + person.setAge(1); + person.setGender((byte)2); + person.setPhone("13288889999"); + person.setIsBigBoolean(true); + person.setSmallBoolean(true); + + person.getIsBigBoolean(); + + person.isSmallBoolean(); + + BeanCopier beanCopier = BeanCopier.create(Person.class, PersonDTO.class, false); + PersonDTO personDTO = new PersonDTO(); + beanCopier.copy(person, personDTO, null); + + System.out.println(JSON.toJSONString(personDTO)); + } + @Test public void copyProperties() { Person source = new Person(); source.setName("111"); source.setAge(22); - PersonDTO personDTO = CommonBeanUtil.copyProperties(source, PersonDTO::new); + PersonDTO personDTO = CommonBeanUtil.copyProperties_methodInvoke(source, PersonDTO::new); System.out.println(JSON.toJSONString(personDTO)); } diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" new file mode 100644 index 00000000..05d24757 --- /dev/null +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" @@ -0,0 +1,125 @@ +package org.tianbin.java.反射; + +import common.model.Person; +import common.model.PersonDTO; +import common.util.CommonBeanUtil; +import common.util.DateTimeUtil; +import org.junit.Test; + +import java.time.LocalDateTime; + +/** + * Created by nibnait on 2021/03/23 + */ +public class CopyProperties_性能测试 { + + private static final int cycleTimes = 10000000; + + @Test + public void main() { + test_BeanCopier(); + test_BeanUtils(); +// test_fieldGetSet(); +// test_methodInvoke(); +// test_methodInvoke_V2(); + + + /* + copyProperties_BeanCopier 960ms + copyProperties_BeanUtils 2158ms + copyProperties_fieldGetSet 130803ms + copyProperties_methodInvoke 45393ms + copyProperties_methodInvoke_V2 49951ms + */ + } + + @Test + public void test_BeanCopier() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_BeanCopier(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_BeanCopier " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_BeanUtils() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_BeanUtils(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_BeanUtils " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_fieldGetSet() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_fieldGetSet(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_fieldGetSet " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_methodInvoke() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_methodInvoke(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_methodInvoke " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } + + @Test + public void test_methodInvoke_V2() { + Person person = new Person(); + person.setName(""); + person.setAge(0); + person.setGender((byte)0); + person.setPhone("13288889999"); + + LocalDateTime startTime = LocalDateTime.now(); + for (int i = 0; i < cycleTimes; i++) { + CommonBeanUtil.copyProperties_methodInvoke_V2(person, PersonDTO::new); + } + LocalDateTime endTime = LocalDateTime.now(); + + System.out.println("copyProperties_methodInvoke_V2 " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + + } +} diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" new file mode 100644 index 00000000..e69de29b diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" new file mode 100644 index 00000000..24053c3c --- /dev/null +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" @@ -0,0 +1,47 @@ +package org.tianbin.java.集合; + +import common.model.Person; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.List; +import java.util.stream.Collectors; + +/** + * Created by nibnait on 2021/05/20 + */ +public class ListStreamTest { + + @Test + public void test01() { + + + List personList = new ArrayList<>(); + + Person p1 = new Person(); + p1.setAge(1); + personList.add(p1); + Person p3 = new Person(); + p3.setAge(3); + personList.add(p3); + Person p2 = new Person(); + p2.setAge(2); + personList.add(p2); + + + System.out.println(personList); + List collect = personList.stream() + .sorted(Comparator.comparing(Person::getAge)) + .map(Person::getAge) + .collect(Collectors.toList()); + System.out.println(collect); + + List collectReversed = personList.stream() + .sorted(Comparator.comparing(Person::getAge).reversed()) + .map(Person::getAge) + .collect(Collectors.toList()); + System.out.println(collectReversed); + } + +} diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 0e98c4dd..46e91527 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -3,12 +3,12 @@ import com.alibaba.fastjson.JSONObject; import com.google.common.base.Functions; import com.google.common.collect.Lists; -import common.util.CommonBeanUtil; import org.junit.Test; import java.util.ArrayList; import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; /* @@ -16,6 +16,27 @@ */ public class ListTest { + @Test + public void testContains() { + Integer i = null; + List list = Lists.newArrayList(1); + System.out.println(list.contains(i)); + } + + @Test + public void test03() { + List strList = Lists.newArrayList("1","2"); + System.out.println(strList.stream().collect(Collectors.joining(","))); + } + + @Test + public void test02() { + List list = Lists.newArrayList(); + for (Integer integer : list) { + System.out.println(integer.intValue()); + } + } + @Test public void copyListProperties() { List list = Lists.newArrayList(2,1,3); diff --git a/src/main/test/org/tianbin/temp/JsonParseTest.java b/src/main/test/org/tianbin/temp/JsonParseTest.java index 34c1e790..a0a54216 100644 --- a/src/main/test/org/tianbin/temp/JsonParseTest.java +++ b/src/main/test/org/tianbin/temp/JsonParseTest.java @@ -1,5 +1,6 @@ package org.tianbin.temp; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import junit.framework.TestCase; import org.apache.commons.lang3.StringUtils; @@ -10,6 +11,12 @@ */ public class JsonParseTest extends TestCase { + @Test + public void test() { + String s = JSON.toJSONString(null); + System.out.println(s); + } + @Test public void testCase() { From aa306f5bb00810028320f66438e00001a2a0aad9 Mon Sep 17 00:00:00 2001 From: tianbin Date: Sun, 22 Aug 2021 20:59:26 +0800 Subject: [PATCH 04/36] =?UTF-8?q?FluentValidator=20=E9=93=BE=E5=BC=8F?= =?UTF-8?q?=E8=B0=83=E7=94=A8=E9=AA=8C=E8=AF=81=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../common/exception/ClientViewException.java | 43 ++++++ src/main/java/common/util/DataUtils.java | 83 +++++++++++ .../common/util/validate/FluentValidator.java | 136 ++++++++++++++++++ .../java/common/util/validate/Validator.java | 24 ++++ .../validate/context/ValidateContext.java | 127 ++++++++++++++++ .../context/ValidateContextAttrKey.java | 22 +++ .../validate/context/ValidateElement.java | 24 ++++ .../util/validate/context/ValidateResult.java | 34 +++++ .../validate/validator/OperatorValidator.java | 29 ++++ .../tianbin/java/proxy/jdk/HelloService.java | 2 + .../java/proxy/jdk/HelloServiceImpl.java | 5 + .../Main.java" | 2 +- .../HelloServiceProxy.java" | 7 +- .../util/validate/FluentValidatorTest.java | 7 + 14 files changed, 543 insertions(+), 2 deletions(-) create mode 100644 src/main/java/common/exception/ClientViewException.java create mode 100644 src/main/java/common/util/DataUtils.java create mode 100644 src/main/java/common/util/validate/FluentValidator.java create mode 100644 src/main/java/common/util/validate/Validator.java create mode 100644 src/main/java/common/util/validate/context/ValidateContext.java create mode 100644 src/main/java/common/util/validate/context/ValidateContextAttrKey.java create mode 100644 src/main/java/common/util/validate/context/ValidateElement.java create mode 100644 src/main/java/common/util/validate/context/ValidateResult.java create mode 100644 src/main/java/common/util/validate/validator/OperatorValidator.java create mode 100644 src/main/test/common/util/validate/FluentValidatorTest.java diff --git a/src/main/java/common/exception/ClientViewException.java b/src/main/java/common/exception/ClientViewException.java new file mode 100644 index 00000000..937414a3 --- /dev/null +++ b/src/main/java/common/exception/ClientViewException.java @@ -0,0 +1,43 @@ +package common.exception; + +import common.util.DataUtils; + +public class ClientViewException extends RuntimeException { + + private Long code; + + private String message; + + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + public String getMsg() { + return message; + } + + public void setMsg(String message) { + this.message = message; + } + + public ClientViewException() { super(); } + + public ClientViewException(String message){ + super(message); + } + + public ClientViewException(String message, Object... args) { + super(DataUtils.format(message, args)); + } + + public ClientViewException(Long code, String message){ + super(message); + this.code = code; + this.message = message; + } + +} diff --git a/src/main/java/common/util/DataUtils.java b/src/main/java/common/util/DataUtils.java new file mode 100644 index 00000000..55e9cbd5 --- /dev/null +++ b/src/main/java/common/util/DataUtils.java @@ -0,0 +1,83 @@ +package common.util; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Lists; +import com.google.common.collect.Maps; +import com.google.common.collect.Sets; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.lang3.StringUtils; +import org.slf4j.helpers.MessageFormatter; + +import java.util.Collection; +import java.util.List; + +/** + * Created by nibnait on 2021/08/18 + */ +@Slf4j +public class DataUtils { + + /** + * 返回 list1 - (list1 ∩ list2) + */ + public static List difference(Collection list1, Collection list2) { + return Lists.newArrayList(Sets.difference(Sets.newHashSet(list1), Sets.newHashSet(list2))); + } + + /** + * 返回交集 list1 ∩ list2 + */ + public static List intersection(Collection list1, Collection list2) { + return Lists.newArrayList(Sets.intersection(Sets.newHashSet(list1), Sets.newHashSet(list2))); + } + + /** + * @param format abc{}e + * @param args d + * @return abcde + */ + public static String format(String format, Object... args) { + return MessageFormatter.arrayFormat(format, args).getMessage(); + } + + /** + * @param clazz 类型不可为抽象类/接口 + */ + public static T parseObject(String s, Class clazz) { + if (StringUtils.isBlank(s) || "null".equalsIgnoreCase(s)) { + try { + return clazz.newInstance(); + } catch (InstantiationException | IllegalAccessException e) { + log.error(e.getMessage(), e); + return null; + } + } + try { + return JSON.parseObject(s, clazz); + } catch (Throwable e) { + log.error(e.getMessage(), e); + return null; + } + } + + public static List parseArray(String s, Class clazz) { + if (StringUtils.isBlank(s) || "null".equalsIgnoreCase(s)) { + return Lists.newArrayList(); + } + return JSON.parseArray(s, clazz); + } + + public static String toJsonStringObject(Object o) { + if (o == null) { + return JSON.toJSONString(Maps.newHashMap()); + } + return JSON.toJSONString(o); + } + + public static String toJsonStringArray(Object o) { + if (o == null) { + return JSON.toJSONString(Lists.newArrayList()); + } + return JSON.toJSONString(o); + } +} diff --git a/src/main/java/common/util/validate/FluentValidator.java b/src/main/java/common/util/validate/FluentValidator.java new file mode 100644 index 00000000..5b07599e --- /dev/null +++ b/src/main/java/common/util/validate/FluentValidator.java @@ -0,0 +1,136 @@ +package common.util.validate; + +import common.util.validate.context.ValidateContext; +import common.util.validate.context.ValidateContextAttrKey; +import common.util.validate.context.ValidateElement; +import common.util.validate.context.ValidateResult; +import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.ArrayList; +import java.util.List; + +/** + * 链式调用验证器,参考fluent-validator的简单实现 + * https://github.com/neoremind/fluent-validator + */ +@Slf4j +public class FluentValidator { + /** + * 验证器链,惰性求值期间就是不断的改变这个链表,及时求值期间就是遍历链表依次执行验证 + */ + private List ValidateElementList = new ArrayList<>(); + + /** + * 验证器上下文 + */ + private ValidateContext context = new ValidateContext(); + + /** + * 私有构造方法,只能通过checkAll创建对象 + */ + private FluentValidator() { + } + + /** + * 创建FluentValidator对象 + * + * @return + */ + public static FluentValidator checkAll() { + return new FluentValidator(); + } + + /** + * 使用验证器进行验证 + * + * @param validator 验证器 + * @return + */ + public FluentValidator on(Validator validator) { + ValidateElementList.add(new ValidateElement(null, validator)); + return this; + } + + /** + * 使用验证器验证指定对象 + * + * @param t 待验证对象 + * @param validator 验证器 + * @return + */ + public FluentValidator on(T t, Validator validator) { + ValidateElementList.add(new ValidateElement(t, validator)); + return this; + } + + /** + * 使用验证器验证指定对象 + * + * @param t 待验证对象 + * @param validator 验证器 + * @param condition 条件,为true时才会将验证器加入验证器列表中 + * @return + */ + public FluentValidator on(T t, Validator validator, boolean condition) { + if (condition) { + ValidateElementList.add(new ValidateElement(t, validator)); + } + return this; + } + + /** + * 执行各个验证器中的验证逻辑 + * + * @return + */ + public FluentValidator doValidate() { + if (CollectionUtils.isEmpty(ValidateElementList)) { + log.info("Nothing to validate"); + return null; + } + try { + for (ValidateElement element : ValidateElementList) { + Object target = element.getTarget(); + Validator validator = element.getValidator(); + validator.validate(context, target); + } + } catch (Exception e) { + log.error("FluentValidator.doValidate error ", e); + throw e; + } + return this; + } + + /** + * 转换为对外的验证结果,在FluentValidator.on(..).on(..).doValidate()这一连串计算后的“及时求值”收殓出口。 + * + * @return 对外验证结果 + */ + public ValidateResult result() { + return context.result(); + } + + /** + * 将键值对放入上下文 + * + * @param key 键 + * @param value 值 + * @return FluentValidator + */ + public FluentValidator putAttribute2Context(ValidateContextAttrKey key, Object value) { + if (context == null) { + context = new ValidateContext(); + } + context.setAttribute(key, value); + return this; + } + + /** + * 获取验证器上下文 + */ + public ValidateContext getContext() { + return context; + } + +} diff --git a/src/main/java/common/util/validate/Validator.java b/src/main/java/common/util/validate/Validator.java new file mode 100644 index 00000000..40bb83eb --- /dev/null +++ b/src/main/java/common/util/validate/Validator.java @@ -0,0 +1,24 @@ +package common.util.validate; + +import common.util.validate.context.ValidateContext; + +/** + * 验证器接口。 + *

+ * 泛型T表示待验证对象的类型 + * + */ +public interface Validator { + + /** + * 执行验证 + *

+ * 如果发生错误内部需要调用{@link ValidateContext#addErrorMsg(String)}方法,也即context.addErrorMsg(String) + * 来添加错误,该错误会被添加到结果存根{@link ValidateContext#result()} 的错误消息列表中。 + * + * @param context 验证上下文 + * @param t 待验证对象 + */ + void validate(ValidateContext context, T t); + +} diff --git a/src/main/java/common/util/validate/context/ValidateContext.java b/src/main/java/common/util/validate/context/ValidateContext.java new file mode 100644 index 00000000..81d89648 --- /dev/null +++ b/src/main/java/common/util/validate/context/ValidateContext.java @@ -0,0 +1,127 @@ +package common.util.validate.context; + +import org.apache.commons.collections4.MapUtils; + +import java.math.BigDecimal; +import java.util.HashMap; +import java.util.Map; + +/** + * 验证器在执行调用过程中的上下文 + * 1.验证器中的数据传递共享 + * 2.验证结果数据缓存以作后续使用 + * Created by nibnait on 2021/08/22 + */ +public class ValidateContext { + /** + * 验证器均可以共享使用的属性键值对 + */ + private Map attributes; + + /** + * 调用结果对象 + */ + public ValidateResult result = new ValidateResult(); + + /** + * 添加错误信息 + * + * @param msg 错误信息 + */ + public void addErrorMsg(String msg) { + result.addError(msg); + } + + public ValidateResult result() { + return result; + } + + /** + * 设置属性值 + * + * @param key 键 + * @param value 值 + */ + public void setAttribute(ValidateContextAttrKey key, Object value) { + if (attributes == null) { + attributes = new HashMap<>(); + } + attributes.put(key, value); + } + + /** + * 获取对象 + * + * @param key + * @param + * @return + */ + public T get(ValidateContextAttrKey key) { + return (T) getAttribute(key); + } + + /** + * 获取属性 + * + * @param key 键 + * @return 值 + */ + public Object getAttribute(ValidateContextAttrKey key) { + if (MapUtils.isNotEmpty(attributes)) { + return attributes.get(key); + } + return null; + } + + /** + * 获取String值 + * + * @param key + * @return + */ + public String getString(ValidateContextAttrKey key) { + return (String) getAttribute(key); + } + + /** + * 获取Integer值 + * + * @param key + * @return + */ + public Integer getInteger(ValidateContextAttrKey key) { + return (Integer) getAttribute(key); + } + + /** + * 获取Boolean值 + * + * @param key + * @return + */ + public Boolean getBoolean(ValidateContextAttrKey key) { + return (Boolean) getAttribute(key); + } + + + /** + * 获取Long值 + * + * @param key + * @return + */ + public Long getLong(ValidateContextAttrKey key) { + return (Long) getAttribute(key); + } + + /** + * 获取BigDecimal值 + * + * @param key + * @return + */ + public BigDecimal getBigDecimal(ValidateContextAttrKey key) { + return (BigDecimal) getAttribute(key); + } + +} diff --git a/src/main/java/common/util/validate/context/ValidateContextAttrKey.java b/src/main/java/common/util/validate/context/ValidateContextAttrKey.java new file mode 100644 index 00000000..87e4698b --- /dev/null +++ b/src/main/java/common/util/validate/context/ValidateContextAttrKey.java @@ -0,0 +1,22 @@ +package common.util.validate.context; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +import java.util.Map; + +/** + * Created by nibnait on 2021/08/22 + */ +@Getter +@AllArgsConstructor +public enum ValidateContextAttrKey { + + TAG_NAME_MAP("tagMap", Map.class), + + ; + + private String description; + private Class attrClass; + +} diff --git a/src/main/java/common/util/validate/context/ValidateElement.java b/src/main/java/common/util/validate/context/ValidateElement.java new file mode 100644 index 00000000..415d5e89 --- /dev/null +++ b/src/main/java/common/util/validate/context/ValidateElement.java @@ -0,0 +1,24 @@ +package common.util.validate.context; + +import common.util.validate.Validator; +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * 验证器包装类 + * Created by nibnait on 2021/08/22 + */ +@Getter +@AllArgsConstructor +public class ValidateElement { + /** + * 待验证对象 + */ + private Object target; + + /** + * 验证器 + */ + private Validator validator; + +} diff --git a/src/main/java/common/util/validate/context/ValidateResult.java b/src/main/java/common/util/validate/context/ValidateResult.java new file mode 100644 index 00000000..9de8d400 --- /dev/null +++ b/src/main/java/common/util/validate/context/ValidateResult.java @@ -0,0 +1,34 @@ +package common.util.validate.context; + +import lombok.Data; + +import java.util.ArrayList; +import java.util.List; + +/** + * 内部用验证结果 + * + */ +@Data +public class ValidateResult { + + /** + * 是否成功,一旦发生错误,即置为false,默认为{@value} + */ + private boolean isSuccess = true; + + /** + * 验证错误 + */ + private List errorMsg = new ArrayList<>(); + + /** + * 添加错误 + * + * @param error 错误 + */ + public void addError(String error) { + errorMsg.add(error); + } + +} diff --git a/src/main/java/common/util/validate/validator/OperatorValidator.java b/src/main/java/common/util/validate/validator/OperatorValidator.java new file mode 100644 index 00000000..82cbe87c --- /dev/null +++ b/src/main/java/common/util/validate/validator/OperatorValidator.java @@ -0,0 +1,29 @@ +package common.util.validate.validator; + +import common.exception.ClientViewException; +import common.model.Person; +import common.util.StringUtil; +import common.util.validate.Validator; +import common.util.validate.context.ValidateContext; + +/** + * Created by nibnait on 2021/08/22 + */ +public class OperatorValidator implements Validator { + + /** + * 执行验证 + *

+ * 如果发生错误内部需要调用{@link ValidateContext#addErrorMsg(String)}方法,也即context.addErrorMsg(String) + * 来添加错误,该错误会被添加到结果存根{@link ValidateContext#result()} 的错误消息列表中。 + * + * @param context 验证上下文 + * @param person 待验证对象 + */ + @Override + public void validate(ValidateContext context, Person person) { + if (StringUtil.isBlank(person.getName())) { + throw new ClientViewException("用户名 不能为空"); + } + } +} diff --git a/src/main/java/org/tianbin/java/proxy/jdk/HelloService.java b/src/main/java/org/tianbin/java/proxy/jdk/HelloService.java index 502a6b8b..cf18edd7 100644 --- a/src/main/java/org/tianbin/java/proxy/jdk/HelloService.java +++ b/src/main/java/org/tianbin/java/proxy/jdk/HelloService.java @@ -6,4 +6,6 @@ */ public interface HelloService { void sayHello(); + + void speak(String word); } \ No newline at end of file diff --git a/src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java b/src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java index 0c97645e..509f29c0 100644 --- a/src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java +++ b/src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java @@ -10,4 +10,9 @@ public class HelloServiceImpl implements HelloService { public void sayHello() { System.out.println("Hello world!"); } + + @Override + public void speak(String word) { + System.out.println("speak" + word); + } } \ No newline at end of file diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" "b/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" index 26d41f2f..cb3e6890 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" +++ "b/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" @@ -39,7 +39,7 @@ public void testMain() throws NoSuchMethodException, IllegalAccessException, Inv new MyInvocationHandler(new HelloServiceImpl()) ); Jerry.sayHello(); - + Jerry.speak("123"); /*************************源码解析:************************************/ // 1、生成$Proxy0的class文件 diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" "b/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" index 78a4dab0..3c47761c 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" +++ "b/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" @@ -5,7 +5,7 @@ /** * Created by nibnait on 2020/11/23 */ -public class HelloServiceProxy implements HelloService { +public class HelloServiceProxy implements HelloService { private HelloService helloService; public HelloServiceProxy(HelloService helloService) { @@ -16,4 +16,9 @@ public HelloServiceProxy(HelloService helloService) { public void sayHello() { helloService.sayHello(); } + + @Override + public void speak(String word) { + helloService.speak(word); + } } diff --git a/src/main/test/common/util/validate/FluentValidatorTest.java b/src/main/test/common/util/validate/FluentValidatorTest.java new file mode 100644 index 00000000..683f2d2f --- /dev/null +++ b/src/main/test/common/util/validate/FluentValidatorTest.java @@ -0,0 +1,7 @@ +package common.util.validate; + +/** + * Created by nibnait on 2021/08/22 + */ +public class FluentValidatorTest { +} From 234165b4c76d3110cdb7c9d4a35f9e7c0d3a63c0 Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 1 Sep 2021 06:16:43 +0800 Subject: [PATCH 05/36] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB=E4=BC=98?= =?UTF-8?q?=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 15 ++ .../context/ApplicationContextHelper.java | 84 ++++++ src/main/java/common/exception/ErrorCode.java | 20 ++ .../exception/GlobalExceptionHandler.java | 129 +++++++++ .../exception/GlobalExceptionResponse.java | 41 +++ .../common/exception/ServiceException.java | 45 ++++ src/main/java/common/util/DateTimeUtil.java | 246 +++++++----------- .../java/common/util/LocalDateTimeUtil.java | 1 + .../common/util/validate/FluentValidator.java | 21 +- .../validate/context/ValidateElement.java | 5 +- 10 files changed, 449 insertions(+), 158 deletions(-) create mode 100644 src/main/java/common/context/ApplicationContextHelper.java create mode 100644 src/main/java/common/exception/ErrorCode.java create mode 100644 src/main/java/common/exception/GlobalExceptionHandler.java create mode 100644 src/main/java/common/exception/GlobalExceptionResponse.java create mode 100644 src/main/java/common/exception/ServiceException.java diff --git a/pom.xml b/pom.xml index 8d854c0b..3b3a3040 100644 --- a/pom.xml +++ b/pom.xml @@ -49,6 +49,21 @@ spring-beans 4.3.8.RELEASE + + org.springframework + spring-context + 4.3.8.RELEASE + + + org.springframework + spring-web + 4.3.8.RELEASE + + + org.apache.tomcat.embed + tomcat-embed-core + 8.5.14 + diff --git a/src/main/java/common/context/ApplicationContextHelper.java b/src/main/java/common/context/ApplicationContextHelper.java new file mode 100644 index 00000000..6c857f00 --- /dev/null +++ b/src/main/java/common/context/ApplicationContextHelper.java @@ -0,0 +1,84 @@ +package common.context; + +import common.exception.ServiceException; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.BeansException; +import org.springframework.beans.factory.config.BeanDefinition; +import org.springframework.beans.factory.support.BeanDefinitionBuilder; +import org.springframework.beans.factory.support.BeanDefinitionRegistry; +import org.springframework.context.ApplicationContext; +import org.springframework.context.ApplicationContextAware; +import org.springframework.context.ConfigurableApplicationContext; + +import java.beans.Introspector; +import java.util.Map; + +/** + * Created by nibnait on 2021/09/01 + */ +@Slf4j +public class ApplicationContextHelper implements ApplicationContextAware { + + private static ApplicationContext applicationContext; + + private static BeanDefinitionRegistry beanDefinitionRegistry; + + /** + * 动态注册bean + */ + public synchronized static void registerBean(String beanName, Class clazz) { + if (null == beanName || null == clazz) { + throw new RuntimeException(beanName + "注册失败"); + } + + BeanDefinition beanDefinition = getBeanDefinitionBuilder(clazz).getBeanDefinition(); + if (!beanDefinitionRegistry.containsBeanDefinition(beanName)) { + beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition); + } + } + + + private static BeanDefinitionBuilder getBeanDefinitionBuilder(Class clazz) { + return BeanDefinitionBuilder.genericBeanDefinition(clazz); + } + + @Override + public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { + ApplicationContextHelper.applicationContext = applicationContext; + ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; + beanDefinitionRegistry = (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory(); + } + + public static T getBean(Class targetClz) { + T beanInstance = null; + //byType + try { + beanInstance = applicationContext.getBean(targetClz); + } catch (Exception e) { + log.error("ApplicationContextHelper getBean error ", e); + } + //byName + if (beanInstance == null) { + String simpleName = Introspector.decapitalize(targetClz.getSimpleName()); + try { + Object bean = applicationContext.getBean(simpleName); + if (bean == null) { + throw new ServiceException("获取bean失败 {}", targetClz); + } + beanInstance = targetClz.cast(bean); + } catch (Exception e) { + log.error("ApplicationContextHelper getBean beanInstance error", e); + } + } + return beanInstance; + } + + public static T getBean(String beanName, Class targetClz) { + return applicationContext.getBean(beanName, targetClz); + } + + public static Map getBeansOfType(Class clazz) { + return applicationContext.getBeansOfType(clazz); + } + +} diff --git a/src/main/java/common/exception/ErrorCode.java b/src/main/java/common/exception/ErrorCode.java new file mode 100644 index 00000000..fc03aed7 --- /dev/null +++ b/src/main/java/common/exception/ErrorCode.java @@ -0,0 +1,20 @@ +package common.exception; + +import lombok.AllArgsConstructor; +import lombok.Getter; + +/** + * Created by nibnait on 2021/09/01 + */ +@Getter +@AllArgsConstructor +public enum ErrorCode { + SUCCESS(0L, "success"), + SERVICE_ERROR(83000004L, "service error"), + + ; + + private Long code; + private String message; + +} diff --git a/src/main/java/common/exception/GlobalExceptionHandler.java b/src/main/java/common/exception/GlobalExceptionHandler.java new file mode 100644 index 00000000..111a3fe6 --- /dev/null +++ b/src/main/java/common/exception/GlobalExceptionHandler.java @@ -0,0 +1,129 @@ +package common.exception; + +import lombok.extern.slf4j.Slf4j; +import org.springframework.validation.BindingResult; +import org.springframework.validation.FieldError; +import org.springframework.validation.ObjectError; +import org.springframework.web.bind.MethodArgumentNotValidException; +import org.springframework.web.bind.MissingServletRequestParameterException; +import org.springframework.web.bind.annotation.ControllerAdvice; +import org.springframework.web.bind.annotation.ExceptionHandler; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; + +import javax.servlet.http.HttpServletRequest; + +@ControllerAdvice +@Slf4j +public class GlobalExceptionHandler { + + @ExceptionHandler(MethodArgumentTypeMismatchException.class) + @ResponseBody + public GlobalExceptionResponse methodArgumentTypeMismatchExceptionHandler(HttpServletRequest req, MethodArgumentTypeMismatchException e) { + + String p = e.getParameter().getParameterName(); + String message = "param error: " + p; + Long code = ErrorCode.SERVICE_ERROR.getCode(); + GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); + log.error("MethodArgumentTypeMismatchException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); + return globalExceptionResponse; + } + + + @ExceptionHandler(MissingServletRequestParameterException.class) + @ResponseBody + public GlobalExceptionResponse missingServletRequestParameterExceptionHandler(HttpServletRequest req, MissingServletRequestParameterException e) { + + String p = e.getParameterName(); + String message = "param missing error: " + p; + + Long code = ErrorCode.SERVICE_ERROR.getCode(); + GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); + log.error("MethodArgumentTypeMismatchException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); + return globalExceptionResponse; + } + + + @ExceptionHandler(MethodArgumentNotValidException.class) + @ResponseBody + public GlobalExceptionResponse methodArgumentNotValidExceptionHandler(HttpServletRequest req, MethodArgumentNotValidException e) { + String p = e.getParameter().getParameterName(); + BindingResult bindingResult = e.getBindingResult(); + String fieldErrorMessage = ""; + if (bindingResult.hasErrors()) { + StringBuilder sb = new StringBuilder(); + for (ObjectError objectError : bindingResult.getAllErrors()) { + sb.append(((FieldError) objectError).getField() + ":").append(objectError.getDefaultMessage()).append("; "); + } + fieldErrorMessage = sb.toString(); + } + String message = "param error: " + p + ", " + fieldErrorMessage; + Long code = ErrorCode.SERVICE_ERROR.getCode(); + GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); + log.error("MethodArgumentNotValidException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); + return globalExceptionResponse; + } + + @ExceptionHandler(common.exception.ServiceException.class) + @ResponseBody + public GlobalExceptionResponse exceptionHandler(HttpServletRequest req, common.exception.ServiceException e) { + String message = e.getMessage(); + if (null == message || message.equals("")) { + message = "server runtime error"; + } + + Long code = e.getCode(); + if (null == code) { + code = ErrorCode.SERVICE_ERROR.getCode(); + } + + GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); + log.error("ServiceException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); + return globalExceptionResponse; + } + + @ExceptionHandler(ClientViewException.class) + @ResponseBody + public GlobalExceptionResponse viewExceptionHandler(HttpServletRequest req, ClientViewException e) { + String message = e.getMessage(); + if (null == message || message.equals("")) { + message = "server runtime error"; + } + + Long code = e.getCode(); + if (null == code) { + code = ErrorCode.SERVICE_ERROR.getCode(); + } + GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); + log.info("ClientViewException: from:{} uri:{} code:{} message:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); + return globalExceptionResponse; + } + + @ExceptionHandler(IllegalArgumentException.class) + @ResponseBody + public GlobalExceptionResponse illegalArgumentExceptionHandler(HttpServletRequest req, IllegalArgumentException e) { + String message = e.getMessage(); + if (null == message || message.equals("")) { + message = "IllegalArgumentException"; + } + + GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(ErrorCode.SERVICE_ERROR.getCode(), message); + log.info("IllegalArgumentException: from:{} uri:{} message:{}", req.getRemoteHost(), req.getRequestURI(), message, e); + return globalExceptionResponse; + } + + @ExceptionHandler(RuntimeException.class) + @ResponseBody + public GlobalExceptionResponse runtimeExceptionHandler(HttpServletRequest req, RuntimeException e) { + log.error("RuntimeException: from:{} uri:{} error:{}", req.getRemoteHost(), req.getRequestURI(), e); + return new GlobalExceptionResponse(ErrorCode.SERVICE_ERROR.getCode(), ErrorCode.SERVICE_ERROR.getMessage()); + } + + @ExceptionHandler(Exception.class) + @ResponseBody + public GlobalExceptionResponse defaultExceptionHandler(HttpServletRequest req, Exception e) { + log.error("Exception: from:{} uri:{} error:{}", req.getRemoteHost(), req.getRequestURI(), e); + return new GlobalExceptionResponse(ErrorCode.SERVICE_ERROR.getCode(), ErrorCode.SERVICE_ERROR.getMessage()); + } + +} diff --git a/src/main/java/common/exception/GlobalExceptionResponse.java b/src/main/java/common/exception/GlobalExceptionResponse.java new file mode 100644 index 00000000..505be89e --- /dev/null +++ b/src/main/java/common/exception/GlobalExceptionResponse.java @@ -0,0 +1,41 @@ +package common.exception; + +import java.io.Serializable; + +/** + * Created by nibnait on 2021/09/01 + */ +public class GlobalExceptionResponse implements Serializable { + + private static final long serialVersionUID = 1L; + + public Long code; + public String message; + public Integer errtag = 0; + + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } + + public GlobalExceptionResponse(Long code, String message) { + this.code = code; + this.message = message; + } + + public GlobalExceptionResponse(ErrorCode errorCode) { + this.code = errorCode.getCode(); + this.message = errorCode.getMessage(); + } +} diff --git a/src/main/java/common/exception/ServiceException.java b/src/main/java/common/exception/ServiceException.java new file mode 100644 index 00000000..00b6fa63 --- /dev/null +++ b/src/main/java/common/exception/ServiceException.java @@ -0,0 +1,45 @@ +package common.exception; + +import common.util.DataUtils; +import lombok.extern.slf4j.Slf4j; + +@Slf4j +public class ServiceException extends RuntimeException { + + private Long code; + + private String message; + + public Long getCode() { + return code; + } + + public void setCode(Long code) { + this.code = code; + } + + public String getMsg() { + return message; + } + + public void setMsg(String message) { + this.message = message; + } + + public ServiceException() { super(); } + + public ServiceException(String message){ + super(message); + } + + public ServiceException(Long code, String message){ + super(message); + this.code = code; + this.message = message; + } + + public ServiceException(String message, Object... args) { + super(DataUtils.format(message, args)); + } + +} diff --git a/src/main/java/common/util/DateTimeUtil.java b/src/main/java/common/util/DateTimeUtil.java index e007da4d..3d46b7bb 100644 --- a/src/main/java/common/util/DateTimeUtil.java +++ b/src/main/java/common/util/DateTimeUtil.java @@ -2,11 +2,11 @@ import com.alibaba.fastjson.JSON; import com.google.common.collect.Lists; +import common.exception.ClientViewException; +import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; import org.apache.commons.lang3.math.NumberUtils; -import java.text.DateFormat; import java.text.ParseException; import java.text.SimpleDateFormat; import java.time.*; @@ -14,54 +14,94 @@ import java.util.Date; import java.util.List; +@Slf4j public class DateTimeUtil { + public static final String TIME_MILLISECOND_FORMAT = "HH:mm:ss SSS"; - private static ZoneId zone = ZoneId.systemDefault(); - public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; public static final String DATE_FORMAT = "yyyy-MM-dd"; - public static final String TIME_FORMAT = "HH:mm:ss"; - public static final String TIME_MILLISECOND_FORMAT = "HH:mm:ss SSS"; + public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; - public static LocalDate string2Date(String dateString) { - if (dateString == null) { - return null; + private static ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); + private static ZoneOffset BEIJING_ZONE_OFFSET = ZoneOffset.of("+8"); + private static int MILLI_TIMESTAMP_LENGTH = 13; + private static int SECOND_TIMESTAMP_LENGTH = 10; + + public static Long toMilliTimeStamp(long timeStamp) { + int length = String.valueOf(timeStamp).length(); + if (MILLI_TIMESTAMP_LENGTH == length) { + return timeStamp; + } + if (SECOND_TIMESTAMP_LENGTH == length) { + return timeStamp * 1000; + } + throw new ClientViewException("非10位/13位时间戳"); + } + + public static Long toSecondTimeStamp(long timeStamp) { + int length = String.valueOf(timeStamp).length(); + if (MILLI_TIMESTAMP_LENGTH == length) { + return timeStamp / 1000; + } + if (SECOND_TIMESTAMP_LENGTH == length) { + return timeStamp; + } + throw new ClientViewException("非10位/13位时间戳"); + } + + /************************** String <==> timestamp ******************************/ + public static String timeStamp2String(long timeStamp, String format) { + return new SimpleDateFormat(format).format(timeStamp); + } + + public static Long string2MilliSecond(String time) { + try { + return new SimpleDateFormat(DATE_TIME_FORMAT).parse(time).getTime(); + } catch (ParseException e) { + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.转时间戳失败", time, DATE_TIME_FORMAT); } - DateTimeFormatter formatter = DateTimeFormatter.ofPattern(DATE_FORMAT); - return LocalDate.parse(dateString, formatter); } - public static LocalDate dateStringDateToLocalDate(String date) { - if (StringUtils.isNotBlank(date)) { - return LocalDate.parse(date, DateTimeFormatter.ofPattern(DATE_FORMAT)); - } else { - return LocalDate.now(); + public static Long string2MilliSecond(String time, String format) { + try { + return new SimpleDateFormat(format).parse(time).getTime(); + } catch (ParseException e) { + throw new ClientViewException("timeStr:{}, format:{} 转时间戳失败", time, format); } } - private static DateFormat dateFormat = new SimpleDateFormat(DATE_FORMAT); - private static DateFormat dateTimeFormat = new SimpleDateFormat(DATE_TIME_FORMAT); - private static DateTimeFormatter dateFormatter = DateTimeFormatter.ofPattern(DATE_FORMAT); - private static DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(DATE_TIME_FORMAT); + /************************** LocalDateTime <==> timestamp ******************************/ + public static Long localDateTime2Second(LocalDateTime localDateTime) { + return localDateTime.toEpochSecond(BEIJING_ZONE_OFFSET); + } - private static ZoneId defaultZoneId = ZoneId.systemDefault(); + public static Long localDateTime2MillSecond(LocalDateTime localDateTime) { + return localDateTime.toInstant(BEIJING_ZONE_OFFSET).toEpochMilli(); + } - /** - * String ==> Date - */ - public static Date stringToDate(String dateString) throws ParseException { - return dateFormat.parse(dateString); + public static LocalDate timeStamp2LocalDate(long timeStamp) { + return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDate(); + } + + public static LocalDateTime timeStamp2LocalDateTime(long timeStamp) { + return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDateTime(); } - public static Date stringToDate(String dateString, String dateFormat) throws ParseException { + /************************** String <==> Date ********************************************/ + public static Date string2Date(String dateString) { + try { + return new SimpleDateFormat(DATE_FORMAT).parse(dateString); + } catch (Exception e) { + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2Date error", dateString, DATE_FORMAT); + } + } + + public static Date string2Date(String dateString, String dateFormat) throws ParseException { SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); return simpleDateFormat.parse(dateString); } - /** - * Date ==> String - */ public static String date2String(Date date) { - return dateFormat.format(date); + return new SimpleDateFormat(DATE_FORMAT).format(date); } public static String date2String(Date date, String dateFormat) { @@ -69,54 +109,51 @@ public static String date2String(Date date, String dateFormat) { return simpleDateFormat.format(date); } - /** - * String ==> LocalDate - */ - public static LocalDate stringToLocalDate(String dateString) { - return LocalDate.parse(dateString, dateFormatter); + /************************** String <==> LocalDate ********************************************/ + public static LocalDate string2LocalDate(String dateString) { + return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); } - public static LocalDate stringToLocalDate(String dateString, String dateFormat) { + public static LocalDate string2LocalDate(String dateString, String dateFormat) { DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat); return LocalDate.parse(dateString, dateTimeFormatter); } - /** - * LocalDate ==> String - */ - public static String localDateToString(LocalDate localDate) { - return localDate.format(dateFormatter); + public static String localDate2String(LocalDate localDate) { + return localDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); } - /** - * String ==> LocalDateTime - */ - public static LocalDateTime stringToLocalDateTime(String dateTimeString) { - return LocalDateTime.parse(dateTimeString, dateTimeFormatter); + /************************** String <==> LocalDateTime ********************************************/ + public static LocalDateTime string2LocalDateTime(String dateTimeString) { + return LocalDateTime.parse(dateTimeString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); } - public static LocalDateTime dateStringToLocalDateTime(String dateString) { - LocalDate localDate = LocalDate.parse(dateString, dateFormatter); + public static LocalDateTime dateString2LocalDateTime(String dateString) { + LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); return localDate.atStartOfDay(); } - /** - * LocalDateTime ==> String - */ - public static String localDateTimeToString(LocalDateTime localDateTime) { - return localDateTime.format(dateTimeFormatter); + public static LocalDateTime dateTimeString2LocalDateTime(String dateString) { + return LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); } - public static String localDateTimeToString(LocalDateTime localDateTime, String dateFormat) { - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat); - return localDateTime.format(dateTimeFormatter); + public static String localDateTime2String(LocalDateTime localDateTime) { + return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); } - /** - * Date - * LocalDate ==> java.util.Date - * LocalDateTime ( Date.from(ZonedDateTime.toInstant) ) - */ + /************************** Date ==> LocalDate ********************************************/ + public static LocalDate dateToLocalDate(Date date) { + ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); + return zonedDateTime.toLocalDate(); + } + + /************************** Date ==> LocalDateTime ****************************************/ + public static LocalDateTime dateToLocalDateTime(Date date) { + ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); + return zonedDateTime.toLocalDateTime(); + } + + /******************* java.sql.Date, LocalDate, LocalDateTime ==> Date ********************/ public static Date toUtilDate(Object date) { if (date == null) { return null; @@ -128,10 +165,10 @@ public static Date toUtilDate(Object date) { return (Date) date; } if (date instanceof LocalDate) { - return Date.from(((LocalDate) date).atStartOfDay(defaultZoneId).toInstant()); + return Date.from(((LocalDate) date).atStartOfDay(DEFAULT_ZONE_ID).toInstant()); } if (date instanceof LocalDateTime) { - return Date.from(((LocalDateTime) date).atZone(defaultZoneId).toInstant()); + return Date.from(((LocalDateTime) date).atZone(DEFAULT_ZONE_ID).toInstant()); } if (date instanceof ZonedDateTime) { return Date.from(((ZonedDateTime) date).toInstant()); @@ -143,87 +180,6 @@ public static Date toUtilDate(Object date) { throw new UnsupportedOperationException("Don't know hot to convert " + date.getClass().getName() + " to java.util.Date"); } - /** - * Date ==> LocalDate - * .toIns - * (ZonedDateTime) - */ - public static LocalDate dateToLocalDate(Date date) { - ZonedDateTime zonedDateTime = date.toInstant().atZone(defaultZoneId); - return zonedDateTime.toLocalDate(); - } - - /** - * Date ==> LocalDateTime - * (ZonedDateTime) - */ - public static LocalDateTime dateToLocalDateTime(Date date) { - ZonedDateTime zonedDateTime = date.toInstant().atZone(defaultZoneId); - return zonedDateTime.toLocalDateTime(); - } - - /** - * 获取当前时间戳 - */ - public static Long getTimeInMillis() { - return System.currentTimeMillis(); - } - - /** - * LocalDateTime ==> 秒timestamp - */ - public static Long LocalDateTimeToSecond() { - return LocalDateTime.now().toEpochSecond(ZoneOffset.of("+8")); - } - - /** - * LocalDateTime ==> 毫秒timestamp - */ - public static Long LocalDateTimeToMillSecond() { - return LocalDateTime.now().toInstant(ZoneOffset.of("+8")).toEpochMilli(); - } - - public static final String LONG_TIME_VALID = "长期有效"; - - /** - * 判断是否在有效期内 - * - * @param expireDate - * @return - */ - public static boolean isValidDate(String expireDate) { - if (StringUtils.isBlank(expireDate)) { - return false; - } - if (LONG_TIME_VALID.equals(expireDate)) { - return true; - } - try { - LocalDate expireLocalDate = DateTimeUtil.string2Date(expireDate); - if (LocalDate.now().compareTo(expireLocalDate) < 0) { - return true; - } - } catch (Exception e) { - return false; - } - return false; - } - - /** - * 比较两个日期相差多少天 - * - * @param startTime - * @param endTime - * @return - */ - public static Long durationDays(LocalDateTime startTime, LocalDateTime endTime) { - return Duration.between(startTime, endTime).toDays(); - } - - public static Long durationMillis(LocalDateTime startTime, LocalDateTime endTime) { - return Duration.between(startTime, endTime).toMillis(); - } - /** * 校验时期合法性 */ diff --git a/src/main/java/common/util/LocalDateTimeUtil.java b/src/main/java/common/util/LocalDateTimeUtil.java index 456a7be5..c3ef0429 100644 --- a/src/main/java/common/util/LocalDateTimeUtil.java +++ b/src/main/java/common/util/LocalDateTimeUtil.java @@ -9,6 +9,7 @@ public class LocalDateTimeUtil { public static void main(String[] args) { LocalDateTime start = LocalDateTime.now().minusMinutes(1); + start = LocalDateTime.now().plusDays(1); LocalDateTime end = LocalDateTime.now(); TimeBetween timeBetween = calcTimeBetween(start, end); System.out.println(timeBetween.toString()); diff --git a/src/main/java/common/util/validate/FluentValidator.java b/src/main/java/common/util/validate/FluentValidator.java index 5b07599e..4fd61e4f 100644 --- a/src/main/java/common/util/validate/FluentValidator.java +++ b/src/main/java/common/util/validate/FluentValidator.java @@ -1,5 +1,6 @@ package common.util.validate; +import common.context.ApplicationContextHelper; import common.util.validate.context.ValidateContext; import common.util.validate.context.ValidateContextAttrKey; import common.util.validate.context.ValidateElement; @@ -19,7 +20,7 @@ public class FluentValidator { /** * 验证器链,惰性求值期间就是不断的改变这个链表,及时求值期间就是遍历链表依次执行验证 */ - private List ValidateElementList = new ArrayList<>(); + private List validateElementList = new ArrayList<>(); /** * 验证器上下文 @@ -47,8 +48,8 @@ public static FluentValidator checkAll() { * @param validator 验证器 * @return */ - public FluentValidator on(Validator validator) { - ValidateElementList.add(new ValidateElement(null, validator)); + public FluentValidator on(Class validator) { + validateElementList.add(new ValidateElement(null, validator)); return this; } @@ -59,8 +60,8 @@ public FluentValidator on(Validator validator) { * @param validator 验证器 * @return */ - public FluentValidator on(T t, Validator validator) { - ValidateElementList.add(new ValidateElement(t, validator)); + public FluentValidator on(T t, Class validator) { + validateElementList.add(new ValidateElement(t, validator)); return this; } @@ -72,9 +73,9 @@ public FluentValidator on(T t, Validator validator) { * @param condition 条件,为true时才会将验证器加入验证器列表中 * @return */ - public FluentValidator on(T t, Validator validator, boolean condition) { + public FluentValidator on(T t, Class validator, boolean condition) { if (condition) { - ValidateElementList.add(new ValidateElement(t, validator)); + validateElementList.add(new ValidateElement(t, validator)); } return this; } @@ -85,14 +86,14 @@ public FluentValidator on(T t, Validator validator, boolean condition) { * @return */ public FluentValidator doValidate() { - if (CollectionUtils.isEmpty(ValidateElementList)) { + if (CollectionUtils.isEmpty(validateElementList)) { log.info("Nothing to validate"); return null; } try { - for (ValidateElement element : ValidateElementList) { + for (ValidateElement element : validateElementList) { Object target = element.getTarget(); - Validator validator = element.getValidator(); + Validator validator = (Validator) ApplicationContextHelper.getBean(element.getValidator()); validator.validate(context, target); } } catch (Exception e) { diff --git a/src/main/java/common/util/validate/context/ValidateElement.java b/src/main/java/common/util/validate/context/ValidateElement.java index 415d5e89..71a0209b 100644 --- a/src/main/java/common/util/validate/context/ValidateElement.java +++ b/src/main/java/common/util/validate/context/ValidateElement.java @@ -1,6 +1,5 @@ package common.util.validate.context; -import common.util.validate.Validator; import lombok.AllArgsConstructor; import lombok.Getter; @@ -10,7 +9,7 @@ */ @Getter @AllArgsConstructor -public class ValidateElement { +public class ValidateElement { /** * 待验证对象 */ @@ -19,6 +18,6 @@ public class ValidateElement { /** * 验证器 */ - private Validator validator; + private Class validator; } From 28857a630606482899946fc60d3b45fc743f8f3f Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 1 Nov 2021 17:57:37 +0800 Subject: [PATCH 06/36] =?UTF-8?q?=E5=B7=A5=E5=85=B7=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 16 +- ...350\275\254\351\223\276\350\241\2502.java" | 6 +- ...\345\205\245\346\216\222\345\272\217.java" | 6 +- ...\345\272\217\351\223\276\350\241\250.java" | 6 +- ...\350\275\254\351\223\276\350\241\250.java" | 4 +- ...\345\201\266\351\223\276\350\241\250.java" | 12 +- src/main/java/common/bo/BaseResponse.java | 52 ++++ .../{exception => enums}/ErrorCode.java | 2 +- .../exception/GlobalExceptionHandler.java | 1 + .../exception/GlobalExceptionResponse.java | 2 + src/main/java/common/util/CommonBeanUtil.java | 29 +- src/main/java/common/util/DataUtils.java | 78 ++++++ .../java/common/util/DateTimeCalcUtils.java | 40 +++ .../common/util/DateTimeConvertUtils.java | 190 +++++++++++++ src/main/java/common/util/ExampleUtils.java | 23 ++ .../java/common/util/List2MapFactory.java | 89 ++++++ src/main/java/common/util/NumberUtils.java | 254 ++++++++++++++++++ src/main/java/common/util/PageUtils.java | 55 ++++ src/main/java/common/util/RetryUtils.java | 76 ++++++ .../java/common/util/compare/CompareUtil.java | 61 ----- .../common/util/compare/CompareUtils.java | 143 ++++++++++ .../java/common/util/compare/JsonUtils.java | 2 +- .../IntegerTest.java" | 26 +- ...\350\203\275\346\265\213\350\257\225.java" | 12 +- .../\351\233\206\345\220\210/ListTest.java" | 56 +++- .../RateLimiter/RedisRateLimiterTest.java | 8 +- 26 files changed, 1145 insertions(+), 104 deletions(-) create mode 100644 src/main/java/common/bo/BaseResponse.java rename src/main/java/common/{exception => enums}/ErrorCode.java (91%) create mode 100644 src/main/java/common/util/DateTimeCalcUtils.java create mode 100644 src/main/java/common/util/DateTimeConvertUtils.java create mode 100644 src/main/java/common/util/ExampleUtils.java create mode 100644 src/main/java/common/util/List2MapFactory.java create mode 100644 src/main/java/common/util/NumberUtils.java create mode 100644 src/main/java/common/util/PageUtils.java create mode 100644 src/main/java/common/util/RetryUtils.java delete mode 100644 src/main/java/common/util/compare/CompareUtil.java create mode 100644 src/main/java/common/util/compare/CompareUtils.java diff --git a/pom.xml b/pom.xml index 3b3a3040..f17921f8 100644 --- a/pom.xml +++ b/pom.xml @@ -62,7 +62,7 @@ org.apache.tomcat.embed tomcat-embed-core - 8.5.14 + 8.5.63 @@ -148,6 +148,7 @@ compile + com.json.comparison comparison-core @@ -164,6 +165,19 @@ 2.11.2 + + + com.github.pagehelper + pagehelper + 5.0.1 + + + + javax.servlet + servlet-api + 2.5 + + diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index 9b508125..ed37c8c0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.datastruct.ListNode; -import common.util.compare.CompareUtil; +import common.util.compare.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; @@ -33,14 +33,14 @@ public void testCase() { ListNode excepted = ConstructListNode.construct(new int[]{1, 4, 3, 2, 5}); ListNode actual = reverseBetween(head, m, n); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{3, 5}); m = 1; n = 2; excepted = ConstructListNode.construct(new int[]{5, 3}); actual = reverseBetween(head, m, n); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); } diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index 5ffe8174..8faf560f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.compare.CompareUtil; +import common.util.compare.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; @@ -46,13 +46,13 @@ public void testCase() { ListNode excepted = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); ListNode actual = insertionSortList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{-1,5,3,4,0}); excepted = ConstructListNode.construct(new int[]{-1,0,3,4,5}); actual = insertionSortList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); } /** diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 3ade1f19..58b13c5d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.compare.CompareUtil; +import common.util.compare.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; @@ -40,13 +40,13 @@ public void testCase() { ListNode excepted = ConstructListNode.construct(new int[]{1, 2, 3, 4}); ListNode actual = sortList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{-1,5,3,4,0}); excepted = ConstructListNode.construct(new int[]{-1,0,3,4,5}); actual = sortList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); } diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index c7b3a761..836c9c99 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.ListNode; -import common.util.compare.CompareUtil; +import common.util.compare.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; @@ -32,7 +32,7 @@ public void testCase() { ListNode excepted = ConstructListNode.construct(new int[]{5, 4, 3, 2, 1}); ListNode actual = reverseList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); } diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index a69f20ca..960014dd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code300; import common.datastruct.ListNode; -import common.util.compare.CompareUtil; +import common.util.compare.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; @@ -39,31 +39,31 @@ public void testCase() { ListNode excepted = ConstructListNode.construct(new int[]{1, 3, 5, 2, 4}); ListNode actual = oddEvenList(head); // SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{2, 1, 3, 5, 6, 4, 7}); excepted = ConstructListNode.construct(new int[]{2, 3, 6, 7, 1, 5, 4}); actual = oddEvenList(head); // SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{2, 1, 3, 5, 6, 4, 7}); excepted = ConstructListNode.construct(new int[]{1, 3, 5, 7, 2, 6, 4}); actual = oddEvenValList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); excepted = ConstructListNode.construct(new int[]{1, 3, 5, 2, 4}); actual = oddEvenValList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); head = ConstructListNode.construct(new int[]{2, 1}); excepted = ConstructListNode.construct(new int[]{1, 2}); actual = oddEvenValList(head); SysOut.printList(actual); - Assert.assertTrue(CompareUtil.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); } diff --git a/src/main/java/common/bo/BaseResponse.java b/src/main/java/common/bo/BaseResponse.java new file mode 100644 index 00000000..d485d4e3 --- /dev/null +++ b/src/main/java/common/bo/BaseResponse.java @@ -0,0 +1,52 @@ +package common.bo; + +import common.enums.ErrorCode; + +import java.io.Serializable; + +public class BaseResponse implements Serializable { + + private static final long serialVersionUID = 1L; + + public Long code; + + public String message; + + public T data; + + public Integer errtag = 0; + + public BaseResponse() { + } + + public BaseResponse(Long code, String message, T data) { + super(); + this.code = code; + this.message = message; + this.data = data; + } + + public BaseResponse(Long code, Integer errtag, String message, T data) { + super(); + this.code = code; + this.errtag = errtag; + this.message = message; + this.data = data; + } + + public BaseResponse(T data) { + super(); + this.code = ErrorCode.SUCCESS.getCode(); + this.message = ErrorCode.SUCCESS.getMessage(); + this.data = data; + } + + public BaseResponse(ErrorCode e, T data) { + super(); + this.code = e.getCode(); + this.message = e.getMessage(); + this.data = data; + } + +} + diff --git a/src/main/java/common/exception/ErrorCode.java b/src/main/java/common/enums/ErrorCode.java similarity index 91% rename from src/main/java/common/exception/ErrorCode.java rename to src/main/java/common/enums/ErrorCode.java index fc03aed7..5e5fe9b6 100644 --- a/src/main/java/common/exception/ErrorCode.java +++ b/src/main/java/common/enums/ErrorCode.java @@ -1,4 +1,4 @@ -package common.exception; +package common.enums; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/common/exception/GlobalExceptionHandler.java b/src/main/java/common/exception/GlobalExceptionHandler.java index 111a3fe6..d0e61ae5 100644 --- a/src/main/java/common/exception/GlobalExceptionHandler.java +++ b/src/main/java/common/exception/GlobalExceptionHandler.java @@ -1,5 +1,6 @@ package common.exception; +import common.enums.ErrorCode; import lombok.extern.slf4j.Slf4j; import org.springframework.validation.BindingResult; import org.springframework.validation.FieldError; diff --git a/src/main/java/common/exception/GlobalExceptionResponse.java b/src/main/java/common/exception/GlobalExceptionResponse.java index 505be89e..177fe6fb 100644 --- a/src/main/java/common/exception/GlobalExceptionResponse.java +++ b/src/main/java/common/exception/GlobalExceptionResponse.java @@ -1,5 +1,7 @@ package common.exception; +import common.enums.ErrorCode; + import java.io.Serializable; /** diff --git a/src/main/java/common/util/CommonBeanUtil.java b/src/main/java/common/util/CommonBeanUtil.java index 8881ddc1..4938a94e 100644 --- a/src/main/java/common/util/CommonBeanUtil.java +++ b/src/main/java/common/util/CommonBeanUtil.java @@ -1,7 +1,9 @@ package common.util; import com.esotericsoftware.reflectasm.MethodAccess; +import com.google.common.collect.Lists; import net.sf.cglib.beans.BeanCopier; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.beans.BeanUtils; @@ -126,7 +128,7 @@ public static T copyProperties_methodInvoke_V2(S source, Supplier targ return target; } - public static List copyListProperties(List sources, Supplier targetSupplier) { + public static List copyListProperties_methodInvoke(List sources, Supplier targetSupplier) { List list = new ArrayList<>(sources.size()); for (S source : sources) { T target = copyProperties_methodInvoke(source, targetSupplier); @@ -135,4 +137,29 @@ public static List copyListProperties(List sources, Supplier tar return list; } + /**************** 最佳实践 **************/ + + public static T copyProperties(S source, Supplier targetSupplier) { + if (source == null) { + return null; + } + T target = targetSupplier.get(); + + BeanUtils.copyProperties(source, target); + + return target; + } + + public static List copyListProperties(List sources, Supplier targetSupplier) { + if (CollectionUtils.isEmpty(sources)) { + return Lists.newArrayList(); + } + List list = new ArrayList<>(sources.size()); + for (S source : sources) { + T target = copyProperties(source, targetSupplier); + list.add(target); + } + return list; + } + } \ No newline at end of file diff --git a/src/main/java/common/util/DataUtils.java b/src/main/java/common/util/DataUtils.java index 55e9cbd5..9acc3731 100644 --- a/src/main/java/common/util/DataUtils.java +++ b/src/main/java/common/util/DataUtils.java @@ -5,11 +5,17 @@ import com.google.common.collect.Maps; import com.google.common.collect.Sets; import lombok.extern.slf4j.Slf4j; +import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.helpers.MessageFormatter; import java.util.Collection; import java.util.List; +import java.util.Map; +import java.util.Objects; +import java.util.concurrent.CopyOnWriteArrayList; +import java.util.function.Function; +import java.util.stream.Collectors; /** * Created by nibnait on 2021/08/18 @@ -17,6 +23,21 @@ @Slf4j public class DataUtils { + /** + * 分批调rpc接口 查询数据 + * @param list 入参 eg: skuIdList + * @param size 一批的数量 eg: 100 + * @param function 一个lambda表达式 eg: skuIdList -> itemsSkuService.batchQuery(skuIdList) + * @return 将每一次的返回值,用 flatMap 打平 返回一个 list + */ + public static List getDataPartition(List list, Integer size, Function, List> function) { + return Lists.partition(list, size).stream() + .map(function) + .flatMap(Collection::stream) + .filter(Objects::nonNull) + .collect(Collectors.toList()); + } + /** * 返回 list1 - (list1 ∩ list2) */ @@ -80,4 +101,61 @@ public static String toJsonStringArray(Object o) { } return JSON.toJSONString(o); } + + /** + * 将 element 加到 list 中 + */ + public static List addToList(T element, List list) { + list = CollectionUtils.isEmpty(list) ? Lists.newArrayList() : list; + if (element != null) { + list.add(element); + return list.stream().distinct().collect(Collectors.toList()); + } + return CollectionUtils.isEmpty(list) ? null : list; + } + + /** + * 将 element 加到 list 中 + */ + public static List addToList(List element, List list) { + list = CollectionUtils.isEmpty(list) ? Lists.newArrayList() : list; + if (CollectionUtils.isNotEmpty(element)) { + list.addAll(element); + return list.stream().distinct().collect(Collectors.toList()); + } + return CollectionUtils.isEmpty(list) ? null : list; + } + + /** + * 将 element 从 list 中删除 + */ + public static List removeElement(T element, List list) { + if (CollectionUtils.isEmpty(list)) { + return list; + } + + CopyOnWriteArrayList cowList = new CopyOnWriteArrayList<>(list); + cowList.removeIf(t -> t.equals(element)); + return cowList; + } + + /** + * 返回 list中 重复的元素 + */ + public static List getDuplicateElements(List list) { + return list.stream() + .collect(Collectors.toMap(e -> e, e -> 1, Integer::sum)) + .entrySet().stream() + .filter(e -> e.getValue() > 1) + .map(Map.Entry::getKey) + .collect(Collectors.toList()); + } + + /** + * 判断 list 中 是否包含 t + */ + public static boolean contains(List list, T t) { + return CollectionUtils.isNotEmpty(list) && list.contains(t); + } + } diff --git a/src/main/java/common/util/DateTimeCalcUtils.java b/src/main/java/common/util/DateTimeCalcUtils.java new file mode 100644 index 00000000..3ce13946 --- /dev/null +++ b/src/main/java/common/util/DateTimeCalcUtils.java @@ -0,0 +1,40 @@ +package common.util; + +import lombok.Data; + +import java.time.LocalDateTime; +import java.time.temporal.ChronoUnit; + +/** + * Created by nibnait on 2021/09/08 + */ +public class DateTimeCalcUtils { + + /** + * 计算时间差(start - end) + */ + public static TimeBetween calcTimeBetween(LocalDateTime start, LocalDateTime end) { + TimeBetween timeBetween = new TimeBetween(); + timeBetween.setYears(ChronoUnit.YEARS.between(end, start)); + timeBetween.setMounths(ChronoUnit.MONTHS.between(end, start)); + timeBetween.setDays(ChronoUnit.DAYS.between(end, start)); + timeBetween.setHours(ChronoUnit.HOURS.between(end, start)); + timeBetween.setMinutes(ChronoUnit.MINUTES.between(end, start)); + timeBetween.setSeconds(ChronoUnit.SECONDS.between(end, start)); + timeBetween.setMillis(ChronoUnit.MILLIS.between(end, start)); + return timeBetween; + } + + @Data + public static class TimeBetween { + private Long years; + private Long mounths; + private Long days; + private Long hours; + private Long minutes; + private Long seconds; + private Long millis; + } + + +} diff --git a/src/main/java/common/util/DateTimeConvertUtils.java b/src/main/java/common/util/DateTimeConvertUtils.java new file mode 100644 index 00000000..a7c27d99 --- /dev/null +++ b/src/main/java/common/util/DateTimeConvertUtils.java @@ -0,0 +1,190 @@ +package common.util; + +import common.exception.ClientViewException; +import lombok.extern.slf4j.Slf4j; + +import java.text.ParseException; +import java.text.SimpleDateFormat; +import java.time.*; +import java.time.format.DateTimeFormatter; +import java.util.Date; + +@Slf4j +public class DateTimeConvertUtils { + + public static final String DATE_FORMAT = "yyyy-MM-dd"; + public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + private static ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); + private static ZoneOffset BEIJING_ZONE_OFFSET = ZoneOffset.of("+8"); + private static int MILLI_TIMESTAMP_LENGTH = 13; + private static int SECOND_TIMESTAMP_LENGTH = 10; + + public static Long toMilliTimeStamp(long timeStamp) { + if (timeStamp == 0) { + return 0L; + } + int length = String.valueOf(timeStamp).length(); + if (MILLI_TIMESTAMP_LENGTH == length) { + return timeStamp; + } + if (SECOND_TIMESTAMP_LENGTH == length) { + return timeStamp * 1000; + } + throw new ClientViewException("{} 非10位/13位时间戳", timeStamp); + } + + public static Long toSecondTimeStamp(long timeStamp) { + int length = String.valueOf(timeStamp).length(); + if (MILLI_TIMESTAMP_LENGTH == length) { + return timeStamp / 1000; + } + if (SECOND_TIMESTAMP_LENGTH == length) { + return timeStamp; + } + throw new ClientViewException("非10位/13位时间戳"); + } + + /************************** String <==> timestamp ******************************/ + public static String timeStamp2String(long timeStamp, String format) { + return new SimpleDateFormat(format).format(toMilliTimeStamp(timeStamp)); + } + + public static Long string2MilliSecond(String time) { + try { + return new SimpleDateFormat(DATE_TIME_FORMAT).parse(time).getTime(); + } catch (ParseException e) { + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.转时间戳失败", time, DATE_TIME_FORMAT); + } + } + + public static Long string2MilliSecond(String time, String format) { + try { + return new SimpleDateFormat(format).parse(time).getTime(); + } catch (ParseException e) { + throw new ClientViewException("timeStr:{}, format:{} 转时间戳失败", time, format); + } + } + + /************************** LocalDateTime <==> timestamp ******************************/ + public static Long localDateTime2Second(LocalDateTime localDateTime) { + return localDateTime.toEpochSecond(BEIJING_ZONE_OFFSET); + } + + public static Long localDateTime2MillSecond(LocalDateTime localDateTime) { + return localDateTime.toInstant(BEIJING_ZONE_OFFSET).toEpochMilli(); + } + + public static LocalDate timeStamp2LocalDate(long timeStamp) { + return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDate(); + } + + public static LocalDateTime timeStamp2LocalDateTime(long timeStamp) { + return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDateTime(); + } + + /************************** String <==> Date ********************************************/ + public static Date string2Date(String dateString) { + try { + return new SimpleDateFormat(DATE_FORMAT).parse(dateString); + } catch (Exception e) { + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2Date error", dateString, DATE_FORMAT); + } + } + + public static Date string2Date(String dateString, String dateFormat) { + try { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); + return simpleDateFormat.parse(dateString); + } catch (Exception e) { + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2Date error", dateString, dateFormat); + } + } + + public static String date2String(Date date) { + return new SimpleDateFormat(DATE_FORMAT).format(date); + } + + public static String date2String(Date date, String dateFormat) { + SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); + return simpleDateFormat.format(date); + } + + /************************** String <==> LocalDate ********************************************/ + public static LocalDate string2LocalDate(String dateString) { + return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); + } + + public static LocalDate string2LocalDate(String dateString, String dateFormat) { + DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat); + return LocalDate.parse(dateString, dateTimeFormatter); + } + + public static String localDate2String(LocalDate localDate) { + return localDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); + } + + /************************** String <==> LocalDateTime ********************************************/ + public static LocalDateTime string2LocalDateTime(String dateTimeString) { + return LocalDateTime.parse(dateTimeString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); + } + + public static LocalDateTime dateString2LocalDateTime(String dateString) { + LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); + return localDate.atStartOfDay(); + } + + public static LocalDateTime dateTimeString2LocalDateTime(String dateString) { + return LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); + } + + public static String localDateTime2String(LocalDateTime localDateTime) { + return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); + } + + /************************** Date ==> LocalDate ********************************************/ + public static LocalDate dateToLocalDate(Date date) { + ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); + return zonedDateTime.toLocalDate(); + } + + /************************** Date ==> LocalDateTime ****************************************/ + public static LocalDateTime dateToLocalDateTime(Date date) { + ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); + return zonedDateTime.toLocalDateTime(); + } + + /******************* java.sql.Date, LocalDate, LocalDateTime ==> Date ********************/ + public static Date toUtilDate(Object date) { + if (date == null) { + return null; + } + if (date instanceof Integer) { + return new Date(toMilliTimeStamp((Integer) date)); + } + if (date instanceof Long) { + return new Date(toMilliTimeStamp((Long) date)); + } + if (date instanceof java.sql.Date || date instanceof java.sql.Timestamp) { + return new Date(((Date) date).getTime()); + } + if (date instanceof Date) { + return (Date) date; + } + if (date instanceof LocalDate) { + return Date.from(((LocalDate) date).atStartOfDay(DEFAULT_ZONE_ID).toInstant()); + } + if (date instanceof LocalDateTime) { + return Date.from(((LocalDateTime) date).atZone(DEFAULT_ZONE_ID).toInstant()); + } + if (date instanceof ZonedDateTime) { + return Date.from(((ZonedDateTime) date).toInstant()); + } + if (date instanceof Instant) { + return Date.from((Instant) date); + } + + throw new UnsupportedOperationException("Don't know hot to convert " + date.getClass().getName() + " to java.util.Date"); + } + +} diff --git a/src/main/java/common/util/ExampleUtils.java b/src/main/java/common/util/ExampleUtils.java new file mode 100644 index 00000000..a6b7319b --- /dev/null +++ b/src/main/java/common/util/ExampleUtils.java @@ -0,0 +1,23 @@ +package common.util; + +import org.apache.commons.collections4.CollectionUtils; + +import java.util.List; +import java.util.function.UnaryOperator; + +/** + * Created by nibnait on 2021/10/10 + */ +public class ExampleUtils { + + public static void addQueryCriteria(T criteria, Object object, UnaryOperator unaryOperator) { + if (object == null) { + return; + } + if (List.class.isAssignableFrom(object.getClass()) && CollectionUtils.isEmpty((List) object)) { + return; + } + unaryOperator.apply(criteria); + } + +} diff --git a/src/main/java/common/util/List2MapFactory.java b/src/main/java/common/util/List2MapFactory.java new file mode 100644 index 00000000..b3972244 --- /dev/null +++ b/src/main/java/common/util/List2MapFactory.java @@ -0,0 +1,89 @@ +package common.util; + +import com.google.common.collect.Maps; +import common.exception.ClientViewException; +import org.apache.commons.collections4.CollectionUtils; +import org.slf4j.helpers.MessageFormatter; + +import java.util.List; +import java.util.Map; +import java.util.Optional; +import java.util.function.Function; +import java.util.stream.Collectors; + +public class List2MapFactory { + + public static final String DOUBLE_INDEX_FORMAT = "{}_{}"; + public static final String TRIPLE_INDEX_FORMAT = "{}_{}_{}"; + + public class BizMap { + + private Map map; + + public BizMap(Map map) { + this.map = map; + } + + public BizMap() { + this.map = Maps.newHashMap(); + } + + public V get(K key, String format, Object... args) { + V v = map.get(key); + if (v == null) { + throw new ClientViewException(DataUtils.format(format, args)); + } + return v; + } + + public V get(K key) { + return map.get(key); + } + + public Optional getOptional(K key) { + return Optional.ofNullable(map.get(key)); + } + + public Map getMap() { + return map; + } + } + + + public BizMap transferMap(List list, Function function) { + if (CollectionUtils.isEmpty(list)) { + return new BizMap<>(); + } + return new BizMap<>(list.stream().collect(Collectors.toMap(function, Function.identity(), (o1, o2) -> o1))); + } + + public BizMap> transferMapGroupBy(List list, Function function) { + if (CollectionUtils.isEmpty(list)) { + return new BizMap<>(); + } + return new BizMap<>(list.stream().collect(Collectors.groupingBy(function))); + } + + public BizMap transferDoubleIndexMap(List list, Function fun1, Function fun2) { + if (CollectionUtils.isEmpty(list)) { + return new BizMap<>(); + } + return new BizMap<>(list.stream().collect(Collectors.toMap(o -> doubleIndexFormat(fun1.apply(o), fun2.apply(o)), Function.identity(), (o1, o2) -> o1))); + } + + public String doubleIndexFormat(Object... args) { + return MessageFormatter.arrayFormat(DOUBLE_INDEX_FORMAT, args).getMessage(); + } + + public BizMap transferTripleIndexMap(List list, Function fun1, Function fun2, Function fun3) { + if (CollectionUtils.isEmpty(list)) { + return new BizMap<>(); + } + return new BizMap<>(list.stream().collect(Collectors.toMap(o -> tripleIndexFormat(fun1.apply(o), fun2.apply(o), fun3.apply(o)), Function.identity(), (o1, o2) -> o1))); + } + + public String tripleIndexFormat(Object... args) { + return MessageFormatter.arrayFormat(TRIPLE_INDEX_FORMAT, args).getMessage(); + } + +} diff --git a/src/main/java/common/util/NumberUtils.java b/src/main/java/common/util/NumberUtils.java new file mode 100644 index 00000000..baf1deed --- /dev/null +++ b/src/main/java/common/util/NumberUtils.java @@ -0,0 +1,254 @@ +package common.util; + +import java.math.BigDecimal; +import java.math.RoundingMode; + +public class NumberUtils { + + private static final BigDecimal BIGDECIMAL_ONE_HUNDRED = BigDecimal.valueOf(100); + // 除法,scale 保留2位小数 + private static final int SCALE = 2; + // 除法,一律向下取整(舍弃scale后面的数字) + private static final RoundingMode ROUNDING_MODE = RoundingMode.DOWN; + + /** + * 非空 && >=0 + */ + public static boolean notNullAndGreaterThanOrEqualsZero(Integer o) { + if (o == null) { + return false; + } + return greaterThanOrEqualsZero(o); + } + + public static boolean notNullAndGreaterThanOrEqualsZero(Long o) { + if (o == null) { + return false; + } + return greaterThanOrEqualsZero(o); + } + + public static boolean notNullAndGreaterThanOrEqualsZero(BigDecimal o) { + if (o == null) { + return false; + } + return greaterThanOrEqualsZero(o); + } + + /** + * 非空 && >0 + */ + public static boolean notNullAndGreaterThanZero(Integer o) { + return !nullOrLessThanOrEqualsZero(o); + } + + public static boolean notNullAndGreaterThanZero(Long o) { + return !nullOrLessThanOrEqualsZero(o); + } + + public static boolean notNullAndGreaterThanZero(BigDecimal o) { + return !nullOrLessThanOrEqualsZero(o); + } + + /** + * 空 || <= 0 + */ + public static boolean nullOrLessThanOrEqualsZero(Integer o) { + if (o == null) { + return true; + } + return lessThanOrEqualsZero(o); + } + + public static boolean nullOrLessThanOrEqualsZero(Long o) { + if (o == null) { + return true; + } + return lessThanOrEqualsZero(o); + } + + public static boolean nullOrLessThanOrEqualsZero(BigDecimal o) { + if (o == null) { + return true; + } + return lessThanOrEqualsZero(o); + } + + public static boolean nullOrLessThanZero(Integer o) { + if (o == null) { + return true; + } + return lessThanZero(o); + } + + public static boolean nullOrLessThanZero(Long o) { + if (o == null) { + return true; + } + return lessThanZero(o); + } + + public static boolean nullOrLessThanZero(BigDecimal o) { + if (o == null) { + return true; + } + return lessThanZero(o); + } + + /******** 基础方法:<= 0 ******/ + + public static boolean lessThanOrEqualsZero(Integer o) { + return lessThanOrEquals(o, 0); + } + + public static boolean lessThanOrEqualsZero(Long o) { + return lessThanOrEquals(o, 0L); + } + + public static boolean lessThanOrEqualsZero(BigDecimal o) { + return lessThanOrEquals(o, BigDecimal.ZERO); + } + + public static > boolean lessThanOrEquals(T o, T num) { + if (num == null || o == null) { + return false; + } + return o.compareTo(num) <= 0; + } + + /******** 基础方法:< 0 ******/ + public static boolean lessThanZero(Integer o) { + return lessThan(o, 0); + } + + public static boolean lessThanZero(Long o) { + return lessThan(o, 0L); + } + + public static boolean lessThanZero(BigDecimal o) { + return lessThan(o, BigDecimal.ZERO); + } + + public static > boolean lessThan(T o, T num) { + if (num == null || o == null) { + return false; + } + return o.compareTo(num) < 0; + } + + /******** 基础方法:>= 0 ******/ + + public static boolean greaterThanOrEqualsZero(Integer o) { + return greaterThanOrEquals(o, 0); + } + + public static boolean greaterThanOrEqualsZero(Long o) { + return greaterThanOrEquals(o, 0L); + } + + public static boolean greaterThanOrEqualsZero(BigDecimal o) { + return greaterThanOrEquals(o, BigDecimal.ZERO); + } + + public static > boolean greaterThanOrEquals(T o, T num) { + if (num == null || o == null) { + return false; + } + return o.compareTo(num) >= 0; + } + + /******** 基础方法:> 0 ******/ + + public static boolean greaterThanZero(Integer o) { + return greaterThan(o, 0); + } + + public static boolean greaterThanZero(Long o) { + return greaterThan(o, 0L); + } + + public static boolean greaterThanZero(BigDecimal o) { + return greaterThan(o, BigDecimal.ZERO); + } + + public static > boolean greaterThan(T o, T num) { + if (num == null || o == null) { + return false; + } + return o.compareTo(num) > 0; + } + + /****************** 价格 单位转换 *******************/ + /** + * 单位分 -> 单位元 + */ + public static BigDecimal getPriceYuan(Integer fen) { + return greaterThanZero(fen) + ? divide100(fen) + : null; + } + + public static BigDecimal getPriceYuan(Long fen) { + return greaterThanZero(fen) + ? divide100(fen) + : null; + } + + public static BigDecimal getPriceYuan(BigDecimal fen) { + return greaterThanZero(fen) + ? divide100(fen) + : null; + } + + /******** 基础方法:÷ 100 ******/ + public static BigDecimal divide100(Integer fen) { + return divide(BigDecimal.valueOf(fen), BIGDECIMAL_ONE_HUNDRED); + } + + public static BigDecimal divide100(Long fen) { + return divide(BigDecimal.valueOf(fen), BIGDECIMAL_ONE_HUNDRED); + } + + public static BigDecimal divide100(BigDecimal fen) { + return divide(fen, BIGDECIMAL_ONE_HUNDRED); + } + + /** + * 除法,默认保留两位小数,向下取整 + * + * @param dividend 被除数 + * @param divisor 除数 + * @return 商 + */ + public static BigDecimal divide(BigDecimal dividend, BigDecimal divisor) { + if (dividend == null || divisor == null) { + return BigDecimal.ZERO; + } + return dividend.divide(divisor, SCALE, ROUNDING_MODE); + } + + public static BigDecimal divide(BigDecimal dividend, BigDecimal divisor, int scale, RoundingMode roundingMode) { + if (dividend == null || divisor == null) { + return BigDecimal.ZERO; + } + return dividend.divide(divisor, scale, roundingMode); + } + + /** + * 单位分 -> 单位元 + */ + public static BigDecimal getPriceFen(BigDecimal yuan) { + if (yuan == null) { + return null; + } + return yuan.multiply(BIGDECIMAL_ONE_HUNDRED); + } + + public static BigDecimal getPriceFen(Double yuan) { + if (yuan == null) { + return null; + } + return BigDecimal.valueOf(yuan).multiply(BIGDECIMAL_ONE_HUNDRED); + } + +} diff --git a/src/main/java/common/util/PageUtils.java b/src/main/java/common/util/PageUtils.java new file mode 100644 index 00000000..44eed3bd --- /dev/null +++ b/src/main/java/common/util/PageUtils.java @@ -0,0 +1,55 @@ +package common.util; + +import com.github.pagehelper.PageInfo; +import com.google.common.collect.Lists; +import org.springframework.util.CollectionUtils; + +import java.util.List; +import java.util.function.Function; +import java.util.function.IntFunction; +import java.util.stream.Collectors; + +public class PageUtils { + + public static PageInfo convertPageInfo(PageInfo sourcePage, List list) { + if (sourcePage == null) { + return new PageInfo<>(); + } + + PageInfo newPageInfo = CommonBeanUtil.copyProperties(sourcePage, PageInfo::new); + if (newPageInfo == null || CollectionUtils.isEmpty(list)) { + newPageInfo.setList(list); + return newPageInfo; + } + newPageInfo.setList(list); + return newPageInfo; + } + + public static PageInfo convertPageInfo(PageInfo sourcePage, Function function) { + if (sourcePage == null) { + return new PageInfo<>(); + } + + PageInfo newPageInfo = CommonBeanUtil.copyProperties(sourcePage, PageInfo::new); + if (newPageInfo == null || sourcePage.getList() == null) { + return newPageInfo; + } + newPageInfo.setList(sourcePage.getList().stream().map(function).collect(Collectors.toList())); + return newPageInfo; + } + + public static List getPageInfoTotalList(IntFunction> intFunction) { + List list = Lists.newArrayList(); + int pageNum = 1; + PageInfo pageInfo; + do { + pageInfo = intFunction.apply(pageNum++); + if (pageInfo == null) { + break; + } + list.addAll(pageInfo.getList()); + } while (pageInfo.isHasNextPage()); + return list; + } + +} diff --git a/src/main/java/common/util/RetryUtils.java b/src/main/java/common/util/RetryUtils.java new file mode 100644 index 00000000..3b926e08 --- /dev/null +++ b/src/main/java/common/util/RetryUtils.java @@ -0,0 +1,76 @@ +package common.util; + +import common.bo.BaseResponse; +import common.enums.ErrorCode; +import lombok.extern.slf4j.Slf4j; + +import java.util.function.Supplier; + +/** + * Created by nibnait on 2021/10/21 + */ +@Slf4j +public class RetryUtils { + + /** + * 无返回值的重试 num 次 + * @param runnable 一个匿名函数:() -> xx.xxx + * @param num 重试次数 + * @param errorMsg 报错信息 + * @param sleepMillis 每次重试间隔的毫秒数 + */ + public static void retryRunnable(Runnable runnable, int num, String errorMsg, Long sleepMillis) { + boolean isFail = true; + int count = 0; + while (isFail && count < num) { + isFail = false; + try { + runnable.run(); + } catch (Exception e) { + isFail = true; + count ++ ; + log.error(DataUtils.format("第 {} 次重试 {}", count, errorMsg), e); + try { + Thread.sleep(sleepMillis); + } catch (InterruptedException ex) { + log.warn(ex.getMessage(), ex); + Thread.currentThread().interrupt(); + } + } + } + } + + /** + * 带返回值的重试 num 次 + * @param supplier 一个匿名函数:() -> xx.xxx + * @param num 重试次数 + * @param errorMsg 报错信息 + * @param sleepMillis 每次重试间隔的毫秒数 + */ + public static BaseResponse retrySupplier(Supplier supplier, int num, String errorMsg, Long sleepMillis) { + boolean isFail = true; + int count = 0; + while (isFail && count < num) { + isFail = false; + try { + BaseResponse baseResponse = supplier.get(); + if (ErrorCode.SUCCESS.getCode().equals(baseResponse.code)) { + return baseResponse; + } + } catch (Exception e) { + isFail = true; + count ++ ; + log.error(DataUtils.format("第 {} 次重试 {}", count, errorMsg), e); + try { + Thread.sleep(sleepMillis); + } catch (InterruptedException ex) { + log.warn(ex.getMessage(), ex); + Thread.currentThread().interrupt(); + } + } + } + + return new BaseResponse(ErrorCode.SERVICE_ERROR, errorMsg); + } + +} diff --git a/src/main/java/common/util/compare/CompareUtil.java b/src/main/java/common/util/compare/CompareUtil.java deleted file mode 100644 index 4bb72a24..00000000 --- a/src/main/java/common/util/compare/CompareUtil.java +++ /dev/null @@ -1,61 +0,0 @@ -package common.util.compare; - -import com.alibaba.fastjson.JSON; -import com.google.common.collect.Sets; -import common.bo.compare.CompareBO; -import common.bo.compare.CompareResultDTO; -import common.datastruct.ListNode; -import lombok.extern.slf4j.Slf4j; - -import java.util.Set; - -/** - * Created by nibnait on 2020/11/20 - */ -@Slf4j -public class CompareUtil { - - public static boolean compareListNode(ListNode left, ListNode right) { - while (left != null && right != null && left.val == right.val) { - left = left.next; - right = right.next; - } - return left == right; - } - - public static boolean match(T actual, T expect) { - return match(actual, expect, Sets.newHashSet()); - } - - public static boolean match(T actual, T expect, Set excludeFields) { - CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); - compareBO.setExcludeFields(excludeFields); - - CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); - if (!compareResultDTO.isMatch()) { - log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); - } - return compareResultDTO.isMatch(); - } - - public static boolean compareObject(Object expectObj, Object actualObj) { - - if ((expectObj == null && actualObj != null) || (expectObj != null && actualObj == null)) { - return false; - } - - if (expectObj == null) { - return true; - } - - if (!expectObj.getClass().equals(actualObj.getClass())) { - return false; - } - - if (expectObj instanceof Number && expectObj instanceof Comparable) { - return ((Comparable) expectObj).compareTo(actualObj) == 0; - } - - return expectObj.equals(actualObj); - } -} diff --git a/src/main/java/common/util/compare/CompareUtils.java b/src/main/java/common/util/compare/CompareUtils.java new file mode 100644 index 00000000..8c290f77 --- /dev/null +++ b/src/main/java/common/util/compare/CompareUtils.java @@ -0,0 +1,143 @@ +package common.util.compare; + +import com.alibaba.fastjson.JSON; +import com.google.common.collect.Sets; +import common.bo.compare.CompareBO; +import common.bo.compare.CompareResultDTO; +import common.datastruct.ListNode; +import lombok.extern.slf4j.Slf4j; + +import java.util.Set; + +/** + * Created by nibnait on 2020/11/20 + */ +@Slf4j +public class CompareUtils { + + /** + * 对比两个链表 + */ + public static boolean compareListNode(ListNode left, ListNode right) { + while (left != null && right != null && left.val == right.val) { + left = left.next; + right = right.next; + } + return left == right; + } + + /** + * 对比两个对象的所有字段是否一致 + * @param actual 实际值 + * @param expect 期望值 + */ + public static boolean match(T actual, T expect) { + return matchExcudeFields(actual, expect, Sets.newHashSet()); + } + + /** + * 对比两个对象的所有字段是否一致,排除某些字段 + * @param actual 实际值 + * @param expect 期望值 + * @param excludeFields 排除的字段 list + */ + public static boolean matchExcudeFields(T actual, T expect, Set excludeFields) { + CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); + compareBO.setExcludeFields(excludeFields); + + CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); + if (!compareResultDTO.isMatch()) { + log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); + } + return compareResultDTO.isMatch(); + } + + /** + * 仅对比两个对象中 focusFields list 字段是否一致 + * @param actual 实际值 + * @param expect 期望值 + * @param focusFields 想要对比的字段 list + */ + public static boolean matchFocusFields(T actual, T expect, Set focusFields) { + CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); + compareBO.setFocusFields(focusFields); + + CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); + if (!compareResultDTO.isMatch()) { + log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); + } + return compareResultDTO.isMatch(); + } + + /** + * 对比两个 PageInfo对象 的所有字段是否一致 + * @param actual 实际值 + * @param expect 期望值 + */ + public static boolean matchPage(T actual, T expect) { + return matchPageExculdeFields(actual, expect, Sets.newHashSet()); + } + + /** + * 对比两个 PageInfo对象 的所有字段是否一致,排除某些字段 + * @param actual 实际值 + * @param expect 期望值 + * @param excludeFields 排除的字段 list + */ + public static boolean matchPageExculdeFields(T actual, T expect, Set excludeFields) { + CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); + compareBO.setOptimizations(Sets.newHashSet(CompareBO.OptimizationType.PAGE_HELPER)); + compareBO.setExcludeFields(excludeFields); + + CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); + if (!compareResultDTO.isMatch()) { + log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); + } + return compareResultDTO.isMatch(); + } + + /** + * 仅对比两个 PageInfo对象 中 focusFields list 字段是否一致 + * @param actual 实际值 + * @param expect 期望值 + * @param focusFields 想要对比的字段 list + */ + public static boolean matchPageFocusFields(T actual, T expect, Set focusFields) { + CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); + compareBO.setOptimizations(Sets.newHashSet(CompareBO.OptimizationType.PAGE_HELPER)); + compareBO.setFocusFields(focusFields); + + CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); + if (!compareResultDTO.isMatch()) { + log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); + } + return compareResultDTO.isMatch(); + } + + /** + * 直接调用两个 object 的 .equals 方法,对比 + * @param actualObj 实际值 + * @param expectObj 期望值 + */ + public static boolean matchObject(Object actualObj, Object expectObj) { + + if ((expectObj == null && actualObj != null) || (expectObj != null && actualObj == null)) { + return false; + } + + if (expectObj == null) { + return true; + } + + if (!expectObj.getClass().equals(actualObj.getClass())) { + return false; + } + + if (expectObj instanceof Number && expectObj instanceof Comparable) { + return ((Comparable) expectObj).compareTo(actualObj) == 0; + } + + return expectObj.equals(actualObj); + } + +} diff --git a/src/main/java/common/util/compare/JsonUtils.java b/src/main/java/common/util/compare/JsonUtils.java index a877abc8..6c7c1db8 100644 --- a/src/main/java/common/util/compare/JsonUtils.java +++ b/src/main/java/common/util/compare/JsonUtils.java @@ -35,7 +35,7 @@ public static CompareResultDTO diffJsonObject(JSONObject actualObject, JSONObjec for (String key : focusFields) { String actual = actualObject.getString(key); String expect = expectObject.getString(key); - if (!CompareUtil.compareObject(expect, actual)) { + if (!CompareUtils.matchObject(actual, expect)) { addModifyFields(key, actual, expect, modifiedFields); } } diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" index 309433da..6489633c 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" @@ -31,9 +31,29 @@ public void test02() { } @Test - public void test01() { - String s = "xxx"; - int i = Integer.parseInt(s); + public void testParseInt() { + try { + String s = "xxx"; + int i = Integer.parseInt(s); + System.out.println(i); + } catch (Exception e) { + e.printStackTrace(); + } + + try { + String s = "1234567890123"; + int i = Integer.parseInt(s); + System.out.println(i); + } catch (Exception e) { + e.printStackTrace(); + } + + } + + @Test + public void valueOf() { + Long l = 1234567890123L; + Integer i = Integer.valueOf(l.toString()); System.out.println(i); } diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" index 05d24757..0bde56c5 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" @@ -3,7 +3,7 @@ import common.model.Person; import common.model.PersonDTO; import common.util.CommonBeanUtil; -import common.util.DateTimeUtil; +import common.util.DateTimeCalcUtils; import org.junit.Test; import java.time.LocalDateTime; @@ -47,7 +47,7 @@ public void test_BeanCopier() { } LocalDateTime endTime = LocalDateTime.now(); - System.out.println("copyProperties_BeanCopier " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + System.out.println("copyProperties_BeanCopier " + DateTimeCalcUtils.calcTimeBetween(startTime, endTime).getMillis() + "ms"); } @@ -65,7 +65,7 @@ public void test_BeanUtils() { } LocalDateTime endTime = LocalDateTime.now(); - System.out.println("copyProperties_BeanUtils " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + System.out.println("copyProperties_BeanUtils " + DateTimeCalcUtils.calcTimeBetween(startTime, endTime).getMillis() + "ms"); } @@ -83,7 +83,7 @@ public void test_fieldGetSet() { } LocalDateTime endTime = LocalDateTime.now(); - System.out.println("copyProperties_fieldGetSet " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + System.out.println("copyProperties_fieldGetSet " + DateTimeCalcUtils.calcTimeBetween(startTime, endTime).getMillis() + "ms"); } @@ -101,7 +101,7 @@ public void test_methodInvoke() { } LocalDateTime endTime = LocalDateTime.now(); - System.out.println("copyProperties_methodInvoke " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + System.out.println("copyProperties_methodInvoke " + DateTimeCalcUtils.calcTimeBetween(startTime, endTime).getMillis() + "ms"); } @@ -119,7 +119,7 @@ public void test_methodInvoke_V2() { } LocalDateTime endTime = LocalDateTime.now(); - System.out.println("copyProperties_methodInvoke_V2 " + DateTimeUtil.durationMillis(startTime, endTime) + "ms"); + System.out.println("copyProperties_methodInvoke_V2 " + DateTimeCalcUtils.calcTimeBetween(startTime, endTime).getMillis() + "ms"); } } diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 46e91527..cb11e2b5 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -1,21 +1,59 @@ package org.tianbin.java.集合; +import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.common.base.Functions; import com.google.common.collect.Lists; +import common.model.Person; +import common.util.DataUtils; +import common.util.compare.CompareUtils; +import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; import java.util.Collections; +import java.util.Comparator; import java.util.List; import java.util.stream.Collectors; -/* - -Created by nibnait on 2020-01-09 - */ public class ListTest { + @Test + public void sorted() { + List people = new ArrayList<>(); + Person p1 = new Person(); + p1.setAge(1); + people.add(p1); + + Person p2 = new Person(); + p2.setAge(2); + people.add(p2); + + Person p3 = new Person(); + p3.setAge(3); + people.add(p3); + + people = people.stream().sorted(Comparator.comparing(Person::getAge).reversed()).collect(Collectors.toList()); + System.out.println(JSON.toJSONString(people)); + + System.out.println("==========="); + System.out.println(JSON.toJSONString(people)); + people.sort((o1, o2) -> { + return o1.getAge() - o2.getAge(); + }); + System.out.println(JSON.toJSONString(people)); + } + + @Test + public void difference() { + List all = Lists.newArrayList(1, 2, 3, 3); + List sub = all.stream().distinct().collect(Collectors.toList()); + + List difference = DataUtils.difference(all, sub); + List expect = Lists.newArrayList(3); + Assert.assertTrue(CompareUtils.match(difference, expect)); + } + @Test public void testContains() { Integer i = null; @@ -25,7 +63,7 @@ public void testContains() { @Test public void test03() { - List strList = Lists.newArrayList("1","2"); + List strList = Lists.newArrayList("1", "2"); System.out.println(strList.stream().collect(Collectors.joining(","))); } @@ -39,7 +77,7 @@ public void test02() { @Test public void copyListProperties() { - List list = Lists.newArrayList(2,1,3); + List list = Lists.newArrayList(2, 1, 3); System.out.println(list); Collections.sort(list); System.out.println(list); @@ -47,13 +85,13 @@ public void copyListProperties() { @Test public void testSubList() { - List list = Lists.newArrayList(1,2,3); - System.out.println(list.subList(0,0)); + List list = Lists.newArrayList(1, 2, 3); + System.out.println(list.subList(0, 0)); } @Test public void sort() { - List list = Lists.newArrayList(2,3,1); + List list = Lists.newArrayList(2, 3, 1); Collections.sort(list); System.out.println(list); } diff --git a/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java b/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java index acf97840..9ada109d 100644 --- a/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java +++ b/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java @@ -41,7 +41,7 @@ public void acquire() throws Exception { pool.execute(() -> { double acquire = limiter.acquire(1); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTimeToString(LocalDateTime.now(), DateTimeUtil.TIME_MILLISECOND_FORMAT)); + + DateTimeUtil.localDateTime2String(LocalDateTime.now())); }); } @@ -56,7 +56,7 @@ public void tryAcquire() throws Exception { pool.execute(() -> { boolean acquire = limiter.tryAcquire(); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTimeToString(LocalDateTime.now(), DateTimeUtil.TIME_MILLISECOND_FORMAT)); + + DateTimeUtil.localDateTime2String(LocalDateTime.now())); }); } @@ -71,7 +71,7 @@ public void tryAcquireTimeout() throws Exception { pool.execute(() -> { boolean acquire = limiter.tryAcquire(1000L, TimeUnit.MILLISECONDS); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTimeToString(LocalDateTime.now(), DateTimeUtil.TIME_MILLISECOND_FORMAT)); + + DateTimeUtil.localDateTime2String(LocalDateTime.now())); }); } @@ -93,7 +93,7 @@ public void batchAcquireLazy() throws Exception { pool.execute(() -> { double acquire = redisRateLimiter.acquireLazy(10); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTimeToString(LocalDateTime.now(), DateTimeUtil.TIME_MILLISECOND_FORMAT)); + + DateTimeUtil.localDateTime2String(LocalDateTime.now())); }); } From 8f5a1da1000a8e5707a4462416068215ef2c8603 Mon Sep 17 00:00:00 2001 From: tianbin Date: Sun, 9 Jan 2022 15:31:55 +0800 Subject: [PATCH 07/36] DownloadUtil --- src/main/java/common/util/DownloadUtil.java | 144 ++++++++++++++++++ .../BigDecimalTest.java" | 6 + .../ByteTest.java" | 16 ++ .../MathTest.java" | 16 ++ .../\351\233\206\345\220\210/ListTest.java" | 11 +- 5 files changed, 192 insertions(+), 1 deletion(-) create mode 100644 src/main/java/common/util/DownloadUtil.java create mode 100644 "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" create mode 100644 "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" diff --git a/src/main/java/common/util/DownloadUtil.java b/src/main/java/common/util/DownloadUtil.java new file mode 100644 index 00000000..afc36333 --- /dev/null +++ b/src/main/java/common/util/DownloadUtil.java @@ -0,0 +1,144 @@ +package common.util; + +import com.google.common.collect.Lists; + +import java.io.*; +import java.net.URL; +import java.net.URLConnection; +import java.net.URLDecoder; +import java.util.List; + +/** + * Created by nibnait on 2022/01/09 + */ +public class DownloadUtil { + public static void main(String[] args) throws InterruptedException { + + downloadA("http://tb.nsfocus.co/1R2A8952.jpg", "/Users/nibnait/Downloads/qiniuyun/1R2A8952.jpg"); + downloadB("http://tb.nsfocus.co/1R2A8961.jpg", "1R2A8961.jpg", "/Users/nibnait/Downloads/qiniuyun"); + + List urlList = Lists.newArrayList("http://tb.nsfocus.co/1R2A8962.jpg"); + + for (String url : urlList) { + String fileName = decode(url.substring(url.lastIndexOf("/"))); + downloadB(url, fileName, "/Users/nibnait/Downloads/qiniuyun"); + + System.out.println(fileName); + Thread.sleep(1000); + } + + } + + public static String decode(String url) { + try { + String prevURL = ""; + String decodeURL = url; + while (!prevURL.equals(decodeURL)) { + prevURL = decodeURL; + decodeURL = URLDecoder.decode(decodeURL, "UTF-8"); + } + return decodeURL; + } catch (UnsupportedEncodingException e) { + return "Issue while decoding" + e.getMessage(); + } + } + + + /** + * 根据链接地址下载文件 + * + * @param downloadUrl 文件链接地址 + * @param path 下载存放文件地址 + 文件名 + */ + private static void downloadA(String downloadUrl, String path) { + URL url = null; + DataInputStream dataInputStream = null; + FileOutputStream fileOutputStream = null; + try { + url = new URL(downloadUrl); + dataInputStream = new DataInputStream(url.openStream()); + fileOutputStream = new FileOutputStream(new File(path)); + ByteArrayOutputStream output = new ByteArrayOutputStream(); + + byte[] buffer = new byte[1024]; + int length; + + while ((length = dataInputStream.read(buffer)) > 0) { + output.write(buffer, 0, length); + } + fileOutputStream.write(output.toByteArray()); + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (dataInputStream != null) { + try { + dataInputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (fileOutputStream != null) { + try { + fileOutputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + + /** + * @param downloadUrl 文件链接地址 + * @param filename 保存文件名 + * @param filePath 保存文件路径 + */ + private static void downloadB(String downloadUrl, String filename, String filePath) { + URL url = null; + InputStream inputStream = null; + OutputStream outputStream = null; + try { + url = new URL(downloadUrl); + // 打开连接 + URLConnection con = url.openConnection(); + // 请求超时:5s + con.setConnectTimeout(5 * 1000); + inputStream = con.getInputStream(); + + byte[] bytes = new byte[1024]; + // 读取到的数据长度 + int length; + File savePath = new File(filePath); + if (!savePath.exists()) { + // 如果不存在当前文件夹,则创建该文件夹 + boolean mkdir = savePath.mkdirs(); + if (!mkdir) { + System.out.println("创建文件夹失败"); + return; + } + } + outputStream = new FileOutputStream(savePath.getPath() + "/" + filename); + // 读取 + while ((length = inputStream.read(bytes)) != -1) { + outputStream.write(bytes, 0, length); + } + } catch (IOException e) { + e.printStackTrace(); + } finally { + if (inputStream != null) { + try { + inputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + if (outputStream != null) { + try { + outputStream.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } + } + } + +} diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" index 055d4f0c..c4702e5a 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" @@ -10,6 +10,12 @@ */ public class BigDecimalTest { + @Test + public void divide() { + BigDecimal divide = new BigDecimal("1").divide(new BigDecimal("3"), RoundingMode.HALF_UP); + System.out.println(divide); + } + @Test public void test04() { int i = 1; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" new file mode 100644 index 00000000..bb4d0212 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" @@ -0,0 +1,16 @@ +package org.tianbin.java.基本数据类型; + +import org.junit.Test; + +/** + * Created by nibnait on 2021/12/09 + */ +public class ByteTest { + + @Test + public void equals() { + Byte b6 = (byte) 6; + Integer i6 = 6; + System.out.println(b6.equals(i6)); + } +} diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" new file mode 100644 index 00000000..b64b7ed3 --- /dev/null +++ "b/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" @@ -0,0 +1,16 @@ +package org.tianbin.java.基本数据类型; + +import org.junit.Test; + +/** + * Created by nibnait on 2022/01/03 + */ +public class MathTest { + + @Test + public void ceil() { + int ceil = (int) Math.ceil(2 * 0.9); + System.out.println(ceil); + } + +} diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index cb11e2b5..138a61ff 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -18,6 +18,13 @@ public class ListTest { + @Test + public void sum() { + List list = Lists.newArrayList(); + int sum = list.stream().mapToInt(Person::getAge).sum(); + System.out.println(sum); + } + @Test public void sorted() { List people = new ArrayList<>(); @@ -59,6 +66,8 @@ public void testContains() { Integer i = null; List list = Lists.newArrayList(1); System.out.println(list.contains(i)); + + System.out.println(list.contains(null)); } @Test @@ -91,7 +100,7 @@ public void testSubList() { @Test public void sort() { - List list = Lists.newArrayList(2, 3, 1); + List list = Lists.newArrayList(2293, 2304, 2313, 2408, 2419, 2421, 2066, 2273, 2278, 2312, 2418, 2274, 2331, 2273); Collections.sort(list); System.out.println(list); } From 5bc0ab23bc6619d1cee4c9b42129a6edee083a4c Mon Sep 17 00:00:00 2001 From: tianbin Date: Sun, 9 Jan 2022 15:48:39 +0800 Subject: [PATCH 08/36] upgrade pom version --- pom.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pom.xml b/pom.xml index f17921f8..0971e36a 100644 --- a/pom.xml +++ b/pom.xml @@ -57,7 +57,7 @@ org.springframework spring-web - 4.3.8.RELEASE + 4.3.29.RELEASE org.apache.tomcat.embed @@ -101,7 +101,7 @@ com.alibaba fastjson - 1.2.47 + 1.2.79 From bf22557223183c0d1e090c726a397cd335802a16 Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 11 Apr 2022 06:24:50 +0800 Subject: [PATCH 09/36] =?UTF-8?q?common.util=20=E4=B8=8D=E5=86=8D=E7=BB=B4?= =?UTF-8?q?=E6=8A=A4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 12 +- ...\346\216\245\351\233\250\346\260\264.java" | 2 - ...\345\275\242\345\217\230\346\215\242.java" | 108 ++++++++++++ src/main/java/common/CommonConstants.java | 46 +++++ src/main/java/common/bo/excel/WorkBookBO.java | 47 ++---- src/main/java/common/model/Person.java | 2 + .../java/common/util/DateConvertUtils.java | 158 ++++++++++++++++++ .../common/util/DateTimeConvertUtils.java | 31 +++- src/main/java/common/util/DateUtils.java | 31 ++++ .../java/common/util/EnhanceFileUtils.java | 25 +++ src/main/java/common/util/ExcelReadUtils.java | 126 ++++++++++++++ src/main/java/common/util/README.md | 4 + src/main/resources/excel/report.xls | 0 src/main/test/common/util/DataUtilsTest.java | 23 +++ .../test/common/util/ExcelReadUtilsTest.java | 59 +++++++ src/main/test/org/tianbin/excel/ExcelGen.java | 2 +- .../test/org/tianbin/excel/ParseJson.java | 32 ++++ src/main/test/org/tianbin/excel/StockDTO.java | 80 +++++++++ .../test/org/tianbin/java/OptionalTest.java | 20 +++ .../\351\233\206\345\220\210/ListTest.java" | 133 ++++++++++++++- 20 files changed, 895 insertions(+), 46 deletions(-) create mode 100644 "src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" create mode 100644 src/main/java/common/CommonConstants.java create mode 100644 src/main/java/common/util/DateConvertUtils.java create mode 100644 src/main/java/common/util/DateUtils.java create mode 100644 src/main/java/common/util/EnhanceFileUtils.java create mode 100644 src/main/java/common/util/ExcelReadUtils.java create mode 100644 src/main/java/common/util/README.md delete mode 100644 src/main/resources/excel/report.xls create mode 100644 src/main/test/common/util/DataUtilsTest.java create mode 100644 src/main/test/common/util/ExcelReadUtilsTest.java create mode 100644 src/main/test/org/tianbin/excel/ParseJson.java create mode 100644 src/main/test/org/tianbin/excel/StockDTO.java create mode 100644 src/main/test/org/tianbin/java/OptionalTest.java diff --git a/pom.xml b/pom.xml index 0971e36a..0a58fa44 100644 --- a/pom.xml +++ b/pom.xml @@ -37,6 +37,16 @@ poi 3.17 + + org.apache.poi + poi-ooxml + 3.17 + + + com.alibaba + easyexcel + 2.2.7 + com.esotericsoftware @@ -47,7 +57,7 @@ org.springframework spring-beans - 4.3.8.RELEASE + 5.3.12 org.springframework diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" index 2d255abd..6b008f49 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" @@ -3,8 +3,6 @@ import junit.framework.TestCase; import org.junit.Test; -import java.util.LinkedList; -import java.util.Queue; import java.util.Stack; /* diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" new file mode 100644 index 00000000..ee09c438 --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" @@ -0,0 +1,108 @@ +package algorithm_practice.LeetCode.code000; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/* +将一个给定字符串 s 根据给定的行数 numRows ,以从上往下、从左到右进行 Z 字形排列。 +比如输入字符串为 "PAYPALISHIRING" 行数为 3 时,排列如下: + +P A H N +A P L S I I G +Y I R +之后,你的输出需要从左往右逐行读取,产生出一个新的字符串,比如:"PAHNAPLSIIGYIR"。 + +请你实现这个将字符串进行指定行数变换的函数: +string convert(string s, int numRows); + + +示例 1: +输入:s = "PAYPALISHIRING", numRows = 3 +输出:"PAHNAPLSIIGYIR" + +示例 2: +输入:s = "PAYPALISHIRING", numRows = 4 +输出:"PINALSIGYAHRPI" +解释: +P I N +A L S I G +Y A H R +P I +示例 3: +输入:s = "A", numRows = 1 +输出:"A" + +提示: +1 <= s.length <= 1000 +s 由英文字母(小写和大写)、',' 和 '.' 组成 +1 <= numRows <= 1000 + + +来源:力扣(LeetCode) +链接:https://leetcode-cn.com/problems/zigzag-conversion +著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 + */ +public class M006_Z字形变换 { + + @Test + public void test() { + String s = "PAYPALISHIRING"; + int numRows = 3; + Assert.assertEquals("PAHNAPLSIIGYIR", convert(s, numRows)); + + s = "PAYPALISHIRING"; + numRows = 4; + Assert.assertEquals("PINALSIGYAHRPI", convert(s, numRows)); + + s = "A"; + numRows = 1; + Assert.assertEquals("A", convert(s, numRows)); + + s = "AB"; + numRows = 1; + Assert.assertEquals("AB", convert(s, numRows)); + + s = "ABCD"; + numRows = 2; + Assert.assertEquals("ACBD", convert(s, numRows)); + + } + + public int ROW_FLAG = 1; + + public String convert(String s, int numRows) { + if (numRows == 1) { + return s; + } + + Map map = new HashMap<>(); + int row = 0; + for (int i = 0; i < s.length(); i++) { + row = getNextRowNum(row, numRows); + String str = map.get(row) == null ? "" : map.get(row); + + str += s.charAt(i); + map.put(row, str); + } + + StringBuilder result = new StringBuilder(); + for (String value : map.values()) { + result.append(value); + } + + return result.toString(); + } + + private int getNextRowNum(int row, int numRows) { + if (row == numRows) { + ROW_FLAG = -1; + } + if (row == 1) { + ROW_FLAG = 1; + } + return row + ROW_FLAG; + } +} diff --git a/src/main/java/common/CommonConstants.java b/src/main/java/common/CommonConstants.java new file mode 100644 index 00000000..722e17da --- /dev/null +++ b/src/main/java/common/CommonConstants.java @@ -0,0 +1,46 @@ +package common; + +/** + * Created by nibnait on 2022/03/10 + */ +public class CommonConstants { + + public static final String FILE_PATH = "/data/file"; + public static final String FILE_ENCODE_UTF8 = "UTF-8"; + + public static final String AUDIT_DEFAULT_VALUE = "NULL"; + public static final String SKU_AUDIT_DEFAULT_VALUE = "NULL"; + public static final String NULL_STRING = "null"; + public static final String EMPTY_STRING = ""; + public static final String EMPTY_STRING_LIST = "[\"\"]"; + public static final Byte BYTE_ZERO = (byte) 0; + public static final Integer INTEGER_ZERO = 0; + public static final Long LONG_ZERO = 0L; + public static final Byte BYTE_ONE = (byte) 1; + public static final Integer INTEGER_ONE = 1; + public static final Long Long_ONE = 1L; + + public static final String UNDERLINE_SEPARATOR = "_"; + public static final String BLANK_SPACE_SEPARATOR = " "; + public static final String DOT_SEPARATOR = "."; + public static final String MINUS_SEPARATOR = "-"; + public static final String MINUS_MINUS_SEPARATOR = "--"; + public static final String COMMA_SEPARATOR = ","; + public static final String DWUKROPEK_SEPARATOR = ":"; + public static final String SEMICOLON_SEPARATOR = ";"; + public static final String EQUAL_SIGN_SEPARATOR = "="; + public static final String SLASH_SEPARATOR = "/"; + public static final String BACK_SLASH_SEPARATOR = "\\"; + + public static final String HDFS_FILE_FIELD_SEPARATOR = "\u0001"; + public static final String NEWLINE_SEPARATOR = "\n"; + + public static final String FULL_SHAPED_SEMICOLON_SEPARATOR = ";"; + + public static final String SUCCESS = "success"; + public static final String FAIL = "fail"; + + public static final String SUFFIX_XLS = ".xls"; + public static final String SUFFIX_CSV = ".csv"; + public static final String SUFFIX_PDF = ".pdf"; +} diff --git a/src/main/java/common/bo/excel/WorkBookBO.java b/src/main/java/common/bo/excel/WorkBookBO.java index 21a99377..6e5f3781 100644 --- a/src/main/java/common/bo/excel/WorkBookBO.java +++ b/src/main/java/common/bo/excel/WorkBookBO.java @@ -1,20 +1,17 @@ package common.bo.excel; +import common.CommonConstants; +import common.util.DateUtils; +import common.util.EnhanceFileUtils; import lombok.Data; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.apache.poi.hssf.usermodel.HSSFSheet; import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.springframework.core.io.Resource; -import org.springframework.core.io.support.PathMatchingResourcePatternResolver; -import org.springframework.core.io.support.ResourcePatternResolver; import java.io.File; -import java.nio.file.Files; -import java.nio.file.Path; -import java.nio.file.Paths; import java.util.ArrayList; import java.util.List; @@ -34,7 +31,7 @@ public WorkBookBO() { sheetList.add(new SheetBO(workbook.createSheet("Sheet1"))); } - public WorkBookBO(int sheetSize, List> sheetTitle, String... sheetName) { + public WorkBookBO(List> sheetTitle, String... sheetName) { workbook = new HSSFWorkbook(); if (CollectionUtils.isEmpty(sheetTitle) || sheetName == null || sheetTitle.size() != sheetName.length) { @@ -43,7 +40,7 @@ public WorkBookBO(int sheetSize, List> sheetTitle, String... sheetN return; } - for (int i = 0; i < sheetSize; i++) { + for (int i = 0; i < sheetTitle.size(); i++) { HSSFSheet sheet = workbook.createSheet(sheetName[i]); SheetBO sheetBO = new SheetBO(sheet); sheetBO.appendRow(sheetTitle.get(i)); @@ -53,35 +50,25 @@ public WorkBookBO(int sheetSize, List> sheetTitle, String... sheetN /** * 将 workbook 写成文件 - * @param sourceFileName resources/excel 目录下的文件名 - * @param targetFileName targetFileName 重命名文件(可以为空) + * @param fileName fileName 重命名文件(可以为空) */ - public File writeToFile(String sourceFileName, String targetFileName) { - - if (StringUtils.isBlank(sourceFileName)) { - return null; + public File writeToFile(String fileName) { + if (StringUtils.isBlank(fileName)) { + fileName = String.valueOf(DateUtils.currentTimeMillis()); } - File sourceFile = null; - String sourceFilePathName = "/excel/" + sourceFileName + ".xls"; +// fileName = CommonConstants.FILE_PATH + CommonConstants.SLASH_SEPARATOR + fileName + CommonConstants.SUFFIX_XLS; + fileName = "/Users/nibnait/data/file" + CommonConstants.SLASH_SEPARATOR + fileName + CommonConstants.SUFFIX_XLS; + File file = new File(fileName); + try { - ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver(); - Resource[] resources = resolver.getResources(sourceFilePathName); - sourceFile = resources[0].getFile(); - workbook.write(sourceFile); + file = EnhanceFileUtils.createIfNecessary(fileName); + workbook.write(file); workbook.close(); - resources = resolver.getResources(sourceFilePathName); - sourceFile = resources[0].getFile(); - - if (StringUtils.isNotBlank(targetFileName) && sourceFile != null) { - String path = sourceFile.getPath(); - Path copy = Files.copy(Paths.get(path), Paths.get(path.replaceAll(sourceFileName, targetFileName))); - return copy.toFile(); - } } catch (Exception e) { - log.error("fail to write excel sourceFile", e); + log.error("WorkBookBO writeToFile error ", e); } - return sourceFile; + return file; } } diff --git a/src/main/java/common/model/Person.java b/src/main/java/common/model/Person.java index f784f512..3dd336fb 100644 --- a/src/main/java/common/model/Person.java +++ b/src/main/java/common/model/Person.java @@ -4,6 +4,7 @@ import lombok.Data; import lombok.NoArgsConstructor; +import java.util.List; import java.util.Objects; /** @@ -21,6 +22,7 @@ public class Person { private String phone; private Boolean isBigBoolean; private boolean isSmallBoolean; + private List children; public Person(String name, Integer age) { this.name = name; diff --git a/src/main/java/common/util/DateConvertUtils.java b/src/main/java/common/util/DateConvertUtils.java new file mode 100644 index 00000000..274b032f --- /dev/null +++ b/src/main/java/common/util/DateConvertUtils.java @@ -0,0 +1,158 @@ +package common.util; + +import lombok.extern.slf4j.Slf4j; + +import java.text.DateFormat; +import java.text.SimpleDateFormat; +import java.util.Calendar; +import java.util.Date; + +/** + * Created by nibnait on 2022/03/21 + */ +@Slf4j +public class DateConvertUtils { + + public static final String TIME_INTERVAL_SECOND = "second"; + public static final String TIME_INTERVAL_MINUTE = "minute"; + public static final String TIME_INTERVAL_HOUR = "hour"; + public static final String TIME_INTERVAL_DAY = "day"; + public static final String TIME_INTERVAL_WEEK = "week"; + public static final String TIME_INTERVAL_MONTH = "month"; + public static final String TIME_INTERVAL_QUARTER = "quarter"; + public static final String TIME_INTERVAL_YEAR = "year"; + public static final String DATE_FORMAT = "yyyy-MM-dd"; + public static final String TIME_FORMAT = "HH:mm:ss"; + public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + + + + public static String format(Date date, String dateFormat) { + if (date == null) + return null; + DateFormat df = new SimpleDateFormat(dateFormat); + return df.format(date); + } + + public static String getDateString(String datePattern) { + return new SimpleDateFormat(datePattern).format(DateUtils.now()); + } + + public static String getYesterdayString(String dateFormat) { + Date yesterday = add(Calendar.DAY_OF_YEAR, DateUtils.now(), -1); + return DateConvertUtils.format(yesterday, dateFormat); + } + + public static Date add(int field, Date date, int value) { + Calendar c = Calendar.getInstance(); + c.setTime(date); + + int fieldNewValue = (c.get(field) + value); + c.set(field, fieldNewValue); + return c.getTime(); + } + + public static long dateDiff(String timeInterval, Date date1, Date date2) { + Calendar calendar = Calendar.getInstance(); + if (timeInterval.equals(TIME_INTERVAL_YEAR)) { + calendar.setTime(date1); + int time = calendar.get(Calendar.YEAR); + calendar.setTime(date2); + return (long)time - calendar.get(Calendar.YEAR); + } + + if (timeInterval.equals(TIME_INTERVAL_QUARTER)) { + calendar.setTime(date1); + int time = calendar.get(Calendar.YEAR) * 4; + calendar.setTime(date2); + time -= calendar.get(Calendar.YEAR) * 4; + calendar.setTime(date1); + time += calendar.get(Calendar.MONTH) / 4; + calendar.setTime(date2); + return (long)time - calendar.get(Calendar.MONTH) / 4; + } + + if (timeInterval.equals(TIME_INTERVAL_MONTH)) { + calendar.setTime(date1); + int time = calendar.get(Calendar.YEAR) * 12; + calendar.setTime(date2); + time -= calendar.get(Calendar.YEAR) * 12; + calendar.setTime(date1); + time += calendar.get(Calendar.MONTH); + calendar.setTime(date2); + return (long)time - calendar.get(Calendar.MONTH); + } + + if (timeInterval.equals(TIME_INTERVAL_WEEK)) { + calendar.setTime(date1); + int time = calendar.get(Calendar.YEAR) * 52; + calendar.setTime(date2); + time -= calendar.get(Calendar.YEAR) * 52; + calendar.setTime(date1); + time += calendar.get(Calendar.WEEK_OF_YEAR); + calendar.setTime(date2); + return (long)time - calendar.get(Calendar.WEEK_OF_YEAR); + } + + if (timeInterval.equals(TIME_INTERVAL_DAY)) { + calendar.setTime(date1); + int time = calendar.get(Calendar.DAY_OF_YEAR) + + calendar.get(Calendar.YEAR) * 365; + calendar.setTime(date2); + return (long)time + - (calendar.get(Calendar.DAY_OF_YEAR) + calendar + .get(Calendar.YEAR) * 365); + } + + if (timeInterval.equals(TIME_INTERVAL_HOUR)) { + long time = date1.getTime() / 1000 / 60 / 60; + return time - date2.getTime() / 1000 / 60 / 60; + } + + if (timeInterval.equals(TIME_INTERVAL_MINUTE)) { + long time = date1.getTime() / 1000 / 60; + return time - date2.getTime() / 1000 / 60; + } + + if (timeInterval.equals(TIME_INTERVAL_SECOND)) { + long time = date1.getTime() / 1000; + return time - date2.getTime() / 1000; + } + + return date1.getTime() - date2.getTime(); + } + + public static long dateDiff(String timeInterval, Long unixTime1, + Long unixTime2) { + return dateDiff(timeInterval, new Date(unixTime1), new Date(unixTime2)); + } + + public static void main(String[] args) { + } + + /** + * 取得当前时间戳(精确到秒) + * @return + */ + public static int getCurrentTime(){ + return DateUtils.currentTime(); + } + + + /** + * 时间戳转换成日期格式字符串 + * @param seconds 精确到秒的字符串 + * @return + */ + public static String timeStampToDate(String seconds,String format) { + if(seconds == null || seconds.isEmpty() || seconds.equals("null")){ + return ""; + } + if(format == null || format.isEmpty()){ + format = DATE_TIME_FORMAT; + } + SimpleDateFormat sdf = new SimpleDateFormat(format); + return sdf.format(new Date(Long.valueOf(seconds+"000"))); + } + +} diff --git a/src/main/java/common/util/DateTimeConvertUtils.java b/src/main/java/common/util/DateTimeConvertUtils.java index a7c27d99..8e8968d8 100644 --- a/src/main/java/common/util/DateTimeConvertUtils.java +++ b/src/main/java/common/util/DateTimeConvertUtils.java @@ -13,7 +13,9 @@ public class DateTimeConvertUtils { public static final String DATE_FORMAT = "yyyy-MM-dd"; + public static final String DATE_FORMAT1 = "yyyyMMdd"; public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; + public static final String DATE_TIME_MILLI_FORMAT = "yyyy-MM-dd HH:mm:ss:SSS"; private static ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); private static ZoneOffset BEIJING_ZONE_OFFSET = ZoneOffset.of("+8"); @@ -34,7 +36,18 @@ public static Long toMilliTimeStamp(long timeStamp) { throw new ClientViewException("{} 非10位/13位时间戳", timeStamp); } + public static Long toSecondTimeStamp(Date date) { + if (date == null) { + return 0L; + } + + return toSecondTimeStamp(date.getTime()); + } + public static Long toSecondTimeStamp(long timeStamp) { + if (timeStamp == 0) { + return 0L; + } int length = String.valueOf(timeStamp).length(); if (MILLI_TIMESTAMP_LENGTH == length) { return timeStamp / 1000; @@ -46,15 +59,27 @@ public static Long toSecondTimeStamp(long timeStamp) { } /************************** String <==> timestamp ******************************/ + public static String timeStamp2String(long timeStamp) { + return new SimpleDateFormat(DATE_TIME_FORMAT).format(toMilliTimeStamp(timeStamp)); + } + public static String timeStamp2String(long timeStamp, String format) { return new SimpleDateFormat(format).format(toMilliTimeStamp(timeStamp)); } + public static String timeStamp2DateString(long timeStamp) { + return new SimpleDateFormat(DATE_FORMAT).format(toMilliTimeStamp(timeStamp)); + } + + public static String timeStamp2DateTimeString(long timeStamp) { + return new SimpleDateFormat(DATE_TIME_FORMAT).format(toMilliTimeStamp(timeStamp)); + } + public static Long string2MilliSecond(String time) { try { return new SimpleDateFormat(DATE_TIME_FORMAT).parse(time).getTime(); } catch (ParseException e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.转时间戳失败", time, DATE_TIME_FORMAT); + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2MilliSecond 转时间戳失败", time, DATE_TIME_FORMAT); } } @@ -62,7 +87,7 @@ public static Long string2MilliSecond(String time, String format) { try { return new SimpleDateFormat(format).parse(time).getTime(); } catch (ParseException e) { - throw new ClientViewException("timeStr:{}, format:{} 转时间戳失败", time, format); + throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2MilliSecond 转时间戳失败", time, format); } } @@ -154,7 +179,7 @@ public static LocalDateTime dateToLocalDateTime(Date date) { return zonedDateTime.toLocalDateTime(); } - /******************* java.sql.Date, LocalDate, LocalDateTime ==> Date ********************/ + /******************* timestamp, java.sql.Date, LocalDate, LocalDateTime ==> Date ********************/ public static Date toUtilDate(Object date) { if (date == null) { return null; diff --git a/src/main/java/common/util/DateUtils.java b/src/main/java/common/util/DateUtils.java new file mode 100644 index 00000000..838ef54a --- /dev/null +++ b/src/main/java/common/util/DateUtils.java @@ -0,0 +1,31 @@ +package common.util; + +import java.time.LocalDateTime; +import java.util.Date; + +/** + * Created by nibnait on 2022/03/10 + */ +public class DateUtils { + + public static Date now() { + return new Date(); + } + + public static int currentTime() { + return (int) (System.currentTimeMillis() / 1000); + } + + public static Long currentTimeMillis() { + return System.currentTimeMillis(); + } + + public static Long nanoTime() { + return System.nanoTime(); + } + + public static LocalDateTime now8() { + return LocalDateTime.now(); + } + +} diff --git a/src/main/java/common/util/EnhanceFileUtils.java b/src/main/java/common/util/EnhanceFileUtils.java new file mode 100644 index 00000000..f6ba577e --- /dev/null +++ b/src/main/java/common/util/EnhanceFileUtils.java @@ -0,0 +1,25 @@ +package common.util; + +import lombok.extern.slf4j.Slf4j; + +import java.io.File; +import java.io.IOException; + +/** + * Created by nibnait on 2022/03/02 + */ +@Slf4j +public class EnhanceFileUtils { + + public static File createIfNecessary(String fileName) throws IOException { + File file = new File(fileName); + if (!file.exists()) { + file.getParentFile().mkdirs(); + if (!file.createNewFile()) { + log.error("FileUtils createIfNecessary failed"); + } + } + return file; + } + +} diff --git a/src/main/java/common/util/ExcelReadUtils.java b/src/main/java/common/util/ExcelReadUtils.java new file mode 100644 index 00000000..a0b97959 --- /dev/null +++ b/src/main/java/common/util/ExcelReadUtils.java @@ -0,0 +1,126 @@ +package common.util; + +import com.alibaba.excel.EasyExcelFactory; +import com.alibaba.excel.context.AnalysisContext; +import com.alibaba.excel.event.AnalysisEventListener; +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.apache.poi.hssf.usermodel.HSSFWorkbook; +import org.apache.poi.poifs.filesystem.POIFSFileSystem; +import org.apache.poi.ss.usermodel.*; +import org.apache.poi.xssf.usermodel.XSSFWorkbook; + +import java.io.IOException; +import java.io.InputStream; +import java.math.BigDecimal; +import java.util.ArrayList; +import java.util.Date; +import java.util.List; + +/** + * Created by nibnait on 2022/03/10 + */ +@Slf4j +public class ExcelReadUtils { + + /** + * 使用 easyexcel 读 + */ + public static List read(InputStream in, Class clazz) { + List list = new ArrayList<>(); + + EasyExcelFactory.read(in, clazz, new AnalysisEventListener() { + @Override + public void invoke(T data, AnalysisContext context) { + list.add(data); + } + + @Override + public void doAfterAllAnalysed(AnalysisContext context) {} + }).sheet().doRead(); + + return list; + } + + /** + * 将文件的 inputStream 转成 workbook + */ + public static Workbook convert2Workbook(InputStream inputStream) { + Workbook workbook = null; + try { + workbook = new XSSFWorkbook(inputStream); // 解析2007版本 + } catch (Exception ex) { + try { + POIFSFileSystem pfs = new POIFSFileSystem(inputStream); // 解析2003版本 + workbook = new HSSFWorkbook(pfs); + } catch (IOException e) { + log.error("ExcelReadUtils convert2Workbook error ", e); + } + } finally { + try { + inputStream.close(); + } catch (IOException e) { + log.error("ExcelReadUtils convert2Workbook inputStream.close error ", e); + } + } + return workbook; + } + + /** + * 读第1行数据 + */ + public static List getTitle(Sheet sheet) { + return getRowData(sheet, 0); + } + + /** + * 读指定行号 + * + * @param sheet excel + * @param rowNo 行号 + */ + public static List getRowData(Sheet sheet, int rowNo) { + List rowData = Lists.newArrayList(); + + Row row = sheet.getRow(rowNo); + if (row == null) { + return rowData; + } + + // 读取列 + for (int cellNum = 0; cellNum < row.getLastCellNum(); cellNum++) { + Cell cell = row.getCell(cellNum); + + if (cell == null) { + rowData.add(""); + continue; + } + + // 匹配列的数据类型 + String cellValue = ""; + CellType cellType = cell.getCellTypeEnum(); + switch (cellType) { + case STRING: + cellValue = cell.getStringCellValue(); + break; + case BOOLEAN: + cellValue = String.valueOf(cell.getBooleanCellValue()); + break; + case NUMERIC: + if (DateUtil.isCellDateFormatted(cell)) { + Date date = cell.getDateCellValue(); + cellValue = DateTimeConvertUtils.date2String(date); + } else { + cellValue = BigDecimal.valueOf(cell.getNumericCellValue()).stripTrailingZeros().toString(); + } + break; + default: + break; + } + rowData.add(cellValue); + } + + return rowData; + } + +} diff --git a/src/main/java/common/util/README.md b/src/main/java/common/util/README.md new file mode 100644 index 00000000..ba935393 --- /dev/null +++ b/src/main/java/common/util/README.md @@ -0,0 +1,4 @@ +common.util 包 这里不再维护。 + +移步 [https://github.com/nibnait/common-enhance](https://github.com/nibnait/common-enhance) + diff --git a/src/main/resources/excel/report.xls b/src/main/resources/excel/report.xls deleted file mode 100644 index e69de29b..00000000 diff --git a/src/main/test/common/util/DataUtilsTest.java b/src/main/test/common/util/DataUtilsTest.java new file mode 100644 index 00000000..bf9ea070 --- /dev/null +++ b/src/main/test/common/util/DataUtilsTest.java @@ -0,0 +1,23 @@ +package common.util; + +import com.google.common.collect.Lists; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.List; + +/** + * Created by nibnait on 2022/03/29 + */ +@Slf4j +public class DataUtilsTest { + + @Test + public void difference() { + List list1 = Lists.newArrayList(1); + List list2 = Lists.newArrayList(0); + + System.out.println(DataUtils.difference(list1, list2)); + } + +} diff --git a/src/main/test/common/util/ExcelReadUtilsTest.java b/src/main/test/common/util/ExcelReadUtilsTest.java new file mode 100644 index 00000000..26317b8b --- /dev/null +++ b/src/main/test/common/util/ExcelReadUtilsTest.java @@ -0,0 +1,59 @@ +package common.util; + +import lombok.Data; +import org.apache.poi.ss.usermodel.Sheet; +import org.apache.poi.ss.usermodel.Workbook; +import org.junit.Test; + +import java.io.FileInputStream; +import java.io.FileNotFoundException; +import java.util.List; + +/** + * Created by nibnait on 2022/03/10 + */ +public class ExcelReadUtilsTest { + + @Data + public static class NFT { + private String sourceAddress; + private String linkId; + private Integer stock; + private String specKey1; + private String specKey2; + private String specKey3; + } + + @Test + public void testReadByModule() throws FileNotFoundException { + // 获取文件流 + String path = "/Users/nibnait/Desktop/"; + FileInputStream inputStream = new FileInputStream(path + "nft.xlsx"); + + List read = ExcelReadUtils.read(inputStream, NFT.class); + System.out.println(DataUtils.toJsonStringArray(read)); + } + + @Test + public void testReadByWorkbook() throws FileNotFoundException { + // 获取文件流 + String path = "/Users/nibnait/Desktop/"; + FileInputStream inputStream = new FileInputStream(path + "nft.xlsx"); + + Workbook workbook = ExcelReadUtils.convert2Workbook(inputStream); + + // 获取标题内容 + Sheet sheet = workbook.getSheetAt(0); + List title = ExcelReadUtils.getTitle(sheet); + System.out.println(title); + + // 获取表中的内容 + int rowCount = sheet.getPhysicalNumberOfRows(); + for (int rowNum = 1; rowNum < rowCount; rowNum++) { + List rowData = ExcelReadUtils.getRowData(sheet, rowNum); + System.out.println(rowData); + } + } + + +} diff --git a/src/main/test/org/tianbin/excel/ExcelGen.java b/src/main/test/org/tianbin/excel/ExcelGen.java index a40e2512..c761d44f 100644 --- a/src/main/test/org/tianbin/excel/ExcelGen.java +++ b/src/main/test/org/tianbin/excel/ExcelGen.java @@ -36,7 +36,7 @@ public void excelGen() { xiegehanshu(sheet); - File delay_delivery_report = workBookBO.writeToFile("report", targetFileName); + File delay_delivery_report = workBookBO.writeToFile(targetFileName); System.out.println(delay_delivery_report.getName()); diff --git a/src/main/test/org/tianbin/excel/ParseJson.java b/src/main/test/org/tianbin/excel/ParseJson.java new file mode 100644 index 00000000..0ca4901f --- /dev/null +++ b/src/main/test/org/tianbin/excel/ParseJson.java @@ -0,0 +1,32 @@ +package org.tianbin.excel; + +import com.google.common.collect.Lists; +import common.bo.excel.SheetBO; +import common.bo.excel.WorkBookBO; +import common.util.DataUtils; +import jxl.write.WriteException; + +import java.io.IOException; +import java.util.List; + +/** + * Created by nibnait on 2022/01/18 + */ +public class ParseJson { + + public static void main(String[] args) throws IOException, WriteException { + String str = "[{\"skuId\":1000098016,\"stock\":239,\"frozenStock\":583,\"outStock\":0,\"isolateStock\":0,\"purchaseStock\":840,\"warehouseIds\":\"\",\"warnStock\":1,\"frozenUndeliveryStock\":0,\"ctime\":1623744663000,\"mtime\":1642147764000,\"boxNum\":0,\"onsaleBoxNum\":0}]"; + List stockDTOS = DataUtils.parseArray(str, StockDTO.class); + + WorkBookBO workBookBO = new WorkBookBO(); + SheetBO sheetBO = workBookBO.getSheetList().get(0); + + for (StockDTO stockDTO : stockDTOS) { + sheetBO.appendRow(Lists.newArrayList(stockDTO.getSkuId()+"", stockDTO.getStock()+"")); + } + + workBookBO.writeToFile("stock"); + + } + +} diff --git a/src/main/test/org/tianbin/excel/StockDTO.java b/src/main/test/org/tianbin/excel/StockDTO.java new file mode 100644 index 00000000..3bce28f0 --- /dev/null +++ b/src/main/test/org/tianbin/excel/StockDTO.java @@ -0,0 +1,80 @@ +package org.tianbin.excel; + +import lombok.Data; + +import java.util.Date; + +/** + * Created by nibnait on 2022/01/18 + */ +@Data +public class StockDTO { + + private static final long serialVersionUID = -503150452346799617L; + + /** + * sku_id + */ + private Long skuId; + + /** + * 可售库存 + */ + private Integer stock; + + /** + * 冻结库存 + */ + private Integer frozenStock; + + /** + * 出库库存 + */ + private Integer outStock; + + /** + * 隔离库存 + */ + private Integer isolateStock; + + /** + * 采购库存 + */ + private Integer purchaseStock; + + /** + * 仓库id + */ + private String warehouseIds; + + /** + * 预警库存 + */ + private Integer warnStock; + + /** + * 待下发冻结 + */ + private Integer frozenUndeliveryStock; + + /** + * 创建时间 + */ + private Date ctime; + + /** + * 修改时间 + */ + private Date mtime; + + /** + * 一番赏箱子数量 + */ + private Integer boxNum; + + + /** + * 一番赏箱子数量 + */ + private Integer onsaleBoxNum; +} diff --git a/src/main/test/org/tianbin/java/OptionalTest.java b/src/main/test/org/tianbin/java/OptionalTest.java new file mode 100644 index 00000000..311cb247 --- /dev/null +++ b/src/main/test/org/tianbin/java/OptionalTest.java @@ -0,0 +1,20 @@ +package org.tianbin.java; + +import org.junit.Test; + +import java.util.Optional; + +/** + * Created by nibnait on 2022/03/17 + */ +public class OptionalTest { + + @Test + public void test01() { + Integer i = null; + System.out.println(Optional.ofNullable(i).orElse(null)); + + i = 1; + System.out.println(Optional.ofNullable(i).orElse(null)); + } +} diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 138a61ff..6d3a8505 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -4,10 +4,9 @@ import com.alibaba.fastjson.JSONObject; import com.google.common.base.Functions; import com.google.common.collect.Lists; +import com.google.common.collect.Sets; import common.model.Person; import common.util.DataUtils; -import common.util.compare.CompareUtils; -import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; @@ -18,6 +17,62 @@ public class ListTest { + @Test + public void addAll() { + List list = new ArrayList<>(); + list.addAll(Lists.newArrayList(1,2,3)); + list.addAll(Lists.newArrayList()); + list.addAll(Lists.newArrayList(1)); + System.out.println(list); + } + + @Test + public void distinct() { + List list = Lists.newArrayList(1000113650, 1000115822, 1000112888, 1000119317, 1000113660, 1000116588, 1000112553, 1000112536, 1000112557, 1000112555, 1000112552, 1000110757, 1000112886, 1000112551, 1000112554, 1000107340, 1000110542, 1000107318, 1000107335, 1000107310, 1000107317, 1000107294, 1000107319, 1000107230, 1000098976, 1000107229, 1000100864); + System.out.println(list.stream().distinct().collect(Collectors.toList())); + } + + @Test + public void remove2() { +// List list = Lists.newArrayList("1", "1", "2", "3", "1"); + List list = Lists.newArrayList("1", "1"); + for (int i = 0; i < list.size(); i++) { + if ("1".equals(list.get(i))) { + list.remove(i); + i = i - 1; + } else { + break; + } + } + + System.out.println(list); + } + + @Test + public void remove1() { + List list = Lists.newArrayList(1, 2, 3); + for (Integer integer : list) { + if (integer.equals(1)) { + list.remove(integer); + } else { + break; + } + } + + System.out.println(list); + } + + @Test + public void listPointer() { + List children = Lists.newArrayList(); + Person person = new Person(); + person.setChildren(children); + System.out.println(person.getChildren()); + + children.add(1); + System.out.println(person.getChildren()); + } + @Test public void sum() { List list = Lists.newArrayList(); @@ -51,14 +106,51 @@ public void sorted() { System.out.println(JSON.toJSONString(people)); } + @Test + public void duplicate() { + List list2 = Lists.newArrayList(1000059552,1000068557,1000052556,1000131519,1000131522,1000131511,1000108485,1000108487,1000108486,1000135252,1000135191,1000135205,1000135254,1000135294,1000135204,1000135251,1000135253,1000131523,1000103250,1000103249,1000107207,1000107237,1000102019,1000103724,1000103237,1000080830,1000121622,1000135781,1000092288,1000118620,1000117198,1000117197,1000117199,1000117202,1000117196,1000117201,1000117200,1000089820,1000095265,1000089823,1000089824,1000089822,1000099788,1000113684,1000108865,1000107903,1000107902,1000107901,1000103155,1000103156,1000105793,1000103170,1000095196,1000101180,1000142626,1000142627,1000142628,1000142622,1000142624,1000123426,1000082839,1000137961,1000098500,1000098502,1000098506,1000098507,1000098501,1000098512,1000098505,1000098504,1000098499,1000098509,1000098508,1000098514,1000098498,1000098533,1000098526,1000098532,1000098503,1000098510,1000096453,1000096450,1000096451,1000096475,1000096449,1000096452,1000096472,1000096448,1000096473,1000096474,1000096471,1000096476,1000114551,1000114552,1000125074,1000114574,1000114550,1000114575,1000114576,1000114549,1000114577,1000125103,1000081713,1000074323,1000081712,1000074893,1000066590,1000065049,1000066586,1000080773,1000096487,1000097000,1000079185,1000082541,1000079236,1000079242,1000065055,1000071376,1000086033,1000083975,1000088539,1000090970,1000108241,1000102089,1000144992,1000144996,1000137988,1000137989,1000137987,1000136264,1000136265,1000134619,1000135895,1000135896,1000144785,1000144786,1000140793,1000020449,1000055809,1000063560,1000073840,1000069340,1000074104,1000069284,1000081510,1000136063,1000136073,1000136068,1000136069,1000136067,1000136074,1000136071,1000108686,1000143503,1000143506,1000143504,1000143507,1000143505,1000143509,1000143508,1000126707,1000137585,1000144843,1000144850,1000143728,1000144848,1000143435,1000143440,1000143726,1000143765,1000141521,1000143776,1000058101,1000144838,1000144829,1000143775,1000143437,1000143451,1000143774,1000144833,1000143773,1000110453,1000115892,1000116547,1000135991,1000135992,1000135986,1000135989,1000135994,1000135990,1000135988,1000135993,1000135995,1000135996,1000135987,1000135997,1000135998,1000144734,1000144735,1000143079,1000077184,1000077173,1000081673,1000103442,1000082640,1000082642,1000082641,1000080636,1000080635,1000080640,1000080641,1000080637,1000080633,1000080642,1000080634,1000080643,1000080644,1000080632,1000080645,1000080639,1000082804,1000124142,1000124210,1000125452,1000125451,1000125819,1000126215,1000125448,1000125817,1000125820,1000125822,1000125821,1000125449,1000125818,1000126216,1000125456,1000125462,1000121975,1000121978,1000121976,1000121990,1000121977,1000121992,1000122033,1000126230,1000122032,1000121991,1000121974,1000130142,1000130141,1000130208,1000130217,1000130209,1000130140,1000130147,1000130120,1000130119,1000130149,1000130121,1000130210,1000137765,1000137767,1000137766,1000104969,1000104968,1000104966,1000104967,1000044389,1000117614,1000141714,1000141748,1000141712,1000117414,1000109711,1000125796,1000125800,1000125797,1000125794,1000125795,1000125798,1000125799,1000125768,1000125769,1000125773,1000125786,1000125767,1000125787,1000125772,1000125771,1000125770,1000125785,1000125784,1000125789,1000125790,1000125788,1000143411,1000143407,1000143410,1000143415,1000143416,1000143405,1000145378,1000073625,1000093298,1000093254,1000100205,1000093252,1000093296,1000100204,1000093253,1000093297,1000093251,1000093295,1000093255,1000093294,1000121128,1000121129,1000121130,1000121145,1000121148,1000121147,1000121132,1000121143,1000121142,1000121131,1000121146,1000121133,1000121144,1000121126,1000121127,1000121141,1000138891,1000136215,1000136214,1000080657,1000046345,1000073221,1000080304,1000080303,1000083084,1000137834,1000050231,1000099816,1000099850,1000099856,1000099853,1000118303,1000099851,1000099814,1000099817,1000099815,1000099859,1000099813,1000099852,1000117372,1000099858,1000099857,1000050229,1000083925,1000088374,1000118409,1000124465,1000135679,1000113224,1000135965,1000117379,1000117382,1000076376,1000097159,1000069772,1000135682,1000020598,1000012142,1000145302,1000135763,1000135761,1000146633,1000146628,1000146632,1000146629,1000146630,1000146631,1000090610,1000145652,1000145651,1000145650,1000145649,1000102854,1000122089,1000122090,1000122091,1000122092,1000117617,1000105993,1000099789,1000109229,1000130918,1000139271,1000139270,1000101700,1000064426,1000135315,1000108684,1000126887,1000131448,1000135849,1000146553,1000039831,1000088833,1000094936,1000131158,1000131167,1000130400,1000131150,1000130401,1000131154,1000135622,1000137613,1000137619,1000134634,1000130405,1000111163,1000111164,1000114457,1000111161,1000114459,1000114460,1000111162,1000114458,1000136072,1000136062,1000112962,1000112963,1000113047,1000113046,1000113049,1000112972,1000112971,1000112970,1000112974,1000113034,1000113031,1000112976,1000116329,1000113027,1000132090,1000139391,1000139401,1000139384,1000118973,1000085962,1000085963,1000100970,1000100825,1000107335,1000107340,1000112551,1000110757,1000112552,1000112555,1000116588,1000113660,1000113650,1000139230,1000139229,1000103628,1000119317,1000135709,1000135706,1000135708,1000136027,1000136028,1000136029,1000136025,1000136026,1000136030,1000135705,1000135707,1000136059,1000136060,1000136061,1000134840,1000134843,1000136058,1000134839,1000136050,1000134841,1000134844,1000134845,1000136047,1000136048,1000136051,1000136049,1000136056,1000136057); + + List duplicateElements = DataUtils.getDuplicateElements(list2); + System.out.println(duplicateElements); + + System.out.println(Sets.newHashSet(list2)); + } + @Test public void difference() { - List all = Lists.newArrayList(1, 2, 3, 3); - List sub = all.stream().distinct().collect(Collectors.toList()); +// List all = Lists.newArrayList(1, 2, 3, 3); +// List sub = all.stream().distinct().collect(Collectors.toList()); +// +// List difference = DataUtils.difference(all, sub); +// System.out.println(difference); +// List expect = Lists.newArrayList(3); +// Assert.assertTrue(CompareUtils.match(difference, expect)); + + + List list1 = Lists.newArrayList(1000082236, 1000134040, 1000134041, 1000073245, 1000134042, 1000134036, 1000135700, 1000134037, 1000134039, 1000135703, 1000135404, 1000135400, 1000135401, 1000135402, 1000135403, 1000135460, 1000135456, 1000070182, 1000135457, 1000135459); + List list2 = Lists.newArrayList(1000134040, 1000134041, 1000073245, 1000134042, 1000134036, 1000135700, 1000134037, 1000134039, 1000135703, 1000082236, 1000135460, 1000135456, 1000070182, 1000135457, 1000135459, 1000135404, 1000135400, 1000135401, 1000135402, 1000135403); + List difference1 = DataUtils.difference(list1, list2); + System.out.println(difference1); + + + List intersection = DataUtils.intersection(list1, list2); + System.out.println(intersection); + + List difference = DataUtils.difference(list2, intersection); +// System.out.println(difference); +// difference1 = DataUtils.difference(list1, list2); +// System.out.println(difference1); + } + + @Test + public void intersection() { + List oldList = Lists.newArrayList(0); + List newList = Lists.newArrayList(1, 3); + List difference1 = DataUtils.intersection(newList, oldList); + System.out.println(difference1); + difference1 = DataUtils.intersection(oldList, newList); + System.out.println(difference1); - List difference = DataUtils.difference(all, sub); - List expect = Lists.newArrayList(3); - Assert.assertTrue(CompareUtils.match(difference, expect)); } @Test @@ -94,8 +186,31 @@ public void copyListProperties() { @Test public void testSubList() { - List list = Lists.newArrayList(1, 2, 3); - System.out.println(list.subList(0, 0)); + List list = Lists.newArrayList(); + for (int i = 1; i < 33; i++) { + list.add(i); + } + + int pageNum = 1; + int pageSize = 10; + int fromIndex = pageNum * pageSize; + int toIndex = fromIndex + pageSize; + System.out.println(list.subList(fromIndex, toIndex)); + + pageNum = 2; + fromIndex = pageNum * pageSize; + toIndex = fromIndex + pageSize; + System.out.println(list.subList(fromIndex, toIndex)); + + pageNum = 3; + fromIndex = pageNum * pageSize; + toIndex = fromIndex + pageSize; + System.out.println(list.subList(fromIndex, toIndex)); + + pageNum = 4; + fromIndex = pageNum * pageSize; + toIndex = fromIndex + pageSize; + System.out.println(list.subList(fromIndex, toIndex)); } @Test From 284a95cef1b45c3c53fbe15ef9b212670ed7905e Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 11 Apr 2022 07:10:16 +0800 Subject: [PATCH 10/36] clean pom, clean common.util --- pom.xml | 194 ++----------- ...\351\225\277\345\255\220\344\270\262.java" | 4 +- ...350\275\254\351\223\276\350\241\2502.java" | 2 +- ...350\257\215\346\213\206\345\210\2062.java" | 4 +- ...\345\205\245\346\216\222\345\272\217.java" | 2 +- ...\345\272\217\351\223\276\350\241\250.java" | 2 +- ...\345\205\254\345\233\240\345\255\220.java" | 1 - ...\350\275\254\351\223\276\350\241\250.java" | 2 +- ...\345\201\266\351\223\276\350\241\250.java" | 2 +- ...\350\257\215\351\241\272\345\272\217.java" | 6 +- ...\345\255\227\347\254\246\344\270\262.java" | 5 +- ...\347\232\204\345\255\227\347\254\246.java" | 4 +- src/main/java/common/CommonConstants.java | 46 ---- src/main/java/common/bo/BaseResponse.java | 52 ---- src/main/java/common/bo/EmailBO.java | 29 -- .../java/common/bo/compare/CompareBO.java | 56 ---- .../common/bo/compare/CompareResultDTO.java | 37 --- src/main/java/common/bo/excel/SheetBO.java | 32 --- src/main/java/common/bo/excel/WorkBookBO.java | 74 ----- .../context/ApplicationContextHelper.java | 2 +- .../common/exception/ClientViewException.java | 43 --- .../exception/GlobalExceptionHandler.java | 130 --------- .../exception/GlobalExceptionResponse.java | 43 --- .../common/exception/ServiceException.java | 45 --- src/main/java/common/util/CompareUtils.java | 21 ++ src/main/java/common/util/DataUtils.java | 161 ----------- .../java/common/util/DateConvertUtils.java | 158 ----------- .../java/common/util/DateTimeCalcUtils.java | 40 --- .../common/util/DateTimeConvertUtils.java | 215 --------------- src/main/java/common/util/DateTimeUtil.java | 258 ------------------ src/main/java/common/util/DateUtils.java | 31 --- src/main/java/common/util/EmailUtils.java | 79 ------ .../java/common/util/EnhanceFileUtils.java | 25 -- src/main/java/common/util/ExampleUtils.java | 23 -- src/main/java/common/util/ExcelReadUtils.java | 126 --------- .../java/common/util/List2MapFactory.java | 89 ------ .../java/common/util/LocalDateTimeUtil.java | 33 --- src/main/java/common/util/NumberUtils.java | 254 ----------------- src/main/java/common/util/PageUtils.java | 55 ---- src/main/java/common/util/RetryUtils.java | 76 ------ src/main/java/common/util/StringUtil.java | 27 -- .../common/util/compare/CompareUtils.java | 143 ---------- .../common/util/compare/JacksonUtils.java | 219 --------------- .../java/common/util/compare/JsonUtils.java | 242 ---------------- .../validate/validator/OperatorValidator.java | 6 +- .../JavaExcelFullGCTest.java" | 48 ---- .../LoadDemo.class" | Bin 456 -> 0 bytes .../redis/RateLimiter/RedisRateLimiter.java | 4 +- src/main/test/common/util/DataUtilsTest.java | 23 -- .../test/common/util/ExcelReadUtilsTest.java | 59 ---- src/main/test/org/tianbin/excel/ExcelGen.java | 20 +- .../test/org/tianbin/excel/ParseJson.java | 12 +- ...\350\203\275\346\265\213\350\257\225.java" | 2 +- .../\351\233\206\345\220\210/ListTest.java" | 2 +- .../\351\233\206\345\220\210/SetTest.java" | 5 +- .../RateLimiter/RedisRateLimiterTest.java | 10 +- 56 files changed, 89 insertions(+), 3194 deletions(-) delete mode 100644 src/main/java/common/CommonConstants.java delete mode 100644 src/main/java/common/bo/BaseResponse.java delete mode 100644 src/main/java/common/bo/EmailBO.java delete mode 100644 src/main/java/common/bo/compare/CompareBO.java delete mode 100644 src/main/java/common/bo/compare/CompareResultDTO.java delete mode 100644 src/main/java/common/bo/excel/SheetBO.java delete mode 100644 src/main/java/common/bo/excel/WorkBookBO.java delete mode 100644 src/main/java/common/exception/ClientViewException.java delete mode 100644 src/main/java/common/exception/GlobalExceptionHandler.java delete mode 100644 src/main/java/common/exception/GlobalExceptionResponse.java delete mode 100644 src/main/java/common/exception/ServiceException.java create mode 100644 src/main/java/common/util/CompareUtils.java delete mode 100644 src/main/java/common/util/DataUtils.java delete mode 100644 src/main/java/common/util/DateConvertUtils.java delete mode 100644 src/main/java/common/util/DateTimeCalcUtils.java delete mode 100644 src/main/java/common/util/DateTimeConvertUtils.java delete mode 100644 src/main/java/common/util/DateTimeUtil.java delete mode 100644 src/main/java/common/util/DateUtils.java delete mode 100644 src/main/java/common/util/EmailUtils.java delete mode 100644 src/main/java/common/util/EnhanceFileUtils.java delete mode 100644 src/main/java/common/util/ExampleUtils.java delete mode 100644 src/main/java/common/util/ExcelReadUtils.java delete mode 100644 src/main/java/common/util/List2MapFactory.java delete mode 100644 src/main/java/common/util/LocalDateTimeUtil.java delete mode 100644 src/main/java/common/util/NumberUtils.java delete mode 100644 src/main/java/common/util/PageUtils.java delete mode 100644 src/main/java/common/util/RetryUtils.java delete mode 100644 src/main/java/common/util/StringUtil.java delete mode 100644 src/main/java/common/util/compare/CompareUtils.java delete mode 100644 src/main/java/common/util/compare/JacksonUtils.java delete mode 100644 src/main/java/common/util/compare/JsonUtils.java delete mode 100644 "src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/JavaExcelFullGCTest.java" delete mode 100644 "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.class" delete mode 100644 src/main/test/common/util/DataUtilsTest.java delete mode 100644 src/main/test/common/util/ExcelReadUtilsTest.java diff --git a/pom.xml b/pom.xml index 0a58fa44..05d041b9 100644 --- a/pom.xml +++ b/pom.xml @@ -7,11 +7,6 @@ org.tianbin algorithm 1.0-SNAPSHOT - war - - algorithm_practice Maven Webapp - - http://www.example.com UTF-8 @@ -20,210 +15,69 @@ + - cn.hutool - hutool-all - 5.4.5 - - - - io.github.biezhi - oh-my-email - 0.0.3 - - - - org.apache.poi - poi - 3.17 - - - org.apache.poi - poi-ooxml - 3.17 - - - com.alibaba - easyexcel - 2.2.7 - - - - com.esotericsoftware - reflectasm - 1.11.9 - - - - org.springframework - spring-beans - 5.3.12 - - - org.springframework - spring-context - 4.3.8.RELEASE - - - org.springframework - spring-web - 4.3.29.RELEASE - - - org.apache.tomcat.embed - tomcat-embed-core - 8.5.63 + io.github.nibnait + common-enhance + 1.0-SNAPSHOT cglib cglib - 3.2.12 + 3.3.0 - + com.lmax disruptor - 3.2.0 + 3.4.4 io.netty netty-all - 4.1.44.Final - - - - org.apache.commons - commons-lang3 - 3.8.1 - - - - org.apache.commons - commons-collections4 - 4.4 - - - - com.alibaba - fastjson - 1.2.79 - - - - com.google.collections - google-collections - 1.0 - - - org.projectlombok - lombok - 1.18.4 - - - net.sourceforge.jexcelapi - jxl - 2.6.12 - - - - junit - junit - 4.13.1 + 4.1.75.Final - + com.caucho hessian - 4.0.63 + 4.0.65 - + redis.clients jedis - 3.3.0 - - - - - com.google.guava - guava - 30.0-jre - compile + 4.2.1 - - - com.json.comparison - comparison-core - 1.2 - - - com.fasterxml.jackson.core - jackson-core - 2.11.2 - + - com.fasterxml.jackson.core - jackson-databind - 2.11.2 + com.esotericsoftware + reflectasm + 1.11.9 - + - com.github.pagehelper - pagehelper - 5.0.1 + org.springframework + spring-context + 5.3.17 + - javax.servlet - servlet-api - 2.5 + junit + junit + 4.13.2 - - algorithm_practice - - - - maven-clean-plugin - 3.1.0 - - - - maven-resources-plugin - 3.0.2 - - - maven-compiler-plugin - 3.8.0 - - - maven-surefire-plugin - 2.22.1 - - - maven-war-plugin - 3.2.2 - - - maven-install-plugin - 2.5.2 - - - maven-deploy-plugin - 2.8.2 - - - - diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" index 9c17f110..c2940b9e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.util.SysOut; -import common.util.StringUtil; +import io.github.nibnait.common.constants.CommonConstants; import junit.framework.TestCase; import org.junit.Test; @@ -145,7 +145,7 @@ private int lengthOfLongestSubstring3(String s) { * 玩转字符串 */ private int lengthOfLongestSubstring2(String s) { - String longestSubString = StringUtil.EMPTY_STRING; + String longestSubString = CommonConstants.EMPTY_STRING; StringBuilder currentStringBuilder = new StringBuilder(""); for (int i = 0; i < s.length(); i++) { Character currentChar = s.charAt(i); diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index ed37c8c0..3739a2ba 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.datastruct.ListNode; -import common.util.compare.CompareUtils; +import common.util.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" index 1743505e..1fecbdd9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import com.google.common.collect.Lists; -import common.util.StringUtil; +import org.apache.commons.lang3.StringUtils; import org.junit.Assert; import org.junit.Test; @@ -135,7 +135,7 @@ private void dfs(List res, Deque path, Set wordSet, Stri */ public List wordBreak2(String s, List wordDict) { List result = new ArrayList<>(); - if (StringUtil.isBlank(s)) { + if (StringUtils.isBlank(s)) { return result; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index 8faf560f..be89cbbd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.compare.CompareUtils; +import common.util.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 58b13c5d..4439ebe6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.ListNode; -import common.util.compare.CompareUtils; +import common.util.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" "b/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" index 328e66a4..2a5e6127 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" @@ -1,6 +1,5 @@ package algorithm_practice.LeetCode.code1000; -import common.util.StringUtil; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index 836c9c99..8f146f7a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.ListNode; -import common.util.compare.CompareUtils; +import common.util.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index 960014dd..bc7c02dc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code300; import common.datastruct.ListNode; -import common.util.compare.CompareUtils; +import common.util.CompareUtils; import common.util.ConstructListNode; import common.util.SysOut; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" "b/src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" index fb47ef97..77b31678 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.util.StringUtil; +import org.apache.commons.lang3.StringUtils; /** * 题目一:输入一个英文句子,翻转句子中单词的顺序,但单词内字啊的顺序不变。为简单起见,标点符号和普通字母一样处理。 @@ -25,7 +25,7 @@ public class f42_1$翻转单词顺序 { * @return */ private static String reverseSentence2(String str) { - if (StringUtil.isBlank(str)){ + if (StringUtils.isBlank(str)){ return ""; } String[] arr = str.split(" "); @@ -44,7 +44,7 @@ public static void main(String[] args) { } private static String reverseSentence(String str) { - if (StringUtil.isBlank(str)){ + if (StringUtils.isBlank(str)){ return ""; } char[] chars = str.toCharArray(); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" "b/src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" index 0e4fc7e6..c4e1199a 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" @@ -1,7 +1,6 @@ package algorithm_practice.SwordOffer.old; - -import common.util.StringUtil; +import org.apache.commons.lang3.StringUtils; import static algorithm_practice.SwordOffer.old.f42_1$翻转单词顺序.Reverse; @@ -34,7 +33,7 @@ public static void main(String[] args) { } private static String leftRotateString(String str, int n) { - if (StringUtil.isBlank(str) || n<=0 || n>=str.length()){ //n==0,n==str.length 都不用翻转! + if (StringUtils.isBlank(str) || n<=0 || n>=str.length()){ //n==0,n==str.length 都不用翻转! return str; } char[] chars = str.toCharArray(); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" "b/src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" index 77223d1b..bd008865 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.util.StringUtil; +import org.apache.commons.lang3.StringUtils; import java.util.HashMap; import java.util.LinkedHashMap; @@ -35,7 +35,7 @@ public class h55_字符流中第一个不重复的字符 { private static char firstAppearingOnce(String str) { - if (StringUtil.isBlank(str)){ + if (StringUtils.isBlank(str)){ return '\0'; } HashMap map = new LinkedHashMap<>(); diff --git a/src/main/java/common/CommonConstants.java b/src/main/java/common/CommonConstants.java deleted file mode 100644 index 722e17da..00000000 --- a/src/main/java/common/CommonConstants.java +++ /dev/null @@ -1,46 +0,0 @@ -package common; - -/** - * Created by nibnait on 2022/03/10 - */ -public class CommonConstants { - - public static final String FILE_PATH = "/data/file"; - public static final String FILE_ENCODE_UTF8 = "UTF-8"; - - public static final String AUDIT_DEFAULT_VALUE = "NULL"; - public static final String SKU_AUDIT_DEFAULT_VALUE = "NULL"; - public static final String NULL_STRING = "null"; - public static final String EMPTY_STRING = ""; - public static final String EMPTY_STRING_LIST = "[\"\"]"; - public static final Byte BYTE_ZERO = (byte) 0; - public static final Integer INTEGER_ZERO = 0; - public static final Long LONG_ZERO = 0L; - public static final Byte BYTE_ONE = (byte) 1; - public static final Integer INTEGER_ONE = 1; - public static final Long Long_ONE = 1L; - - public static final String UNDERLINE_SEPARATOR = "_"; - public static final String BLANK_SPACE_SEPARATOR = " "; - public static final String DOT_SEPARATOR = "."; - public static final String MINUS_SEPARATOR = "-"; - public static final String MINUS_MINUS_SEPARATOR = "--"; - public static final String COMMA_SEPARATOR = ","; - public static final String DWUKROPEK_SEPARATOR = ":"; - public static final String SEMICOLON_SEPARATOR = ";"; - public static final String EQUAL_SIGN_SEPARATOR = "="; - public static final String SLASH_SEPARATOR = "/"; - public static final String BACK_SLASH_SEPARATOR = "\\"; - - public static final String HDFS_FILE_FIELD_SEPARATOR = "\u0001"; - public static final String NEWLINE_SEPARATOR = "\n"; - - public static final String FULL_SHAPED_SEMICOLON_SEPARATOR = ";"; - - public static final String SUCCESS = "success"; - public static final String FAIL = "fail"; - - public static final String SUFFIX_XLS = ".xls"; - public static final String SUFFIX_CSV = ".csv"; - public static final String SUFFIX_PDF = ".pdf"; -} diff --git a/src/main/java/common/bo/BaseResponse.java b/src/main/java/common/bo/BaseResponse.java deleted file mode 100644 index d485d4e3..00000000 --- a/src/main/java/common/bo/BaseResponse.java +++ /dev/null @@ -1,52 +0,0 @@ -package common.bo; - -import common.enums.ErrorCode; - -import java.io.Serializable; - -public class BaseResponse implements Serializable { - - private static final long serialVersionUID = 1L; - - public Long code; - - public String message; - - public T data; - - public Integer errtag = 0; - - public BaseResponse() { - } - - public BaseResponse(Long code, String message, T data) { - super(); - this.code = code; - this.message = message; - this.data = data; - } - - public BaseResponse(Long code, Integer errtag, String message, T data) { - super(); - this.code = code; - this.errtag = errtag; - this.message = message; - this.data = data; - } - - public BaseResponse(T data) { - super(); - this.code = ErrorCode.SUCCESS.getCode(); - this.message = ErrorCode.SUCCESS.getMessage(); - this.data = data; - } - - public BaseResponse(ErrorCode e, T data) { - super(); - this.code = e.getCode(); - this.message = e.getMessage(); - this.data = data; - } - -} - diff --git a/src/main/java/common/bo/EmailBO.java b/src/main/java/common/bo/EmailBO.java deleted file mode 100644 index 704fe8ab..00000000 --- a/src/main/java/common/bo/EmailBO.java +++ /dev/null @@ -1,29 +0,0 @@ -package common.bo; - -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.io.File; -import java.util.List; - -/** - * Created by nibnait on 2021/01/27 - */ -@Data -@AllArgsConstructor -@NoArgsConstructor -public class EmailBO { - - private String fromNickName; - - private String toAddress; - - private String ccAddress; - - private String subject; - - private String content; - - private List attachFiles; -} diff --git a/src/main/java/common/bo/compare/CompareBO.java b/src/main/java/common/bo/compare/CompareBO.java deleted file mode 100644 index 4b7d7160..00000000 --- a/src/main/java/common/bo/compare/CompareBO.java +++ /dev/null @@ -1,56 +0,0 @@ -package common.bo.compare; - -import lombok.AllArgsConstructor; -import lombok.Data; - -import java.util.Collections; -import java.util.HashSet; -import java.util.LinkedHashSet; -import java.util.Set; - -/** - * Created by nibnait on 2021/06/23 - */ -@Data -public class CompareBO { - - /** - * 当前对比的字段 - */ - private String currentField; - - /** - * 排除字段 - */ - private Set excludeFields = new HashSet<>(); - - /** - * 聚焦字段 - */ - private Set focusFields = new HashSet<>(); - - /** - * 系统默认优化项: pageInfo - */ - private Set optimizations = new LinkedHashSet<>(Collections.singletonList(OptimizationType.IGNORE_NEW_FIELDS)); - - @AllArgsConstructor - public enum OptimizationType { - /** - * 优化类型 - */ - PAGE_HELPER("pageHelper 分页插件"), - IGNORE_NEW_FIELDS("比对时忽略新增字段"), - IGNORE_MISSING_FIELDS("比对时忽略丢失字段"), - ; - - String desc; - } - - public static CompareBO newNoOptimizeCompareBO() { - CompareBO compareBO = new CompareBO(); - compareBO.setOptimizations(new LinkedHashSet<>()); - return compareBO; - } - -} diff --git a/src/main/java/common/bo/compare/CompareResultDTO.java b/src/main/java/common/bo/compare/CompareResultDTO.java deleted file mode 100644 index 768c685e..00000000 --- a/src/main/java/common/bo/compare/CompareResultDTO.java +++ /dev/null @@ -1,37 +0,0 @@ -package common.bo.compare; - -import lombok.Data; -import lombok.NoArgsConstructor; - -import java.util.List; - -/** - * Created by nibnait on 2021/06/23 - */ -@Data -@NoArgsConstructor -public class CompareResultDTO { - - private boolean isMatch; - - private List modifiedFields; - - private List missingFields; - - private List newFields; - - private String message; - - @Data - public static class FieldComparison { - private String field; - - private Object expected; - - private Object actual; - } - - public CompareResultDTO(boolean isMatch) { - this.isMatch = isMatch; - } -} diff --git a/src/main/java/common/bo/excel/SheetBO.java b/src/main/java/common/bo/excel/SheetBO.java deleted file mode 100644 index 80d006e9..00000000 --- a/src/main/java/common/bo/excel/SheetBO.java +++ /dev/null @@ -1,32 +0,0 @@ -package common.bo.excel; - -import org.apache.poi.hssf.usermodel.HSSFCell; -import org.apache.poi.hssf.usermodel.HSSFRow; -import org.apache.poi.hssf.usermodel.HSSFSheet; - -import java.util.List; - -/** - * Created by nibnait on 2021/01/21 - */ -public class SheetBO { - - private HSSFSheet sheet; - private Integer rowIndex; - - public SheetBO(HSSFSheet sheet) { - this.sheet = sheet; - rowIndex = 0; - } - - public void appendRow(List row) { - HSSFRow hssfRow = sheet.createRow(rowIndex); - HSSFCell hssfCell; - rowIndex += 1; - for (int i = 0; i < row.size(); i++) { - hssfCell = hssfRow.createCell(i); - hssfCell.setCellValue(row.get(i)); - } - } - -} diff --git a/src/main/java/common/bo/excel/WorkBookBO.java b/src/main/java/common/bo/excel/WorkBookBO.java deleted file mode 100644 index 6e5f3781..00000000 --- a/src/main/java/common/bo/excel/WorkBookBO.java +++ /dev/null @@ -1,74 +0,0 @@ -package common.bo.excel; - - -import common.CommonConstants; -import common.util.DateUtils; -import common.util.EnhanceFileUtils; -import lombok.Data; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.apache.poi.hssf.usermodel.HSSFSheet; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; - -import java.io.File; -import java.util.ArrayList; -import java.util.List; - -/** - * Created by nibnait on 2021/01/21 - */ -@Data -@Slf4j -public class WorkBookBO { - - private HSSFWorkbook workbook; - - private List sheetList = new ArrayList<>(); - - public WorkBookBO() { - workbook = new HSSFWorkbook(); - sheetList.add(new SheetBO(workbook.createSheet("Sheet1"))); - } - - public WorkBookBO(List> sheetTitle, String... sheetName) { - workbook = new HSSFWorkbook(); - if (CollectionUtils.isEmpty(sheetTitle) || sheetName == null - || sheetTitle.size() != sheetName.length) { - // 直接创建一个默认的sheet - sheetList.add(new SheetBO(workbook.createSheet("Sheet1"))); - return; - } - - for (int i = 0; i < sheetTitle.size(); i++) { - HSSFSheet sheet = workbook.createSheet(sheetName[i]); - SheetBO sheetBO = new SheetBO(sheet); - sheetBO.appendRow(sheetTitle.get(i)); - sheetList.add(sheetBO); - } - } - - /** - * 将 workbook 写成文件 - * @param fileName fileName 重命名文件(可以为空) - */ - public File writeToFile(String fileName) { - if (StringUtils.isBlank(fileName)) { - fileName = String.valueOf(DateUtils.currentTimeMillis()); - } - -// fileName = CommonConstants.FILE_PATH + CommonConstants.SLASH_SEPARATOR + fileName + CommonConstants.SUFFIX_XLS; - fileName = "/Users/nibnait/data/file" + CommonConstants.SLASH_SEPARATOR + fileName + CommonConstants.SUFFIX_XLS; - File file = new File(fileName); - - try { - file = EnhanceFileUtils.createIfNecessary(fileName); - workbook.write(file); - workbook.close(); - } catch (Exception e) { - log.error("WorkBookBO writeToFile error ", e); - } - - return file; - } -} diff --git a/src/main/java/common/context/ApplicationContextHelper.java b/src/main/java/common/context/ApplicationContextHelper.java index 6c857f00..e782af88 100644 --- a/src/main/java/common/context/ApplicationContextHelper.java +++ b/src/main/java/common/context/ApplicationContextHelper.java @@ -1,6 +1,6 @@ package common.context; -import common.exception.ServiceException; +import io.github.nibnait.common.exception.ServiceException; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.BeanDefinition; diff --git a/src/main/java/common/exception/ClientViewException.java b/src/main/java/common/exception/ClientViewException.java deleted file mode 100644 index 937414a3..00000000 --- a/src/main/java/common/exception/ClientViewException.java +++ /dev/null @@ -1,43 +0,0 @@ -package common.exception; - -import common.util.DataUtils; - -public class ClientViewException extends RuntimeException { - - private Long code; - - private String message; - - public Long getCode() { - return code; - } - - public void setCode(Long code) { - this.code = code; - } - - public String getMsg() { - return message; - } - - public void setMsg(String message) { - this.message = message; - } - - public ClientViewException() { super(); } - - public ClientViewException(String message){ - super(message); - } - - public ClientViewException(String message, Object... args) { - super(DataUtils.format(message, args)); - } - - public ClientViewException(Long code, String message){ - super(message); - this.code = code; - this.message = message; - } - -} diff --git a/src/main/java/common/exception/GlobalExceptionHandler.java b/src/main/java/common/exception/GlobalExceptionHandler.java deleted file mode 100644 index d0e61ae5..00000000 --- a/src/main/java/common/exception/GlobalExceptionHandler.java +++ /dev/null @@ -1,130 +0,0 @@ -package common.exception; - -import common.enums.ErrorCode; -import lombok.extern.slf4j.Slf4j; -import org.springframework.validation.BindingResult; -import org.springframework.validation.FieldError; -import org.springframework.validation.ObjectError; -import org.springframework.web.bind.MethodArgumentNotValidException; -import org.springframework.web.bind.MissingServletRequestParameterException; -import org.springframework.web.bind.annotation.ControllerAdvice; -import org.springframework.web.bind.annotation.ExceptionHandler; -import org.springframework.web.bind.annotation.ResponseBody; -import org.springframework.web.method.annotation.MethodArgumentTypeMismatchException; - -import javax.servlet.http.HttpServletRequest; - -@ControllerAdvice -@Slf4j -public class GlobalExceptionHandler { - - @ExceptionHandler(MethodArgumentTypeMismatchException.class) - @ResponseBody - public GlobalExceptionResponse methodArgumentTypeMismatchExceptionHandler(HttpServletRequest req, MethodArgumentTypeMismatchException e) { - - String p = e.getParameter().getParameterName(); - String message = "param error: " + p; - Long code = ErrorCode.SERVICE_ERROR.getCode(); - GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); - log.error("MethodArgumentTypeMismatchException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); - return globalExceptionResponse; - } - - - @ExceptionHandler(MissingServletRequestParameterException.class) - @ResponseBody - public GlobalExceptionResponse missingServletRequestParameterExceptionHandler(HttpServletRequest req, MissingServletRequestParameterException e) { - - String p = e.getParameterName(); - String message = "param missing error: " + p; - - Long code = ErrorCode.SERVICE_ERROR.getCode(); - GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); - log.error("MethodArgumentTypeMismatchException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); - return globalExceptionResponse; - } - - - @ExceptionHandler(MethodArgumentNotValidException.class) - @ResponseBody - public GlobalExceptionResponse methodArgumentNotValidExceptionHandler(HttpServletRequest req, MethodArgumentNotValidException e) { - String p = e.getParameter().getParameterName(); - BindingResult bindingResult = e.getBindingResult(); - String fieldErrorMessage = ""; - if (bindingResult.hasErrors()) { - StringBuilder sb = new StringBuilder(); - for (ObjectError objectError : bindingResult.getAllErrors()) { - sb.append(((FieldError) objectError).getField() + ":").append(objectError.getDefaultMessage()).append("; "); - } - fieldErrorMessage = sb.toString(); - } - String message = "param error: " + p + ", " + fieldErrorMessage; - Long code = ErrorCode.SERVICE_ERROR.getCode(); - GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); - log.error("MethodArgumentNotValidException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); - return globalExceptionResponse; - } - - @ExceptionHandler(common.exception.ServiceException.class) - @ResponseBody - public GlobalExceptionResponse exceptionHandler(HttpServletRequest req, common.exception.ServiceException e) { - String message = e.getMessage(); - if (null == message || message.equals("")) { - message = "server runtime error"; - } - - Long code = e.getCode(); - if (null == code) { - code = ErrorCode.SERVICE_ERROR.getCode(); - } - - GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); - log.error("ServiceException: from:{} uri:{} code:{} msg:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); - return globalExceptionResponse; - } - - @ExceptionHandler(ClientViewException.class) - @ResponseBody - public GlobalExceptionResponse viewExceptionHandler(HttpServletRequest req, ClientViewException e) { - String message = e.getMessage(); - if (null == message || message.equals("")) { - message = "server runtime error"; - } - - Long code = e.getCode(); - if (null == code) { - code = ErrorCode.SERVICE_ERROR.getCode(); - } - GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(code, message); - log.info("ClientViewException: from:{} uri:{} code:{} message:{}", req.getRemoteHost(), req.getRequestURI(), code, message, e); - return globalExceptionResponse; - } - - @ExceptionHandler(IllegalArgumentException.class) - @ResponseBody - public GlobalExceptionResponse illegalArgumentExceptionHandler(HttpServletRequest req, IllegalArgumentException e) { - String message = e.getMessage(); - if (null == message || message.equals("")) { - message = "IllegalArgumentException"; - } - - GlobalExceptionResponse globalExceptionResponse = new GlobalExceptionResponse(ErrorCode.SERVICE_ERROR.getCode(), message); - log.info("IllegalArgumentException: from:{} uri:{} message:{}", req.getRemoteHost(), req.getRequestURI(), message, e); - return globalExceptionResponse; - } - - @ExceptionHandler(RuntimeException.class) - @ResponseBody - public GlobalExceptionResponse runtimeExceptionHandler(HttpServletRequest req, RuntimeException e) { - log.error("RuntimeException: from:{} uri:{} error:{}", req.getRemoteHost(), req.getRequestURI(), e); - return new GlobalExceptionResponse(ErrorCode.SERVICE_ERROR.getCode(), ErrorCode.SERVICE_ERROR.getMessage()); - } - - @ExceptionHandler(Exception.class) - @ResponseBody - public GlobalExceptionResponse defaultExceptionHandler(HttpServletRequest req, Exception e) { - log.error("Exception: from:{} uri:{} error:{}", req.getRemoteHost(), req.getRequestURI(), e); - return new GlobalExceptionResponse(ErrorCode.SERVICE_ERROR.getCode(), ErrorCode.SERVICE_ERROR.getMessage()); - } - -} diff --git a/src/main/java/common/exception/GlobalExceptionResponse.java b/src/main/java/common/exception/GlobalExceptionResponse.java deleted file mode 100644 index 177fe6fb..00000000 --- a/src/main/java/common/exception/GlobalExceptionResponse.java +++ /dev/null @@ -1,43 +0,0 @@ -package common.exception; - -import common.enums.ErrorCode; - -import java.io.Serializable; - -/** - * Created by nibnait on 2021/09/01 - */ -public class GlobalExceptionResponse implements Serializable { - - private static final long serialVersionUID = 1L; - - public Long code; - public String message; - public Integer errtag = 0; - - public Long getCode() { - return code; - } - - public void setCode(Long code) { - this.code = code; - } - - public String getMessage() { - return message; - } - - public void setMessage(String message) { - this.message = message; - } - - public GlobalExceptionResponse(Long code, String message) { - this.code = code; - this.message = message; - } - - public GlobalExceptionResponse(ErrorCode errorCode) { - this.code = errorCode.getCode(); - this.message = errorCode.getMessage(); - } -} diff --git a/src/main/java/common/exception/ServiceException.java b/src/main/java/common/exception/ServiceException.java deleted file mode 100644 index 00b6fa63..00000000 --- a/src/main/java/common/exception/ServiceException.java +++ /dev/null @@ -1,45 +0,0 @@ -package common.exception; - -import common.util.DataUtils; -import lombok.extern.slf4j.Slf4j; - -@Slf4j -public class ServiceException extends RuntimeException { - - private Long code; - - private String message; - - public Long getCode() { - return code; - } - - public void setCode(Long code) { - this.code = code; - } - - public String getMsg() { - return message; - } - - public void setMsg(String message) { - this.message = message; - } - - public ServiceException() { super(); } - - public ServiceException(String message){ - super(message); - } - - public ServiceException(Long code, String message){ - super(message); - this.code = code; - this.message = message; - } - - public ServiceException(String message, Object... args) { - super(DataUtils.format(message, args)); - } - -} diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java new file mode 100644 index 00000000..b52137cc --- /dev/null +++ b/src/main/java/common/util/CompareUtils.java @@ -0,0 +1,21 @@ +package common.util; + +import common.datastruct.ListNode; + +/** + * Created by nibnait on 2022/04/11 + */ +public class CompareUtils { + + /** + * 对比两个链表 + */ + public static boolean compareListNode(ListNode left, ListNode right) { + while (left != null && right != null && left.val == right.val) { + left = left.next; + right = right.next; + } + return left == right; + } + +} diff --git a/src/main/java/common/util/DataUtils.java b/src/main/java/common/util/DataUtils.java deleted file mode 100644 index 9acc3731..00000000 --- a/src/main/java/common/util/DataUtils.java +++ /dev/null @@ -1,161 +0,0 @@ -package common.util; - -import com.alibaba.fastjson.JSON; -import com.google.common.collect.Lists; -import com.google.common.collect.Maps; -import com.google.common.collect.Sets; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.helpers.MessageFormatter; - -import java.util.Collection; -import java.util.List; -import java.util.Map; -import java.util.Objects; -import java.util.concurrent.CopyOnWriteArrayList; -import java.util.function.Function; -import java.util.stream.Collectors; - -/** - * Created by nibnait on 2021/08/18 - */ -@Slf4j -public class DataUtils { - - /** - * 分批调rpc接口 查询数据 - * @param list 入参 eg: skuIdList - * @param size 一批的数量 eg: 100 - * @param function 一个lambda表达式 eg: skuIdList -> itemsSkuService.batchQuery(skuIdList) - * @return 将每一次的返回值,用 flatMap 打平 返回一个 list - */ - public static List getDataPartition(List list, Integer size, Function, List> function) { - return Lists.partition(list, size).stream() - .map(function) - .flatMap(Collection::stream) - .filter(Objects::nonNull) - .collect(Collectors.toList()); - } - - /** - * 返回 list1 - (list1 ∩ list2) - */ - public static List difference(Collection list1, Collection list2) { - return Lists.newArrayList(Sets.difference(Sets.newHashSet(list1), Sets.newHashSet(list2))); - } - - /** - * 返回交集 list1 ∩ list2 - */ - public static List intersection(Collection list1, Collection list2) { - return Lists.newArrayList(Sets.intersection(Sets.newHashSet(list1), Sets.newHashSet(list2))); - } - - /** - * @param format abc{}e - * @param args d - * @return abcde - */ - public static String format(String format, Object... args) { - return MessageFormatter.arrayFormat(format, args).getMessage(); - } - - /** - * @param clazz 类型不可为抽象类/接口 - */ - public static T parseObject(String s, Class clazz) { - if (StringUtils.isBlank(s) || "null".equalsIgnoreCase(s)) { - try { - return clazz.newInstance(); - } catch (InstantiationException | IllegalAccessException e) { - log.error(e.getMessage(), e); - return null; - } - } - try { - return JSON.parseObject(s, clazz); - } catch (Throwable e) { - log.error(e.getMessage(), e); - return null; - } - } - - public static List parseArray(String s, Class clazz) { - if (StringUtils.isBlank(s) || "null".equalsIgnoreCase(s)) { - return Lists.newArrayList(); - } - return JSON.parseArray(s, clazz); - } - - public static String toJsonStringObject(Object o) { - if (o == null) { - return JSON.toJSONString(Maps.newHashMap()); - } - return JSON.toJSONString(o); - } - - public static String toJsonStringArray(Object o) { - if (o == null) { - return JSON.toJSONString(Lists.newArrayList()); - } - return JSON.toJSONString(o); - } - - /** - * 将 element 加到 list 中 - */ - public static List addToList(T element, List list) { - list = CollectionUtils.isEmpty(list) ? Lists.newArrayList() : list; - if (element != null) { - list.add(element); - return list.stream().distinct().collect(Collectors.toList()); - } - return CollectionUtils.isEmpty(list) ? null : list; - } - - /** - * 将 element 加到 list 中 - */ - public static List addToList(List element, List list) { - list = CollectionUtils.isEmpty(list) ? Lists.newArrayList() : list; - if (CollectionUtils.isNotEmpty(element)) { - list.addAll(element); - return list.stream().distinct().collect(Collectors.toList()); - } - return CollectionUtils.isEmpty(list) ? null : list; - } - - /** - * 将 element 从 list 中删除 - */ - public static List removeElement(T element, List list) { - if (CollectionUtils.isEmpty(list)) { - return list; - } - - CopyOnWriteArrayList cowList = new CopyOnWriteArrayList<>(list); - cowList.removeIf(t -> t.equals(element)); - return cowList; - } - - /** - * 返回 list中 重复的元素 - */ - public static List getDuplicateElements(List list) { - return list.stream() - .collect(Collectors.toMap(e -> e, e -> 1, Integer::sum)) - .entrySet().stream() - .filter(e -> e.getValue() > 1) - .map(Map.Entry::getKey) - .collect(Collectors.toList()); - } - - /** - * 判断 list 中 是否包含 t - */ - public static boolean contains(List list, T t) { - return CollectionUtils.isNotEmpty(list) && list.contains(t); - } - -} diff --git a/src/main/java/common/util/DateConvertUtils.java b/src/main/java/common/util/DateConvertUtils.java deleted file mode 100644 index 274b032f..00000000 --- a/src/main/java/common/util/DateConvertUtils.java +++ /dev/null @@ -1,158 +0,0 @@ -package common.util; - -import lombok.extern.slf4j.Slf4j; - -import java.text.DateFormat; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.Date; - -/** - * Created by nibnait on 2022/03/21 - */ -@Slf4j -public class DateConvertUtils { - - public static final String TIME_INTERVAL_SECOND = "second"; - public static final String TIME_INTERVAL_MINUTE = "minute"; - public static final String TIME_INTERVAL_HOUR = "hour"; - public static final String TIME_INTERVAL_DAY = "day"; - public static final String TIME_INTERVAL_WEEK = "week"; - public static final String TIME_INTERVAL_MONTH = "month"; - public static final String TIME_INTERVAL_QUARTER = "quarter"; - public static final String TIME_INTERVAL_YEAR = "year"; - public static final String DATE_FORMAT = "yyyy-MM-dd"; - public static final String TIME_FORMAT = "HH:mm:ss"; - public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; - - - - public static String format(Date date, String dateFormat) { - if (date == null) - return null; - DateFormat df = new SimpleDateFormat(dateFormat); - return df.format(date); - } - - public static String getDateString(String datePattern) { - return new SimpleDateFormat(datePattern).format(DateUtils.now()); - } - - public static String getYesterdayString(String dateFormat) { - Date yesterday = add(Calendar.DAY_OF_YEAR, DateUtils.now(), -1); - return DateConvertUtils.format(yesterday, dateFormat); - } - - public static Date add(int field, Date date, int value) { - Calendar c = Calendar.getInstance(); - c.setTime(date); - - int fieldNewValue = (c.get(field) + value); - c.set(field, fieldNewValue); - return c.getTime(); - } - - public static long dateDiff(String timeInterval, Date date1, Date date2) { - Calendar calendar = Calendar.getInstance(); - if (timeInterval.equals(TIME_INTERVAL_YEAR)) { - calendar.setTime(date1); - int time = calendar.get(Calendar.YEAR); - calendar.setTime(date2); - return (long)time - calendar.get(Calendar.YEAR); - } - - if (timeInterval.equals(TIME_INTERVAL_QUARTER)) { - calendar.setTime(date1); - int time = calendar.get(Calendar.YEAR) * 4; - calendar.setTime(date2); - time -= calendar.get(Calendar.YEAR) * 4; - calendar.setTime(date1); - time += calendar.get(Calendar.MONTH) / 4; - calendar.setTime(date2); - return (long)time - calendar.get(Calendar.MONTH) / 4; - } - - if (timeInterval.equals(TIME_INTERVAL_MONTH)) { - calendar.setTime(date1); - int time = calendar.get(Calendar.YEAR) * 12; - calendar.setTime(date2); - time -= calendar.get(Calendar.YEAR) * 12; - calendar.setTime(date1); - time += calendar.get(Calendar.MONTH); - calendar.setTime(date2); - return (long)time - calendar.get(Calendar.MONTH); - } - - if (timeInterval.equals(TIME_INTERVAL_WEEK)) { - calendar.setTime(date1); - int time = calendar.get(Calendar.YEAR) * 52; - calendar.setTime(date2); - time -= calendar.get(Calendar.YEAR) * 52; - calendar.setTime(date1); - time += calendar.get(Calendar.WEEK_OF_YEAR); - calendar.setTime(date2); - return (long)time - calendar.get(Calendar.WEEK_OF_YEAR); - } - - if (timeInterval.equals(TIME_INTERVAL_DAY)) { - calendar.setTime(date1); - int time = calendar.get(Calendar.DAY_OF_YEAR) - + calendar.get(Calendar.YEAR) * 365; - calendar.setTime(date2); - return (long)time - - (calendar.get(Calendar.DAY_OF_YEAR) + calendar - .get(Calendar.YEAR) * 365); - } - - if (timeInterval.equals(TIME_INTERVAL_HOUR)) { - long time = date1.getTime() / 1000 / 60 / 60; - return time - date2.getTime() / 1000 / 60 / 60; - } - - if (timeInterval.equals(TIME_INTERVAL_MINUTE)) { - long time = date1.getTime() / 1000 / 60; - return time - date2.getTime() / 1000 / 60; - } - - if (timeInterval.equals(TIME_INTERVAL_SECOND)) { - long time = date1.getTime() / 1000; - return time - date2.getTime() / 1000; - } - - return date1.getTime() - date2.getTime(); - } - - public static long dateDiff(String timeInterval, Long unixTime1, - Long unixTime2) { - return dateDiff(timeInterval, new Date(unixTime1), new Date(unixTime2)); - } - - public static void main(String[] args) { - } - - /** - * 取得当前时间戳(精确到秒) - * @return - */ - public static int getCurrentTime(){ - return DateUtils.currentTime(); - } - - - /** - * 时间戳转换成日期格式字符串 - * @param seconds 精确到秒的字符串 - * @return - */ - public static String timeStampToDate(String seconds,String format) { - if(seconds == null || seconds.isEmpty() || seconds.equals("null")){ - return ""; - } - if(format == null || format.isEmpty()){ - format = DATE_TIME_FORMAT; - } - SimpleDateFormat sdf = new SimpleDateFormat(format); - return sdf.format(new Date(Long.valueOf(seconds+"000"))); - } - -} diff --git a/src/main/java/common/util/DateTimeCalcUtils.java b/src/main/java/common/util/DateTimeCalcUtils.java deleted file mode 100644 index 3ce13946..00000000 --- a/src/main/java/common/util/DateTimeCalcUtils.java +++ /dev/null @@ -1,40 +0,0 @@ -package common.util; - -import lombok.Data; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; - -/** - * Created by nibnait on 2021/09/08 - */ -public class DateTimeCalcUtils { - - /** - * 计算时间差(start - end) - */ - public static TimeBetween calcTimeBetween(LocalDateTime start, LocalDateTime end) { - TimeBetween timeBetween = new TimeBetween(); - timeBetween.setYears(ChronoUnit.YEARS.between(end, start)); - timeBetween.setMounths(ChronoUnit.MONTHS.between(end, start)); - timeBetween.setDays(ChronoUnit.DAYS.between(end, start)); - timeBetween.setHours(ChronoUnit.HOURS.between(end, start)); - timeBetween.setMinutes(ChronoUnit.MINUTES.between(end, start)); - timeBetween.setSeconds(ChronoUnit.SECONDS.between(end, start)); - timeBetween.setMillis(ChronoUnit.MILLIS.between(end, start)); - return timeBetween; - } - - @Data - public static class TimeBetween { - private Long years; - private Long mounths; - private Long days; - private Long hours; - private Long minutes; - private Long seconds; - private Long millis; - } - - -} diff --git a/src/main/java/common/util/DateTimeConvertUtils.java b/src/main/java/common/util/DateTimeConvertUtils.java deleted file mode 100644 index 8e8968d8..00000000 --- a/src/main/java/common/util/DateTimeConvertUtils.java +++ /dev/null @@ -1,215 +0,0 @@ -package common.util; - -import common.exception.ClientViewException; -import lombok.extern.slf4j.Slf4j; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.*; -import java.time.format.DateTimeFormatter; -import java.util.Date; - -@Slf4j -public class DateTimeConvertUtils { - - public static final String DATE_FORMAT = "yyyy-MM-dd"; - public static final String DATE_FORMAT1 = "yyyyMMdd"; - public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; - public static final String DATE_TIME_MILLI_FORMAT = "yyyy-MM-dd HH:mm:ss:SSS"; - - private static ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); - private static ZoneOffset BEIJING_ZONE_OFFSET = ZoneOffset.of("+8"); - private static int MILLI_TIMESTAMP_LENGTH = 13; - private static int SECOND_TIMESTAMP_LENGTH = 10; - - public static Long toMilliTimeStamp(long timeStamp) { - if (timeStamp == 0) { - return 0L; - } - int length = String.valueOf(timeStamp).length(); - if (MILLI_TIMESTAMP_LENGTH == length) { - return timeStamp; - } - if (SECOND_TIMESTAMP_LENGTH == length) { - return timeStamp * 1000; - } - throw new ClientViewException("{} 非10位/13位时间戳", timeStamp); - } - - public static Long toSecondTimeStamp(Date date) { - if (date == null) { - return 0L; - } - - return toSecondTimeStamp(date.getTime()); - } - - public static Long toSecondTimeStamp(long timeStamp) { - if (timeStamp == 0) { - return 0L; - } - int length = String.valueOf(timeStamp).length(); - if (MILLI_TIMESTAMP_LENGTH == length) { - return timeStamp / 1000; - } - if (SECOND_TIMESTAMP_LENGTH == length) { - return timeStamp; - } - throw new ClientViewException("非10位/13位时间戳"); - } - - /************************** String <==> timestamp ******************************/ - public static String timeStamp2String(long timeStamp) { - return new SimpleDateFormat(DATE_TIME_FORMAT).format(toMilliTimeStamp(timeStamp)); - } - - public static String timeStamp2String(long timeStamp, String format) { - return new SimpleDateFormat(format).format(toMilliTimeStamp(timeStamp)); - } - - public static String timeStamp2DateString(long timeStamp) { - return new SimpleDateFormat(DATE_FORMAT).format(toMilliTimeStamp(timeStamp)); - } - - public static String timeStamp2DateTimeString(long timeStamp) { - return new SimpleDateFormat(DATE_TIME_FORMAT).format(toMilliTimeStamp(timeStamp)); - } - - public static Long string2MilliSecond(String time) { - try { - return new SimpleDateFormat(DATE_TIME_FORMAT).parse(time).getTime(); - } catch (ParseException e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2MilliSecond 转时间戳失败", time, DATE_TIME_FORMAT); - } - } - - public static Long string2MilliSecond(String time, String format) { - try { - return new SimpleDateFormat(format).parse(time).getTime(); - } catch (ParseException e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2MilliSecond 转时间戳失败", time, format); - } - } - - /************************** LocalDateTime <==> timestamp ******************************/ - public static Long localDateTime2Second(LocalDateTime localDateTime) { - return localDateTime.toEpochSecond(BEIJING_ZONE_OFFSET); - } - - public static Long localDateTime2MillSecond(LocalDateTime localDateTime) { - return localDateTime.toInstant(BEIJING_ZONE_OFFSET).toEpochMilli(); - } - - public static LocalDate timeStamp2LocalDate(long timeStamp) { - return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDate(); - } - - public static LocalDateTime timeStamp2LocalDateTime(long timeStamp) { - return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDateTime(); - } - - /************************** String <==> Date ********************************************/ - public static Date string2Date(String dateString) { - try { - return new SimpleDateFormat(DATE_FORMAT).parse(dateString); - } catch (Exception e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2Date error", dateString, DATE_FORMAT); - } - } - - public static Date string2Date(String dateString, String dateFormat) { - try { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); - return simpleDateFormat.parse(dateString); - } catch (Exception e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2Date error", dateString, dateFormat); - } - } - - public static String date2String(Date date) { - return new SimpleDateFormat(DATE_FORMAT).format(date); - } - - public static String date2String(Date date, String dateFormat) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); - return simpleDateFormat.format(date); - } - - /************************** String <==> LocalDate ********************************************/ - public static LocalDate string2LocalDate(String dateString) { - return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); - } - - public static LocalDate string2LocalDate(String dateString, String dateFormat) { - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat); - return LocalDate.parse(dateString, dateTimeFormatter); - } - - public static String localDate2String(LocalDate localDate) { - return localDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); - } - - /************************** String <==> LocalDateTime ********************************************/ - public static LocalDateTime string2LocalDateTime(String dateTimeString) { - return LocalDateTime.parse(dateTimeString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); - } - - public static LocalDateTime dateString2LocalDateTime(String dateString) { - LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); - return localDate.atStartOfDay(); - } - - public static LocalDateTime dateTimeString2LocalDateTime(String dateString) { - return LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); - } - - public static String localDateTime2String(LocalDateTime localDateTime) { - return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); - } - - /************************** Date ==> LocalDate ********************************************/ - public static LocalDate dateToLocalDate(Date date) { - ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); - return zonedDateTime.toLocalDate(); - } - - /************************** Date ==> LocalDateTime ****************************************/ - public static LocalDateTime dateToLocalDateTime(Date date) { - ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); - return zonedDateTime.toLocalDateTime(); - } - - /******************* timestamp, java.sql.Date, LocalDate, LocalDateTime ==> Date ********************/ - public static Date toUtilDate(Object date) { - if (date == null) { - return null; - } - if (date instanceof Integer) { - return new Date(toMilliTimeStamp((Integer) date)); - } - if (date instanceof Long) { - return new Date(toMilliTimeStamp((Long) date)); - } - if (date instanceof java.sql.Date || date instanceof java.sql.Timestamp) { - return new Date(((Date) date).getTime()); - } - if (date instanceof Date) { - return (Date) date; - } - if (date instanceof LocalDate) { - return Date.from(((LocalDate) date).atStartOfDay(DEFAULT_ZONE_ID).toInstant()); - } - if (date instanceof LocalDateTime) { - return Date.from(((LocalDateTime) date).atZone(DEFAULT_ZONE_ID).toInstant()); - } - if (date instanceof ZonedDateTime) { - return Date.from(((ZonedDateTime) date).toInstant()); - } - if (date instanceof Instant) { - return Date.from((Instant) date); - } - - throw new UnsupportedOperationException("Don't know hot to convert " + date.getClass().getName() + " to java.util.Date"); - } - -} diff --git a/src/main/java/common/util/DateTimeUtil.java b/src/main/java/common/util/DateTimeUtil.java deleted file mode 100644 index 3d46b7bb..00000000 --- a/src/main/java/common/util/DateTimeUtil.java +++ /dev/null @@ -1,258 +0,0 @@ -package common.util; - -import com.alibaba.fastjson.JSON; -import com.google.common.collect.Lists; -import common.exception.ClientViewException; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.math.NumberUtils; - -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.time.*; -import java.time.format.DateTimeFormatter; -import java.util.Date; -import java.util.List; - -@Slf4j -public class DateTimeUtil { - public static final String TIME_MILLISECOND_FORMAT = "HH:mm:ss SSS"; - - public static final String DATE_FORMAT = "yyyy-MM-dd"; - public static final String DATE_TIME_FORMAT = "yyyy-MM-dd HH:mm:ss"; - - private static ZoneId DEFAULT_ZONE_ID = ZoneId.systemDefault(); - private static ZoneOffset BEIJING_ZONE_OFFSET = ZoneOffset.of("+8"); - private static int MILLI_TIMESTAMP_LENGTH = 13; - private static int SECOND_TIMESTAMP_LENGTH = 10; - - public static Long toMilliTimeStamp(long timeStamp) { - int length = String.valueOf(timeStamp).length(); - if (MILLI_TIMESTAMP_LENGTH == length) { - return timeStamp; - } - if (SECOND_TIMESTAMP_LENGTH == length) { - return timeStamp * 1000; - } - throw new ClientViewException("非10位/13位时间戳"); - } - - public static Long toSecondTimeStamp(long timeStamp) { - int length = String.valueOf(timeStamp).length(); - if (MILLI_TIMESTAMP_LENGTH == length) { - return timeStamp / 1000; - } - if (SECOND_TIMESTAMP_LENGTH == length) { - return timeStamp; - } - throw new ClientViewException("非10位/13位时间戳"); - } - - /************************** String <==> timestamp ******************************/ - public static String timeStamp2String(long timeStamp, String format) { - return new SimpleDateFormat(format).format(timeStamp); - } - - public static Long string2MilliSecond(String time) { - try { - return new SimpleDateFormat(DATE_TIME_FORMAT).parse(time).getTime(); - } catch (ParseException e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.转时间戳失败", time, DATE_TIME_FORMAT); - } - } - - public static Long string2MilliSecond(String time, String format) { - try { - return new SimpleDateFormat(format).parse(time).getTime(); - } catch (ParseException e) { - throw new ClientViewException("timeStr:{}, format:{} 转时间戳失败", time, format); - } - } - - /************************** LocalDateTime <==> timestamp ******************************/ - public static Long localDateTime2Second(LocalDateTime localDateTime) { - return localDateTime.toEpochSecond(BEIJING_ZONE_OFFSET); - } - - public static Long localDateTime2MillSecond(LocalDateTime localDateTime) { - return localDateTime.toInstant(BEIJING_ZONE_OFFSET).toEpochMilli(); - } - - public static LocalDate timeStamp2LocalDate(long timeStamp) { - return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDate(); - } - - public static LocalDateTime timeStamp2LocalDateTime(long timeStamp) { - return Instant.ofEpochMilli(toMilliTimeStamp(timeStamp)).atZone(DEFAULT_ZONE_ID).toLocalDateTime(); - } - - /************************** String <==> Date ********************************************/ - public static Date string2Date(String dateString) { - try { - return new SimpleDateFormat(DATE_FORMAT).parse(dateString); - } catch (Exception e) { - throw new ClientViewException("timeStr:{}, format:{} DateTimeConvertUtils.string2Date error", dateString, DATE_FORMAT); - } - } - - public static Date string2Date(String dateString, String dateFormat) throws ParseException { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); - return simpleDateFormat.parse(dateString); - } - - public static String date2String(Date date) { - return new SimpleDateFormat(DATE_FORMAT).format(date); - } - - public static String date2String(Date date, String dateFormat) { - SimpleDateFormat simpleDateFormat = new SimpleDateFormat(dateFormat); - return simpleDateFormat.format(date); - } - - /************************** String <==> LocalDate ********************************************/ - public static LocalDate string2LocalDate(String dateString) { - return LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); - } - - public static LocalDate string2LocalDate(String dateString, String dateFormat) { - DateTimeFormatter dateTimeFormatter = DateTimeFormatter.ofPattern(dateFormat); - return LocalDate.parse(dateString, dateTimeFormatter); - } - - public static String localDate2String(LocalDate localDate) { - return localDate.format(DateTimeFormatter.ofPattern(DATE_FORMAT)); - } - - /************************** String <==> LocalDateTime ********************************************/ - public static LocalDateTime string2LocalDateTime(String dateTimeString) { - return LocalDateTime.parse(dateTimeString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); - } - - public static LocalDateTime dateString2LocalDateTime(String dateString) { - LocalDate localDate = LocalDate.parse(dateString, DateTimeFormatter.ofPattern(DATE_FORMAT)); - return localDate.atStartOfDay(); - } - - public static LocalDateTime dateTimeString2LocalDateTime(String dateString) { - return LocalDateTime.parse(dateString, DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); - } - - public static String localDateTime2String(LocalDateTime localDateTime) { - return localDateTime.format(DateTimeFormatter.ofPattern(DATE_TIME_FORMAT)); - } - - /************************** Date ==> LocalDate ********************************************/ - public static LocalDate dateToLocalDate(Date date) { - ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); - return zonedDateTime.toLocalDate(); - } - - /************************** Date ==> LocalDateTime ****************************************/ - public static LocalDateTime dateToLocalDateTime(Date date) { - ZonedDateTime zonedDateTime = date.toInstant().atZone(DEFAULT_ZONE_ID); - return zonedDateTime.toLocalDateTime(); - } - - /******************* java.sql.Date, LocalDate, LocalDateTime ==> Date ********************/ - public static Date toUtilDate(Object date) { - if (date == null) { - return null; - } - if (date instanceof java.sql.Date || date instanceof java.sql.Timestamp) { - return new Date(((Date) date).getTime()); - } - if (date instanceof Date) { - return (Date) date; - } - if (date instanceof LocalDate) { - return Date.from(((LocalDate) date).atStartOfDay(DEFAULT_ZONE_ID).toInstant()); - } - if (date instanceof LocalDateTime) { - return Date.from(((LocalDateTime) date).atZone(DEFAULT_ZONE_ID).toInstant()); - } - if (date instanceof ZonedDateTime) { - return Date.from(((ZonedDateTime) date).toInstant()); - } - if (date instanceof Instant) { - return Date.from((Instant) date); - } - - throw new UnsupportedOperationException("Don't know hot to convert " + date.getClass().getName() + " to java.util.Date"); - } - - /** - * 校验时期合法性 - */ - public static boolean isDateValid(List date) { - boolean isvalid = true; - if (CollectionUtils.isEmpty(date)) { - return false; - } - - try { - if (date.size() == 1) { - return NumberUtils.isParsable(date.get(0)); - } - if (date.size() == 2) { - LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), 1); - } - if (date.size() == 3) { - if (NumberUtils.isParsable(date.get(2))) { - LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), Integer.parseInt(date.get(2))); - } else { - LocalDate.of(Integer.parseInt(date.get(0)), Integer.parseInt(date.get(1)), 1); - if (!Lists.newArrayList("上旬", "中上旬", "中旬", "中下旬", "下旬").contains(date.get(2))) { - isvalid = false; - } - } - } - if (date.size() > 3) { - isvalid = false; - } - } catch (Exception e) { - isvalid = false; - } - return isvalid; - } - - public static void main(String[] args) { - List date = Lists.newArrayList("2020", "02", "29"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2021", "02", "29"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2022", "02", "29"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2023", "02", "29"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2019", "02", "29"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2024", "02", "29"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2024", "04", "31"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2024", "05", "31"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2020", "02"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2020"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2020", "02", "上旬"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2020", "02", "xx"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - - date = Lists.newArrayList("2020", "02", "中旬", "lj"); - System.out.println(isDateValid(date) + "\t" + JSON.toJSONString(date)); - } -} diff --git a/src/main/java/common/util/DateUtils.java b/src/main/java/common/util/DateUtils.java deleted file mode 100644 index 838ef54a..00000000 --- a/src/main/java/common/util/DateUtils.java +++ /dev/null @@ -1,31 +0,0 @@ -package common.util; - -import java.time.LocalDateTime; -import java.util.Date; - -/** - * Created by nibnait on 2022/03/10 - */ -public class DateUtils { - - public static Date now() { - return new Date(); - } - - public static int currentTime() { - return (int) (System.currentTimeMillis() / 1000); - } - - public static Long currentTimeMillis() { - return System.currentTimeMillis(); - } - - public static Long nanoTime() { - return System.nanoTime(); - } - - public static LocalDateTime now8() { - return LocalDateTime.now(); - } - -} diff --git a/src/main/java/common/util/EmailUtils.java b/src/main/java/common/util/EmailUtils.java deleted file mode 100644 index 4cdfe554..00000000 --- a/src/main/java/common/util/EmailUtils.java +++ /dev/null @@ -1,79 +0,0 @@ -package common.util; - -import common.bo.EmailBO; -import io.github.biezhi.ome.OhMyEmail; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.io.File; -import java.util.List; -import java.util.Properties; - -@Slf4j -public class EmailUtils { - - - private static final String COMP_EMAIL = "w@tianbin.org"; - private static final String COMP_PW = "xxx"; - - private static final String SENDER_NAME = "系统"; - - - public static void initEmailCfg(){ - Properties props = new Properties(); - props.setProperty("username", COMP_EMAIL); - props.setProperty("password", COMP_PW); - // 开启debug调试 - props.setProperty("mail.debug", "false"); //false - // 发送服务器需要身份验证 - props.setProperty("mail.smtp.auth", "true"); - // 设置邮件服务器主机名 - props.setProperty("mail.host", "smtp.partner.outlook.cn"); - props.setProperty("mail.smtp.host", "smtp.partner.outlook.cn"); - // 发送邮件协议名称 - props.setProperty("mail.transport.protocol", "smtp"); - props.setProperty("mail.smtp.port", "587"); - props.put("mail.smtp.starttls.enable", "true"); - - OhMyEmail.config(props); - } - - - public static void sendEmail(EmailBO emailBO) { - OhMyEmail.config(OhMyEmail.SMTP_ENT_QQ(false), COMP_EMAIL, COMP_PW); - - if (StringUtils.isBlank(emailBO.getToAddress()) || StringUtils.isBlank(emailBO.getSubject())) { - return; - } - - initEmailCfg(); - - String fromNickName = emailBO.getFromNickName(); - if (StringUtils.isBlank(fromNickName)) { - fromNickName = SENDER_NAME; - } - - try { - OhMyEmail ohMyEmail = OhMyEmail.subject(emailBO.getSubject()) - .from(fromNickName) - .to(emailBO.getToAddress()); - - if (StringUtils.isNotBlank(emailBO.getCcAddress())) { - ohMyEmail.cc(emailBO.getCcAddress()); - } - List files = emailBO.getAttachFiles(); - if(files != null && !files.isEmpty()){ - for(File file:files){ - ohMyEmail.attach(file); - } - } - - ohMyEmail.html(emailBO.getContent()); - ohMyEmail.send(); - } catch (Exception e) { - log.error("EmailUtils.sendEmailAttachFiles error ", e); - } - - } - -} diff --git a/src/main/java/common/util/EnhanceFileUtils.java b/src/main/java/common/util/EnhanceFileUtils.java deleted file mode 100644 index f6ba577e..00000000 --- a/src/main/java/common/util/EnhanceFileUtils.java +++ /dev/null @@ -1,25 +0,0 @@ -package common.util; - -import lombok.extern.slf4j.Slf4j; - -import java.io.File; -import java.io.IOException; - -/** - * Created by nibnait on 2022/03/02 - */ -@Slf4j -public class EnhanceFileUtils { - - public static File createIfNecessary(String fileName) throws IOException { - File file = new File(fileName); - if (!file.exists()) { - file.getParentFile().mkdirs(); - if (!file.createNewFile()) { - log.error("FileUtils createIfNecessary failed"); - } - } - return file; - } - -} diff --git a/src/main/java/common/util/ExampleUtils.java b/src/main/java/common/util/ExampleUtils.java deleted file mode 100644 index a6b7319b..00000000 --- a/src/main/java/common/util/ExampleUtils.java +++ /dev/null @@ -1,23 +0,0 @@ -package common.util; - -import org.apache.commons.collections4.CollectionUtils; - -import java.util.List; -import java.util.function.UnaryOperator; - -/** - * Created by nibnait on 2021/10/10 - */ -public class ExampleUtils { - - public static void addQueryCriteria(T criteria, Object object, UnaryOperator unaryOperator) { - if (object == null) { - return; - } - if (List.class.isAssignableFrom(object.getClass()) && CollectionUtils.isEmpty((List) object)) { - return; - } - unaryOperator.apply(criteria); - } - -} diff --git a/src/main/java/common/util/ExcelReadUtils.java b/src/main/java/common/util/ExcelReadUtils.java deleted file mode 100644 index a0b97959..00000000 --- a/src/main/java/common/util/ExcelReadUtils.java +++ /dev/null @@ -1,126 +0,0 @@ -package common.util; - -import com.alibaba.excel.EasyExcelFactory; -import com.alibaba.excel.context.AnalysisContext; -import com.alibaba.excel.event.AnalysisEventListener; -import com.google.common.collect.Lists; -import lombok.extern.slf4j.Slf4j; -import org.apache.poi.hssf.usermodel.HSSFWorkbook; -import org.apache.poi.poifs.filesystem.POIFSFileSystem; -import org.apache.poi.ss.usermodel.*; -import org.apache.poi.xssf.usermodel.XSSFWorkbook; - -import java.io.IOException; -import java.io.InputStream; -import java.math.BigDecimal; -import java.util.ArrayList; -import java.util.Date; -import java.util.List; - -/** - * Created by nibnait on 2022/03/10 - */ -@Slf4j -public class ExcelReadUtils { - - /** - * 使用 easyexcel 读 - */ - public static List read(InputStream in, Class clazz) { - List list = new ArrayList<>(); - - EasyExcelFactory.read(in, clazz, new AnalysisEventListener() { - @Override - public void invoke(T data, AnalysisContext context) { - list.add(data); - } - - @Override - public void doAfterAllAnalysed(AnalysisContext context) {} - }).sheet().doRead(); - - return list; - } - - /** - * 将文件的 inputStream 转成 workbook - */ - public static Workbook convert2Workbook(InputStream inputStream) { - Workbook workbook = null; - try { - workbook = new XSSFWorkbook(inputStream); // 解析2007版本 - } catch (Exception ex) { - try { - POIFSFileSystem pfs = new POIFSFileSystem(inputStream); // 解析2003版本 - workbook = new HSSFWorkbook(pfs); - } catch (IOException e) { - log.error("ExcelReadUtils convert2Workbook error ", e); - } - } finally { - try { - inputStream.close(); - } catch (IOException e) { - log.error("ExcelReadUtils convert2Workbook inputStream.close error ", e); - } - } - return workbook; - } - - /** - * 读第1行数据 - */ - public static List getTitle(Sheet sheet) { - return getRowData(sheet, 0); - } - - /** - * 读指定行号 - * - * @param sheet excel - * @param rowNo 行号 - */ - public static List getRowData(Sheet sheet, int rowNo) { - List rowData = Lists.newArrayList(); - - Row row = sheet.getRow(rowNo); - if (row == null) { - return rowData; - } - - // 读取列 - for (int cellNum = 0; cellNum < row.getLastCellNum(); cellNum++) { - Cell cell = row.getCell(cellNum); - - if (cell == null) { - rowData.add(""); - continue; - } - - // 匹配列的数据类型 - String cellValue = ""; - CellType cellType = cell.getCellTypeEnum(); - switch (cellType) { - case STRING: - cellValue = cell.getStringCellValue(); - break; - case BOOLEAN: - cellValue = String.valueOf(cell.getBooleanCellValue()); - break; - case NUMERIC: - if (DateUtil.isCellDateFormatted(cell)) { - Date date = cell.getDateCellValue(); - cellValue = DateTimeConvertUtils.date2String(date); - } else { - cellValue = BigDecimal.valueOf(cell.getNumericCellValue()).stripTrailingZeros().toString(); - } - break; - default: - break; - } - rowData.add(cellValue); - } - - return rowData; - } - -} diff --git a/src/main/java/common/util/List2MapFactory.java b/src/main/java/common/util/List2MapFactory.java deleted file mode 100644 index b3972244..00000000 --- a/src/main/java/common/util/List2MapFactory.java +++ /dev/null @@ -1,89 +0,0 @@ -package common.util; - -import com.google.common.collect.Maps; -import common.exception.ClientViewException; -import org.apache.commons.collections4.CollectionUtils; -import org.slf4j.helpers.MessageFormatter; - -import java.util.List; -import java.util.Map; -import java.util.Optional; -import java.util.function.Function; -import java.util.stream.Collectors; - -public class List2MapFactory { - - public static final String DOUBLE_INDEX_FORMAT = "{}_{}"; - public static final String TRIPLE_INDEX_FORMAT = "{}_{}_{}"; - - public class BizMap { - - private Map map; - - public BizMap(Map map) { - this.map = map; - } - - public BizMap() { - this.map = Maps.newHashMap(); - } - - public V get(K key, String format, Object... args) { - V v = map.get(key); - if (v == null) { - throw new ClientViewException(DataUtils.format(format, args)); - } - return v; - } - - public V get(K key) { - return map.get(key); - } - - public Optional getOptional(K key) { - return Optional.ofNullable(map.get(key)); - } - - public Map getMap() { - return map; - } - } - - - public BizMap transferMap(List list, Function function) { - if (CollectionUtils.isEmpty(list)) { - return new BizMap<>(); - } - return new BizMap<>(list.stream().collect(Collectors.toMap(function, Function.identity(), (o1, o2) -> o1))); - } - - public BizMap> transferMapGroupBy(List list, Function function) { - if (CollectionUtils.isEmpty(list)) { - return new BizMap<>(); - } - return new BizMap<>(list.stream().collect(Collectors.groupingBy(function))); - } - - public BizMap transferDoubleIndexMap(List list, Function fun1, Function fun2) { - if (CollectionUtils.isEmpty(list)) { - return new BizMap<>(); - } - return new BizMap<>(list.stream().collect(Collectors.toMap(o -> doubleIndexFormat(fun1.apply(o), fun2.apply(o)), Function.identity(), (o1, o2) -> o1))); - } - - public String doubleIndexFormat(Object... args) { - return MessageFormatter.arrayFormat(DOUBLE_INDEX_FORMAT, args).getMessage(); - } - - public BizMap transferTripleIndexMap(List list, Function fun1, Function fun2, Function fun3) { - if (CollectionUtils.isEmpty(list)) { - return new BizMap<>(); - } - return new BizMap<>(list.stream().collect(Collectors.toMap(o -> tripleIndexFormat(fun1.apply(o), fun2.apply(o), fun3.apply(o)), Function.identity(), (o1, o2) -> o1))); - } - - public String tripleIndexFormat(Object... args) { - return MessageFormatter.arrayFormat(TRIPLE_INDEX_FORMAT, args).getMessage(); - } - -} diff --git a/src/main/java/common/util/LocalDateTimeUtil.java b/src/main/java/common/util/LocalDateTimeUtil.java deleted file mode 100644 index c3ef0429..00000000 --- a/src/main/java/common/util/LocalDateTimeUtil.java +++ /dev/null @@ -1,33 +0,0 @@ -package common.util; - -import lombok.Data; - -import java.time.LocalDateTime; -import java.time.temporal.ChronoUnit; - -public class LocalDateTimeUtil { - - public static void main(String[] args) { - LocalDateTime start = LocalDateTime.now().minusMinutes(1); - start = LocalDateTime.now().plusDays(1); - LocalDateTime end = LocalDateTime.now(); - TimeBetween timeBetween = calcTimeBetween(start, end); - System.out.println(timeBetween.toString()); - } - - @Data - static class TimeBetween{ - private long days; - private long seconds; - } - - /** - * 计算时间差 - */ - public static TimeBetween calcTimeBetween(LocalDateTime start, LocalDateTime end) { - TimeBetween timeBetween = new TimeBetween(); - timeBetween.setDays(ChronoUnit.DAYS.between(start, end)); - timeBetween.setSeconds(ChronoUnit.SECONDS.between(start, end)); - return timeBetween; - } -} diff --git a/src/main/java/common/util/NumberUtils.java b/src/main/java/common/util/NumberUtils.java deleted file mode 100644 index baf1deed..00000000 --- a/src/main/java/common/util/NumberUtils.java +++ /dev/null @@ -1,254 +0,0 @@ -package common.util; - -import java.math.BigDecimal; -import java.math.RoundingMode; - -public class NumberUtils { - - private static final BigDecimal BIGDECIMAL_ONE_HUNDRED = BigDecimal.valueOf(100); - // 除法,scale 保留2位小数 - private static final int SCALE = 2; - // 除法,一律向下取整(舍弃scale后面的数字) - private static final RoundingMode ROUNDING_MODE = RoundingMode.DOWN; - - /** - * 非空 && >=0 - */ - public static boolean notNullAndGreaterThanOrEqualsZero(Integer o) { - if (o == null) { - return false; - } - return greaterThanOrEqualsZero(o); - } - - public static boolean notNullAndGreaterThanOrEqualsZero(Long o) { - if (o == null) { - return false; - } - return greaterThanOrEqualsZero(o); - } - - public static boolean notNullAndGreaterThanOrEqualsZero(BigDecimal o) { - if (o == null) { - return false; - } - return greaterThanOrEqualsZero(o); - } - - /** - * 非空 && >0 - */ - public static boolean notNullAndGreaterThanZero(Integer o) { - return !nullOrLessThanOrEqualsZero(o); - } - - public static boolean notNullAndGreaterThanZero(Long o) { - return !nullOrLessThanOrEqualsZero(o); - } - - public static boolean notNullAndGreaterThanZero(BigDecimal o) { - return !nullOrLessThanOrEqualsZero(o); - } - - /** - * 空 || <= 0 - */ - public static boolean nullOrLessThanOrEqualsZero(Integer o) { - if (o == null) { - return true; - } - return lessThanOrEqualsZero(o); - } - - public static boolean nullOrLessThanOrEqualsZero(Long o) { - if (o == null) { - return true; - } - return lessThanOrEqualsZero(o); - } - - public static boolean nullOrLessThanOrEqualsZero(BigDecimal o) { - if (o == null) { - return true; - } - return lessThanOrEqualsZero(o); - } - - public static boolean nullOrLessThanZero(Integer o) { - if (o == null) { - return true; - } - return lessThanZero(o); - } - - public static boolean nullOrLessThanZero(Long o) { - if (o == null) { - return true; - } - return lessThanZero(o); - } - - public static boolean nullOrLessThanZero(BigDecimal o) { - if (o == null) { - return true; - } - return lessThanZero(o); - } - - /******** 基础方法:<= 0 ******/ - - public static boolean lessThanOrEqualsZero(Integer o) { - return lessThanOrEquals(o, 0); - } - - public static boolean lessThanOrEqualsZero(Long o) { - return lessThanOrEquals(o, 0L); - } - - public static boolean lessThanOrEqualsZero(BigDecimal o) { - return lessThanOrEquals(o, BigDecimal.ZERO); - } - - public static > boolean lessThanOrEquals(T o, T num) { - if (num == null || o == null) { - return false; - } - return o.compareTo(num) <= 0; - } - - /******** 基础方法:< 0 ******/ - public static boolean lessThanZero(Integer o) { - return lessThan(o, 0); - } - - public static boolean lessThanZero(Long o) { - return lessThan(o, 0L); - } - - public static boolean lessThanZero(BigDecimal o) { - return lessThan(o, BigDecimal.ZERO); - } - - public static > boolean lessThan(T o, T num) { - if (num == null || o == null) { - return false; - } - return o.compareTo(num) < 0; - } - - /******** 基础方法:>= 0 ******/ - - public static boolean greaterThanOrEqualsZero(Integer o) { - return greaterThanOrEquals(o, 0); - } - - public static boolean greaterThanOrEqualsZero(Long o) { - return greaterThanOrEquals(o, 0L); - } - - public static boolean greaterThanOrEqualsZero(BigDecimal o) { - return greaterThanOrEquals(o, BigDecimal.ZERO); - } - - public static > boolean greaterThanOrEquals(T o, T num) { - if (num == null || o == null) { - return false; - } - return o.compareTo(num) >= 0; - } - - /******** 基础方法:> 0 ******/ - - public static boolean greaterThanZero(Integer o) { - return greaterThan(o, 0); - } - - public static boolean greaterThanZero(Long o) { - return greaterThan(o, 0L); - } - - public static boolean greaterThanZero(BigDecimal o) { - return greaterThan(o, BigDecimal.ZERO); - } - - public static > boolean greaterThan(T o, T num) { - if (num == null || o == null) { - return false; - } - return o.compareTo(num) > 0; - } - - /****************** 价格 单位转换 *******************/ - /** - * 单位分 -> 单位元 - */ - public static BigDecimal getPriceYuan(Integer fen) { - return greaterThanZero(fen) - ? divide100(fen) - : null; - } - - public static BigDecimal getPriceYuan(Long fen) { - return greaterThanZero(fen) - ? divide100(fen) - : null; - } - - public static BigDecimal getPriceYuan(BigDecimal fen) { - return greaterThanZero(fen) - ? divide100(fen) - : null; - } - - /******** 基础方法:÷ 100 ******/ - public static BigDecimal divide100(Integer fen) { - return divide(BigDecimal.valueOf(fen), BIGDECIMAL_ONE_HUNDRED); - } - - public static BigDecimal divide100(Long fen) { - return divide(BigDecimal.valueOf(fen), BIGDECIMAL_ONE_HUNDRED); - } - - public static BigDecimal divide100(BigDecimal fen) { - return divide(fen, BIGDECIMAL_ONE_HUNDRED); - } - - /** - * 除法,默认保留两位小数,向下取整 - * - * @param dividend 被除数 - * @param divisor 除数 - * @return 商 - */ - public static BigDecimal divide(BigDecimal dividend, BigDecimal divisor) { - if (dividend == null || divisor == null) { - return BigDecimal.ZERO; - } - return dividend.divide(divisor, SCALE, ROUNDING_MODE); - } - - public static BigDecimal divide(BigDecimal dividend, BigDecimal divisor, int scale, RoundingMode roundingMode) { - if (dividend == null || divisor == null) { - return BigDecimal.ZERO; - } - return dividend.divide(divisor, scale, roundingMode); - } - - /** - * 单位分 -> 单位元 - */ - public static BigDecimal getPriceFen(BigDecimal yuan) { - if (yuan == null) { - return null; - } - return yuan.multiply(BIGDECIMAL_ONE_HUNDRED); - } - - public static BigDecimal getPriceFen(Double yuan) { - if (yuan == null) { - return null; - } - return BigDecimal.valueOf(yuan).multiply(BIGDECIMAL_ONE_HUNDRED); - } - -} diff --git a/src/main/java/common/util/PageUtils.java b/src/main/java/common/util/PageUtils.java deleted file mode 100644 index 44eed3bd..00000000 --- a/src/main/java/common/util/PageUtils.java +++ /dev/null @@ -1,55 +0,0 @@ -package common.util; - -import com.github.pagehelper.PageInfo; -import com.google.common.collect.Lists; -import org.springframework.util.CollectionUtils; - -import java.util.List; -import java.util.function.Function; -import java.util.function.IntFunction; -import java.util.stream.Collectors; - -public class PageUtils { - - public static PageInfo convertPageInfo(PageInfo sourcePage, List list) { - if (sourcePage == null) { - return new PageInfo<>(); - } - - PageInfo newPageInfo = CommonBeanUtil.copyProperties(sourcePage, PageInfo::new); - if (newPageInfo == null || CollectionUtils.isEmpty(list)) { - newPageInfo.setList(list); - return newPageInfo; - } - newPageInfo.setList(list); - return newPageInfo; - } - - public static PageInfo convertPageInfo(PageInfo sourcePage, Function function) { - if (sourcePage == null) { - return new PageInfo<>(); - } - - PageInfo newPageInfo = CommonBeanUtil.copyProperties(sourcePage, PageInfo::new); - if (newPageInfo == null || sourcePage.getList() == null) { - return newPageInfo; - } - newPageInfo.setList(sourcePage.getList().stream().map(function).collect(Collectors.toList())); - return newPageInfo; - } - - public static List getPageInfoTotalList(IntFunction> intFunction) { - List list = Lists.newArrayList(); - int pageNum = 1; - PageInfo pageInfo; - do { - pageInfo = intFunction.apply(pageNum++); - if (pageInfo == null) { - break; - } - list.addAll(pageInfo.getList()); - } while (pageInfo.isHasNextPage()); - return list; - } - -} diff --git a/src/main/java/common/util/RetryUtils.java b/src/main/java/common/util/RetryUtils.java deleted file mode 100644 index 3b926e08..00000000 --- a/src/main/java/common/util/RetryUtils.java +++ /dev/null @@ -1,76 +0,0 @@ -package common.util; - -import common.bo.BaseResponse; -import common.enums.ErrorCode; -import lombok.extern.slf4j.Slf4j; - -import java.util.function.Supplier; - -/** - * Created by nibnait on 2021/10/21 - */ -@Slf4j -public class RetryUtils { - - /** - * 无返回值的重试 num 次 - * @param runnable 一个匿名函数:() -> xx.xxx - * @param num 重试次数 - * @param errorMsg 报错信息 - * @param sleepMillis 每次重试间隔的毫秒数 - */ - public static void retryRunnable(Runnable runnable, int num, String errorMsg, Long sleepMillis) { - boolean isFail = true; - int count = 0; - while (isFail && count < num) { - isFail = false; - try { - runnable.run(); - } catch (Exception e) { - isFail = true; - count ++ ; - log.error(DataUtils.format("第 {} 次重试 {}", count, errorMsg), e); - try { - Thread.sleep(sleepMillis); - } catch (InterruptedException ex) { - log.warn(ex.getMessage(), ex); - Thread.currentThread().interrupt(); - } - } - } - } - - /** - * 带返回值的重试 num 次 - * @param supplier 一个匿名函数:() -> xx.xxx - * @param num 重试次数 - * @param errorMsg 报错信息 - * @param sleepMillis 每次重试间隔的毫秒数 - */ - public static BaseResponse retrySupplier(Supplier supplier, int num, String errorMsg, Long sleepMillis) { - boolean isFail = true; - int count = 0; - while (isFail && count < num) { - isFail = false; - try { - BaseResponse baseResponse = supplier.get(); - if (ErrorCode.SUCCESS.getCode().equals(baseResponse.code)) { - return baseResponse; - } - } catch (Exception e) { - isFail = true; - count ++ ; - log.error(DataUtils.format("第 {} 次重试 {}", count, errorMsg), e); - try { - Thread.sleep(sleepMillis); - } catch (InterruptedException ex) { - log.warn(ex.getMessage(), ex); - Thread.currentThread().interrupt(); - } - } - } - - return new BaseResponse(ErrorCode.SERVICE_ERROR, errorMsg); - } - -} diff --git a/src/main/java/common/util/StringUtil.java b/src/main/java/common/util/StringUtil.java deleted file mode 100644 index 82101514..00000000 --- a/src/main/java/common/util/StringUtil.java +++ /dev/null @@ -1,27 +0,0 @@ -package common.util; - -/** - * Created by nibnait on 2016/9/11. - */ -public class StringUtil { - - public static final String EMPTY_STRING = ""; - - public static boolean isNotBlank(String str) { - return !isBlank(str); - } - - public static boolean isBlank(String str) { - int strLen; - if (str == null || (strLen = str.length()) == 0) { - return true; - } - for (int i = 0; i < strLen; i++) { - if ((Character.isWhitespace(str.charAt(i)) == false)) { - return false; - } - } - return true; - } - -} diff --git a/src/main/java/common/util/compare/CompareUtils.java b/src/main/java/common/util/compare/CompareUtils.java deleted file mode 100644 index 8c290f77..00000000 --- a/src/main/java/common/util/compare/CompareUtils.java +++ /dev/null @@ -1,143 +0,0 @@ -package common.util.compare; - -import com.alibaba.fastjson.JSON; -import com.google.common.collect.Sets; -import common.bo.compare.CompareBO; -import common.bo.compare.CompareResultDTO; -import common.datastruct.ListNode; -import lombok.extern.slf4j.Slf4j; - -import java.util.Set; - -/** - * Created by nibnait on 2020/11/20 - */ -@Slf4j -public class CompareUtils { - - /** - * 对比两个链表 - */ - public static boolean compareListNode(ListNode left, ListNode right) { - while (left != null && right != null && left.val == right.val) { - left = left.next; - right = right.next; - } - return left == right; - } - - /** - * 对比两个对象的所有字段是否一致 - * @param actual 实际值 - * @param expect 期望值 - */ - public static boolean match(T actual, T expect) { - return matchExcudeFields(actual, expect, Sets.newHashSet()); - } - - /** - * 对比两个对象的所有字段是否一致,排除某些字段 - * @param actual 实际值 - * @param expect 期望值 - * @param excludeFields 排除的字段 list - */ - public static boolean matchExcudeFields(T actual, T expect, Set excludeFields) { - CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); - compareBO.setExcludeFields(excludeFields); - - CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); - if (!compareResultDTO.isMatch()) { - log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); - } - return compareResultDTO.isMatch(); - } - - /** - * 仅对比两个对象中 focusFields list 字段是否一致 - * @param actual 实际值 - * @param expect 期望值 - * @param focusFields 想要对比的字段 list - */ - public static boolean matchFocusFields(T actual, T expect, Set focusFields) { - CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); - compareBO.setFocusFields(focusFields); - - CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); - if (!compareResultDTO.isMatch()) { - log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); - } - return compareResultDTO.isMatch(); - } - - /** - * 对比两个 PageInfo对象 的所有字段是否一致 - * @param actual 实际值 - * @param expect 期望值 - */ - public static boolean matchPage(T actual, T expect) { - return matchPageExculdeFields(actual, expect, Sets.newHashSet()); - } - - /** - * 对比两个 PageInfo对象 的所有字段是否一致,排除某些字段 - * @param actual 实际值 - * @param expect 期望值 - * @param excludeFields 排除的字段 list - */ - public static boolean matchPageExculdeFields(T actual, T expect, Set excludeFields) { - CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); - compareBO.setOptimizations(Sets.newHashSet(CompareBO.OptimizationType.PAGE_HELPER)); - compareBO.setExcludeFields(excludeFields); - - CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); - if (!compareResultDTO.isMatch()) { - log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); - } - return compareResultDTO.isMatch(); - } - - /** - * 仅对比两个 PageInfo对象 中 focusFields list 字段是否一致 - * @param actual 实际值 - * @param expect 期望值 - * @param focusFields 想要对比的字段 list - */ - public static boolean matchPageFocusFields(T actual, T expect, Set focusFields) { - CompareBO compareBO = CompareBO.newNoOptimizeCompareBO(); - compareBO.setOptimizations(Sets.newHashSet(CompareBO.OptimizationType.PAGE_HELPER)); - compareBO.setFocusFields(focusFields); - - CompareResultDTO compareResultDTO = JsonUtils.diffStr(JSON.toJSONString(actual), JSON.toJSONString(expect), compareBO); - if (!compareResultDTO.isMatch()) { - log.info("差异字段: {}", JSON.toJSONString(compareResultDTO)); - } - return compareResultDTO.isMatch(); - } - - /** - * 直接调用两个 object 的 .equals 方法,对比 - * @param actualObj 实际值 - * @param expectObj 期望值 - */ - public static boolean matchObject(Object actualObj, Object expectObj) { - - if ((expectObj == null && actualObj != null) || (expectObj != null && actualObj == null)) { - return false; - } - - if (expectObj == null) { - return true; - } - - if (!expectObj.getClass().equals(actualObj.getClass())) { - return false; - } - - if (expectObj instanceof Number && expectObj instanceof Comparable) { - return ((Comparable) expectObj).compareTo(actualObj) == 0; - } - - return expectObj.equals(actualObj); - } - -} diff --git a/src/main/java/common/util/compare/JacksonUtils.java b/src/main/java/common/util/compare/JacksonUtils.java deleted file mode 100644 index af9bb61c..00000000 --- a/src/main/java/common/util/compare/JacksonUtils.java +++ /dev/null @@ -1,219 +0,0 @@ -package common.util.compare; - -import com.alibaba.fastjson.JSON; -import com.fasterxml.jackson.annotation.JsonInclude; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.ArrayNode; -import com.fasterxml.jackson.databind.node.ObjectNode; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.lang3.StringUtils; - -import java.math.BigDecimal; -import java.text.SimpleDateFormat; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -@Slf4j -public class JacksonUtils { - - private static final ObjectMapper MAPPER = new ObjectMapper(); - private static final String SEPARATOR = ":"; - public static final String ARRAY_SIGN = "*"; - public static final String MINUS_SIGN = "\"-\""; - public static final String ARRAY_SIGN_REPLACE = "#"; - public static final String PLACEHOLDER_SIGN = "{}"; - private static final String BLANK_REPLACE = " "; - private static final String EMPTY = ""; - - static { - SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); - MAPPER.setDateFormat(dateFormat); - MAPPER.setSerializationInclusion(JsonInclude.Include.NON_NULL); - } - - public static String replace(String json, String path, Object value) { - if (StringUtils.isBlank(path)) { - return json; - } - // 使用 # 替换, 否则会因为正则导致替换失败 - path = path.replace(ARRAY_SIGN, ARRAY_SIGN_REPLACE); - // 判断是否多级路径 - int lastNodeIndex = path.lastIndexOf(SEPARATOR); - if (lastNodeIndex == -1) { - return replaceField(json, path, path, value); - } - // 判断是否需要循环解析 - if (!path.contains(ARRAY_SIGN_REPLACE)) { - return replaceField(json, path, path.substring(lastNodeIndex + 1), value); - } - // 需要循环解析, 递归 - String prePath = path.substring(0, getArraySignIndex(path)); - String prePathValue = focus(json, prePath); - JsonNode prePathJsonNode = json2Node(prePathValue); - for (int i = 0; i < prePathJsonNode.size(); i++) { - json = replace(json, path.replaceFirst(ARRAY_SIGN_REPLACE, i + ""), value); - } - return json; - } - - private static int getArraySignIndex(String path) { - return path.indexOf(ARRAY_SIGN_REPLACE) == 0 ? 0 : path.indexOf(ARRAY_SIGN_REPLACE) - 1; - } - - public static String focus(String json, String path) { - if (StringUtils.isBlank(path)) { - return json; - } - // 使用 # 替换, 否则会因为正则导致替换失败 - path = path.replace(ARRAY_SIGN, ARRAY_SIGN_REPLACE); - // 判断是否多级路径 - int lastNodeIndex = path.lastIndexOf(SEPARATOR); - if (lastNodeIndex == -1) { - return focusField(json, path); - } - // 判断是否需要循环解析 - if (!path.contains(ARRAY_SIGN_REPLACE)) { - return focusField(json, path); - } - // 需要循环解析, 递归 - List result = new ArrayList<>(); - String prePath = path.substring(0, getArraySignIndex(path)); - String prePathValue = focus(json, prePath); - JsonNode prePathJsonNode = json2Node(prePathValue); - - if (prePathJsonNode == null) { - return MINUS_SIGN; - } - - for (int i = 0; i < prePathJsonNode.size(); i++) { - String str = focus(json, path.replaceFirst(ARRAY_SIGN_REPLACE, i + "")); - result.add(str); - } - Object[] objects = result.toArray(); - // 自然排序 - Arrays.sort(objects); - return JSON.toJSONString(objects).replaceAll(BLANK_REPLACE, EMPTY); - } - - private static String focusField(String json, String path) { - JsonNode jsonNode = json2Node(json); - String[] paths = path.split(SEPARATOR); - for (String fieldName : paths) { - if (jsonNode == null) { - continue; - } - if (jsonNode.isArray()) { - jsonNode = jsonNode.get(Integer.parseInt(fieldName)); - } else { - jsonNode = jsonNode.get(fieldName); - } - } - return node2Json(jsonNode); - } - - private static String replaceField(String json, String path, String key, Object value) { - if (StringUtils.isBlank(path)) { - return json; - } - JsonNode jsonNode = json2Node(json); - JsonNode temp = jsonNode; - String[] paths = path.split(SEPARATOR); - for (String fieldName : paths) { - if (temp == null) { - continue; - } - // 找到 key - if (fieldName.equals(key)) { - if (temp.isArray()) { - JsonNode removeJsonNode = ((ArrayNode) temp).remove(Integer.parseInt(fieldName)); - if (value != null && removeJsonNode != null) { - Class valueClazz = value.getClass(); - if (valueClazz == String.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (String) value); - } else if (valueClazz == Boolean.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Boolean) value); - } else if (valueClazz == Short.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Short) value); - } else if (valueClazz == Integer.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Integer) value); - } else if (valueClazz == Double.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Double) value); - } else if (valueClazz == Long.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Long) value); - } else if (valueClazz == Float.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (Float) value); - } else if (valueClazz == BigDecimal.class) { - ((ArrayNode) temp).insert(Integer.parseInt(fieldName), (BigDecimal) value); - } - } - } else { - JsonNode removeJsonNode = ((ObjectNode) temp).remove(fieldName); - if (value != null && removeJsonNode != null) { - Class valueClazz = value.getClass(); - if (valueClazz == String.class) { - ((ObjectNode) temp).put(fieldName, (String) value); - } else if (valueClazz == Boolean.class) { - ((ObjectNode) temp).put(fieldName, (Boolean) value); - } else if (valueClazz == Short.class) { - ((ObjectNode) temp).put(fieldName, (Short) value); - } else if (valueClazz == Integer.class) { - ((ObjectNode) temp).put(fieldName, (Integer) value); - } else if (valueClazz == Double.class) { - ((ObjectNode) temp).put(fieldName, (Double) value); - } else if (valueClazz == Long.class) { - ((ObjectNode) temp).put(fieldName, (Long) value); - } else if (valueClazz == Float.class) { - ((ObjectNode) temp).put(fieldName, (Float) value); - } else if (valueClazz == BigDecimal.class) { - ((ObjectNode) temp).put(fieldName, (BigDecimal) value); - } - } - } - continue; - } - if (temp.isArray()) { - temp = temp.get(Integer.parseInt(fieldName)); - } else { - temp = temp.get(fieldName); - } - } - return node2Json(jsonNode); - } - - private static String node2Json(JsonNode jsonNode) { - if (jsonNode == null) { - return null; - } - String value = jsonNode.asText(); - if (StringUtils.isBlank(value)) { - value = jsonNode.toString(); - } - return value; - } - - private static JsonNode json2Node(String json) { - if (StringUtils.isBlank(json)) { - return null; - } - - JsonNode tempNode = null; - try { - tempNode = MAPPER.readTree(json); - } catch (Exception e) { - log.error("json2Node error json {}", json, e); - } - return tempNode; - } - - public static boolean isJson(String json) { - try { - MAPPER.readTree(json); - } catch (Exception e) { - return false; - } - return true; - } - -} diff --git a/src/main/java/common/util/compare/JsonUtils.java b/src/main/java/common/util/compare/JsonUtils.java deleted file mode 100644 index 6c7c1db8..00000000 --- a/src/main/java/common/util/compare/JsonUtils.java +++ /dev/null @@ -1,242 +0,0 @@ -package common.util.compare; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; -import com.alibaba.fastjson.serializer.SerializerFeature; -import com.google.common.collect.Lists; -import com.json.comparison.JsonCompare; -import com.json.comparison.JsonComparisonResult; -import com.json.comparison.comprator.model.api.FieldComparison; -import common.bo.compare.CompareBO; -import common.bo.compare.CompareResultDTO; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; -import org.apache.commons.lang3.StringUtils; -import org.slf4j.helpers.MessageFormatter; - -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Set; -import java.util.stream.Collectors; - -@Slf4j -public class JsonUtils { - - public static CompareResultDTO diffJsonObject(JSONObject actualObject, JSONObject expectObject, Set focusFields) { - CompareResultDTO compareResultDTO = new CompareResultDTO(); - if (CollectionUtils.isEmpty(focusFields)) { - compareResultDTO.setMatch(true); - return compareResultDTO; - } - - List modifiedFields = Lists.newArrayList(); - for (String key : focusFields) { - String actual = actualObject.getString(key); - String expect = expectObject.getString(key); - if (!CompareUtils.matchObject(actual, expect)) { - addModifyFields(key, actual, expect, modifiedFields); - } - } - - compareResultDTO.setMatch(CollectionUtils.isEmpty(modifiedFields)); - compareResultDTO.setModifiedFields(modifiedFields); - return compareResultDTO; - } - - private static void addModifyFields(String key, String actual, String expect, List modifiedFields) { - CompareResultDTO.FieldComparison comparison = new CompareResultDTO.FieldComparison(); - comparison.setField(key); - comparison.setExpected(expect); - comparison.setActual(actual); - - modifiedFields.add(comparison); - } - - public static CompareResultDTO diffStr(String actualStr, String expectStr, CompareBO compareBO) { - // 判断是不是标准 json, 是 json 则不转, 否则会发生转义 - if (!JacksonUtils.isJson(actualStr)) { - try { - actualStr = JSON.toJSONString(JSON.parseObject(actualStr), SerializerFeature.WriteMapNullValue); - } catch (Exception e) { - // ignore - } - } - if (!JacksonUtils.isJson(expectStr)) { - try { - expectStr = JSON.toJSONString(JSON.parseObject(expectStr), SerializerFeature.WriteMapNullValue); - } catch (Exception e) { - // ignore - } - } - return diffStr0(actualStr, expectStr, compareBO); - } - - private static CompareResultDTO diffStr0(String actualStr, String expectStr, CompareBO compareBO) { - CompareResultDTO compareResultDTO = new CompareResultDTO(); - compareResultDTO.setMatch(true); - - // 如果不是 json 数据, 直接当成字符串匹配 - if (!JacksonUtils.isJson(actualStr) || !JacksonUtils.isJson(expectStr)) { - compareResultDTO.setMatch(actualStr.equals(expectStr)); - } - Set optimizations = compareBO.getOptimizations(); - Set focusFields = compareBO.getFocusFields(); - Set excludeFields = compareBO.getExcludeFields(); - // 1. 系统默认优化项: 如果开启了则添加到聚焦字段 - for (CompareBO.OptimizationType optimization : optimizations) { - // 如果是分页插件, 则只关注 data:list 数据内容 - if (optimization == CompareBO.OptimizationType.PAGE_HELPER) { - // 判断是否满足条件, 以是否包含 navigatePages、pageSize 为标准 - if (expectStr.contains("navigatePages") && expectStr.contains("pageSize")) { - focusFields.add("list"); - } - } - } - // 2. 排除字段: 如果有先把指定字段移除 - if (excludeFields.size() > 0) { - for (String excludeField : excludeFields) { - actualStr = JacksonUtils.replace(actualStr, excludeField, null); - expectStr = JacksonUtils.replace(expectStr, excludeField, null); - } - } - // 3. 无聚焦字段: 直接匹配字符串 - if (focusFields.size() <= 0) { - return jsonEqual(actualStr, expectStr, compareBO); - } - // 4. 有聚焦字段: 取出依次比较 - ArrayList modifiedFields = Lists.newArrayList(); - ArrayList missingFields = Lists.newArrayList(); - ArrayList newFields = Lists.newArrayList(); - for (String focusField : focusFields) { - String actualValue = JacksonUtils.focus(actualStr, focusField); - String expectValue = JacksonUtils.focus(expectStr, focusField); - - compareBO.setCurrentField(focusField); - CompareResultDTO currentFieldCompareResult = jsonEqual(actualValue, expectValue, compareBO); - - if (!currentFieldCompareResult.isMatch()) { - compareResultDTO.setMatch(false); - } - modifiedFields.addAll(currentFieldCompareResult.getModifiedFields()); - missingFields.addAll(currentFieldCompareResult.getMissingFields()); - newFields.addAll(currentFieldCompareResult.getNewFields()); - } - // 所有聚焦字段比较完后, 直接返回 true - compareResultDTO.setModifiedFields(modifiedFields); - compareResultDTO.setMissingFields(missingFields); - compareResultDTO.setNewFields(newFields); - - return compareResultDTO; - } - - public static CompareResultDTO jsonEqual(String actual, String expect, CompareBO compareBO) { - // 5. 先用 json 判断是否相等 - JsonComparisonResult comparisonResult = compare(actual, expect, compareBO); - - CompareResultDTO compareResultDTO = new CompareResultDTO(false); - if (comparisonResult == null) { - return compareResultDTO; - } - - compareResultDTO.setMatch(comparisonResult.isMatch()); - compareResultDTO.setModifiedFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getModifiedFields())); - compareResultDTO.setMissingFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getMissingFields())); - compareResultDTO.setNewFields(getFieldComparisonList(compareBO.getCurrentField(), comparisonResult.getNewFields())); - - // 如果全部比对成功, 直接返回 true - if (comparisonResult.isMatch()) { - compareResultDTO.setMatch(true); - } - // 6. 如果有修改字段, 直接返回失败 - if (CollectionUtils.isNotEmpty(comparisonResult.getModifiedFields())) { - compareResultDTO.setMatch(false); - return compareResultDTO; - } - // 7. 程序走到这里, 表明有两种情况, 一种是新增了字段, 一种是丢失了字段, 所以需要判断是否开启了忽略功能 - // 7.1 如果全部开启, 直接返回 true - if (compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_NEW_FIELDS) && - compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_MISSING_FIELDS)) { - compareResultDTO.setMatch(true); - } - // 7.2 只开启忽略新增字段, 那么只需要判断是否有丢失字段即可 - else if (compareBO.getOptimizations().contains(CompareBO.OptimizationType.IGNORE_NEW_FIELDS)) { - compareResultDTO.setMatch(CollectionUtils.isEmpty(comparisonResult.getMissingFields())); - } - // 7.3 只开启忽略丢失字段, 那么只需要判断新增字段即可 - else { - compareResultDTO.setMatch(CollectionUtils.isEmpty(comparisonResult.getNewFields())); - } - - return compareResultDTO; - } - - private static JsonComparisonResult compare(String actual, String expect, CompareBO compareBO) { - JsonComparisonResult comparisonResult = null; - try { - comparisonResult = JsonCompare.builder().build().compare(expect, actual); - } catch (Exception e) { - log.error("JsonUtils.jsonEqual error", e); - } - - if (comparisonResult == null || !comparisonResult.isMatch()) { - log.info("JsonUtils.jsonEqual false compareBO:{}", JSON.toJSONString(compareBO)); - log.info("JsonUtils.jsonEqual false actual:{}", actual); - log.info("JsonUtils.jsonEqual false expect:{}", expect); - } - return comparisonResult; - } - - private static List getFieldComparisonList(String currentField, Collection modifiedFieldList) { - return modifiedFieldList.stream() - .map(comparison -> convertToFieldComparison(currentField, comparison)) - .collect(Collectors.toList()); - } - - private static CompareResultDTO.FieldComparison convertToFieldComparison(String currentField, FieldComparison comparison) { - CompareResultDTO.FieldComparison fieldComparison = new CompareResultDTO.FieldComparison(); - - try { - Integer[] indexArray = getIndexArray(comparison.getField()); - currentField = currentField.replace(JacksonUtils.ARRAY_SIGN, JacksonUtils.PLACEHOLDER_SIGN); - fieldComparison.setField(MessageFormatter.arrayFormat(currentField, indexArray).getMessage()); - } catch (Exception e) { - if (StringUtils.isBlank(currentField)) { - currentField = comparison.getField(); - } - if ("list".equals(currentField)) { - currentField = currentField + comparison.getField(); - } - fieldComparison.setField(currentField); - } - - fieldComparison.setExpected(comparison.getExpected()); - fieldComparison.setActual(comparison.getActual()); - return fieldComparison; - } - - private static Integer[] getIndexArray(String field) { - JSONArray jsonArray; - try { - jsonArray = JSON.parseArray(field); - Integer[] indexArray = new Integer[jsonArray.size()]; - for (int i = 0; i < jsonArray.size(); i++) { - indexArray[i] = (int) jsonArray.get(i); - } - return indexArray; - } catch (Exception e) { - field = "[" + field + "]"; - jsonArray = JSON.parseArray(field); - Integer[] indexArray = new Integer[jsonArray.size()]; - for (int i = 0; i < jsonArray.size(); i++) { - JSONArray arr = (JSONArray) jsonArray.get(i); - indexArray[i] = (int) arr.get(0); - } - return indexArray; - } - - - } - -} diff --git a/src/main/java/common/util/validate/validator/OperatorValidator.java b/src/main/java/common/util/validate/validator/OperatorValidator.java index 82cbe87c..bd77eb58 100644 --- a/src/main/java/common/util/validate/validator/OperatorValidator.java +++ b/src/main/java/common/util/validate/validator/OperatorValidator.java @@ -1,10 +1,10 @@ package common.util.validate.validator; -import common.exception.ClientViewException; import common.model.Person; -import common.util.StringUtil; import common.util.validate.Validator; import common.util.validate.context.ValidateContext; +import io.github.nibnait.common.exception.ClientViewException; +import org.apache.commons.lang3.StringUtils; /** * Created by nibnait on 2021/08/22 @@ -22,7 +22,7 @@ public class OperatorValidator implements Validator { */ @Override public void validate(ValidateContext context, Person person) { - if (StringUtil.isBlank(person.getName())) { + if (StringUtils.isBlank(person.getName())) { throw new ClientViewException("用户名 不能为空"); } } diff --git "a/src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/JavaExcelFullGCTest.java" "b/src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/JavaExcelFullGCTest.java" deleted file mode 100644 index 4fa6fe96..00000000 --- "a/src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/JavaExcelFullGCTest.java" +++ /dev/null @@ -1,48 +0,0 @@ -package org.tianbin.jvm.GC优化; - -import jxl.Workbook; -import jxl.WorkbookSettings; -import jxl.write.Label; -import jxl.write.WritableSheet; -import jxl.write.WritableWorkbook; -import jxl.write.WriteException; - -import java.io.File; -import java.io.IOException; - -/** - * - * -Xmx512m -Xms512m -Xmn256m -XX:+PrintGCDetails -XX:+PrintGCDateStamps -XX:+UseG1GC --verbose:gc --Xloggc:/Users/nibnait/Desktop/Jxl_FGC_Test_gc.log -XX:+HeapDumpOnOutOfMemoryError - - - */ -public class JavaExcelFullGCTest { - - public static void main(String[] args) throws IOException, WriteException { - for (int i = 0; i < 10; i++) { - excelGen(); - } - } - - private static void excelGen() throws IOException, WriteException { - WritableWorkbook book = null; - WritableSheet sheet; - try { - WorkbookSettings settings = new WorkbookSettings(); - settings.setGCDisabled(true); - -// book = Workbook.createWorkbook(new File("/Users/nibnait/Desktop/test.xls"), settings); - book = Workbook.createWorkbook(new File("/Users/nibnait/Desktop/test.xls")); - sheet = book.createSheet("PageNo.1", 0); - Label label = new Label(0, 0, "公众号:【阿飞的博客】"); - sheet.addCell(label); - book.write(); - } catch (Exception e) { - e.printStackTrace(); - } finally { - book.close(); - } - } -} \ No newline at end of file diff --git "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.class" "b/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.class" deleted file mode 100644 index 72d46dedc19b73ae7a85350f5311a7737e2a561b..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 literal 456 zcmZutJ5K^Z5dN0e!FdRR_%_kP1T4J9N{o%hil_;O{th-|$vw>7LEa zp;3cBz~A91zrr|o1hsIBnc43#vpa8J&#wU1u^=OX@f0%1CNUu+hrEPI2?d74rm%#! z#Skr)Y7DV$yTKVU6=CtcwyAUHP}2=UVjg!r2DxgtojTtY0hX@VT4RTs_F7BpXbL1G zB}^%p#tcJYL@xQ=>p{Q&aeD4|uO!SWn8Q57hV3*}PiU4dEVb1!)w-d%u0b8SqYh4P z{kzNer?b!A%h2v$+^D0D4B23yYG_td-Pc>ZPA~fdRgYbdoAf2SO+=v*iiNEnIKuL( zp2Ib>%#i;FW{{2okztXqI5dV+$R(_1xm3e4;SQNSRTNuRenHsGwz0 jOoU(%$9|+Mp%qBoBa(|gAoeSli6VleGFcR=BS?P(io|c6 diff --git a/src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java b/src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java index b833d58a..1dc95048 100644 --- a/src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java +++ b/src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java @@ -1,7 +1,7 @@ package org.tianbin.redis.RateLimiter; import com.google.common.io.ByteStreams; -import common.util.StringUtil; +import io.github.nibnait.common.constants.CommonConstants; import org.tianbin.java.IO.classpath.ResourcesReaderUtil; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; @@ -106,7 +106,7 @@ private static String readScript() { e.printStackTrace(); } - return StringUtil.EMPTY_STRING; + return CommonConstants.EMPTY_STRING; } public static RedisRateLimiter create(String key, double qps, JedisPool jedisPool) { diff --git a/src/main/test/common/util/DataUtilsTest.java b/src/main/test/common/util/DataUtilsTest.java deleted file mode 100644 index bf9ea070..00000000 --- a/src/main/test/common/util/DataUtilsTest.java +++ /dev/null @@ -1,23 +0,0 @@ -package common.util; - -import com.google.common.collect.Lists; -import lombok.extern.slf4j.Slf4j; -import org.junit.Test; - -import java.util.List; - -/** - * Created by nibnait on 2022/03/29 - */ -@Slf4j -public class DataUtilsTest { - - @Test - public void difference() { - List list1 = Lists.newArrayList(1); - List list2 = Lists.newArrayList(0); - - System.out.println(DataUtils.difference(list1, list2)); - } - -} diff --git a/src/main/test/common/util/ExcelReadUtilsTest.java b/src/main/test/common/util/ExcelReadUtilsTest.java deleted file mode 100644 index 26317b8b..00000000 --- a/src/main/test/common/util/ExcelReadUtilsTest.java +++ /dev/null @@ -1,59 +0,0 @@ -package common.util; - -import lombok.Data; -import org.apache.poi.ss.usermodel.Sheet; -import org.apache.poi.ss.usermodel.Workbook; -import org.junit.Test; - -import java.io.FileInputStream; -import java.io.FileNotFoundException; -import java.util.List; - -/** - * Created by nibnait on 2022/03/10 - */ -public class ExcelReadUtilsTest { - - @Data - public static class NFT { - private String sourceAddress; - private String linkId; - private Integer stock; - private String specKey1; - private String specKey2; - private String specKey3; - } - - @Test - public void testReadByModule() throws FileNotFoundException { - // 获取文件流 - String path = "/Users/nibnait/Desktop/"; - FileInputStream inputStream = new FileInputStream(path + "nft.xlsx"); - - List read = ExcelReadUtils.read(inputStream, NFT.class); - System.out.println(DataUtils.toJsonStringArray(read)); - } - - @Test - public void testReadByWorkbook() throws FileNotFoundException { - // 获取文件流 - String path = "/Users/nibnait/Desktop/"; - FileInputStream inputStream = new FileInputStream(path + "nft.xlsx"); - - Workbook workbook = ExcelReadUtils.convert2Workbook(inputStream); - - // 获取标题内容 - Sheet sheet = workbook.getSheetAt(0); - List title = ExcelReadUtils.getTitle(sheet); - System.out.println(title); - - // 获取表中的内容 - int rowCount = sheet.getPhysicalNumberOfRows(); - for (int rowNum = 1; rowNum < rowCount; rowNum++) { - List rowData = ExcelReadUtils.getRowData(sheet, rowNum); - System.out.println(rowData); - } - } - - -} diff --git a/src/main/test/org/tianbin/excel/ExcelGen.java b/src/main/test/org/tianbin/excel/ExcelGen.java index c761d44f..97d8db4f 100644 --- a/src/main/test/org/tianbin/excel/ExcelGen.java +++ b/src/main/test/org/tianbin/excel/ExcelGen.java @@ -1,10 +1,11 @@ package org.tianbin.excel; import com.google.common.collect.Lists; -import common.bo.EmailBO; -import common.util.EmailUtils; -import common.bo.excel.SheetBO; -import common.bo.excel.WorkBookBO; +import io.github.nibnait.common.bo.email.EmailAccount; +import io.github.nibnait.common.bo.email.EmailBO; +import io.github.nibnait.common.bo.excel.SheetBO; +import io.github.nibnait.common.bo.excel.WorkBookBO; +import io.github.nibnait.common.utils.EmailUtils; import org.apache.commons.lang3.StringUtils; import org.junit.Test; @@ -26,7 +27,7 @@ public void test() { public static final String DATE_TIME_FORMAT = "yyyyMMdd-HHmm"; @Test - public void excelGen() { + public void excelGen() throws Exception { String targetFileName = String.format(DELAY_DELIVERY_REPORT_FILE_NAME, getNowDateTime(DATE_TIME_FORMAT)); @@ -36,16 +37,11 @@ public void excelGen() { xiegehanshu(sheet); - File delay_delivery_report = workBookBO.writeToFile(targetFileName); + File delay_delivery_report = workBookBO.writeToDefaultLocalPath(targetFileName); System.out.println(delay_delivery_report.getName()); - EmailUtils.sendEmail(new EmailBO("111", - "tianbin@bilibili.com", - null, - "222", - getEmailContent(), - Lists.newArrayList(delay_delivery_report))); + EmailUtils.sendEmailThrowException(new EmailAccount(), new EmailBO()); } public static String getNowDateTime(String dateFormat) { diff --git a/src/main/test/org/tianbin/excel/ParseJson.java b/src/main/test/org/tianbin/excel/ParseJson.java index 0ca4901f..bf5ce761 100644 --- a/src/main/test/org/tianbin/excel/ParseJson.java +++ b/src/main/test/org/tianbin/excel/ParseJson.java @@ -1,12 +1,10 @@ package org.tianbin.excel; import com.google.common.collect.Lists; -import common.bo.excel.SheetBO; -import common.bo.excel.WorkBookBO; -import common.util.DataUtils; -import jxl.write.WriteException; +import io.github.nibnait.common.bo.excel.SheetBO; +import io.github.nibnait.common.bo.excel.WorkBookBO; +import io.github.nibnait.common.utils.DataUtils; -import java.io.IOException; import java.util.List; /** @@ -14,7 +12,7 @@ */ public class ParseJson { - public static void main(String[] args) throws IOException, WriteException { + public static void main(String[] args) { String str = "[{\"skuId\":1000098016,\"stock\":239,\"frozenStock\":583,\"outStock\":0,\"isolateStock\":0,\"purchaseStock\":840,\"warehouseIds\":\"\",\"warnStock\":1,\"frozenUndeliveryStock\":0,\"ctime\":1623744663000,\"mtime\":1642147764000,\"boxNum\":0,\"onsaleBoxNum\":0}]"; List stockDTOS = DataUtils.parseArray(str, StockDTO.class); @@ -25,7 +23,7 @@ public static void main(String[] args) throws IOException, WriteException { sheetBO.appendRow(Lists.newArrayList(stockDTO.getSkuId()+"", stockDTO.getStock()+"")); } - workBookBO.writeToFile("stock"); + workBookBO.writeToDefaultLocalPath("stock"); } diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" index 0bde56c5..eb86ead5 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" +++ "b/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" @@ -3,7 +3,7 @@ import common.model.Person; import common.model.PersonDTO; import common.util.CommonBeanUtil; -import common.util.DateTimeCalcUtils; +import io.github.nibnait.common.utils.date.DateTimeCalcUtils; import org.junit.Test; import java.time.LocalDateTime; diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 6d3a8505..3d774962 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -6,7 +6,7 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; import common.model.Person; -import common.util.DataUtils; +import io.github.nibnait.common.utils.DataUtils; import org.junit.Test; import java.util.ArrayList; diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" index c5fa5dd7..ebd0ad4a 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" +++ "b/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" @@ -2,9 +2,8 @@ import com.google.common.collect.Lists; import com.google.common.collect.Sets; -import common.util.StringUtil; -import junit.framework.TestCase; import org.apache.commons.collections4.CollectionUtils; +import org.apache.commons.lang3.StringUtils; import org.junit.Test; import java.util.ArrayList; @@ -34,7 +33,7 @@ public void testCase() { private static boolean isRestaurantInGray(long restaurantId, String grayRestaurantIdStr) { - if (StringUtil.isBlank(grayRestaurantIdStr)) { + if (StringUtils.isBlank(grayRestaurantIdStr)) { return false; } diff --git a/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java b/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java index 9ada109d..a291706e 100644 --- a/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java +++ b/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java @@ -1,6 +1,6 @@ package org.tianbin.redis.RateLimiter; -import common.util.DateTimeUtil; +import io.github.nibnait.common.utils.date.DateTimeConvertUtils; import org.junit.After; import org.junit.BeforeClass; import org.junit.Test; @@ -41,7 +41,7 @@ public void acquire() throws Exception { pool.execute(() -> { double acquire = limiter.acquire(1); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTime2String(LocalDateTime.now())); + + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); }); } @@ -56,7 +56,7 @@ public void tryAcquire() throws Exception { pool.execute(() -> { boolean acquire = limiter.tryAcquire(); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTime2String(LocalDateTime.now())); + + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); }); } @@ -71,7 +71,7 @@ public void tryAcquireTimeout() throws Exception { pool.execute(() -> { boolean acquire = limiter.tryAcquire(1000L, TimeUnit.MILLISECONDS); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTime2String(LocalDateTime.now())); + + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); }); } @@ -93,7 +93,7 @@ public void batchAcquireLazy() throws Exception { pool.execute(() -> { double acquire = redisRateLimiter.acquireLazy(10); System.out.println(index + " \t" + acquire + " \t" - + DateTimeUtil.localDateTime2String(LocalDateTime.now())); + + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); }); } From 53cd54ef3b606f201c7fde6158787bfdda2baece Mon Sep 17 00:00:00 2001 From: tianbin Date: Tue, 21 Jun 2022 08:56:43 +0800 Subject: [PATCH 11/36] =?UTF-8?q?=E5=B7=A6=E7=A8=8B=E4=BA=91=E7=AE=97?= =?UTF-8?q?=E6=B3=95=E6=96=B0=E6=89=8B=E7=8F=AD=20day1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- README.md | 4 +- pom.xml | 5 ++ .../a_Sorting/a_Selection.java | 5 +- .../a_Sorting/b_Insertion.java | 3 +- .../algorithm_practice/a_Sorting/d_Merge.java | 3 +- .../algorithm_practice/algorithmzuo/README.md | 4 ++ .../algorithmzuo/a_primary/README.md | 2 + .../a_primary/class01/Code01_PrintBinary.java | 60 ++++++++++++++++++ .../class01/Code02_SumOfFactorial.java | 37 +++++++++++ .../class01/Code03_SelectionSort.java | 49 +++++++++++++++ .../a_primary/class01/Code04_BubbleSort.java | 49 +++++++++++++++ .../class01/Code05_InsertionSort.java | 49 +++++++++++++++ .../algorithmzuo/a_primary/class01/README.md | 63 +++++++++++++++++++ .../algorithmzuo/a_primary/class02/README.md | 15 +++++ .../algorithmzuo/a_primary/class03/README.md | 24 +++++++ .../algorithmzuo/a_primary/class04/README.md | 38 +++++++++++ .../algorithmzuo/a_primary/class05/README.md | 11 ++++ .../algorithmzuo/a_primary/class06/README.md | 27 ++++++++ .../algorithmzuo/a_primary/class07/README.md | 20 ++++++ .../algorithmzuo/a_primary/class08/README.md | 14 +++++ .../algorithmzuo/algorithm_basic/README.md | 2 + .../algorithm_basic/class01/README.md | 2 + .../algorithmzuo/for_great_offer/README.md | 2 + .../tianbin/design_pattern/Singleton.java | 2 +- .../tianbin/hessian/HessianDemo.java | 2 +- .../{org => cc}/tianbin/hessian/README.md | 0 .../Main.java" | 3 +- .../Student.java" | 2 +- .../java/{org => cc}/tianbin/java/IO/1.txt | 0 .../tianbin/java/IO/FileReaderTest.java | 2 +- .../tianbin/java/IO/classpath/Main.java | 4 +- .../IO/classpath/ResourcesReaderUtil.java | 2 +- .../tianbin/java/IO/classpath/RpcConfig.java | 2 +- .../{org => cc}/tianbin/java/proxy/README.md | 0 .../tianbin/java/proxy/cglib/Main.java | 2 +- .../tianbin/java/proxy/cglib/Person.java | 2 +- .../java/proxy/cglib/TargetInterceptor.java | 2 +- .../cglib/TargetMethodCallbackFilter.java | 2 +- .../java/proxy/cglib/TargetResultFixed.java | 2 +- .../lazyloader/ConcreteClassDispatcher.java | 2 +- .../lazyloader/ConcreteClassLazyLoader.java | 2 +- .../java/proxy/cglib/lazyloader/LazyBean.java | 2 +- .../proxy/cglib/lazyloader/PropertyBean.java | 2 +- .../tianbin/java/proxy/jdk/Calculator.java | 2 +- .../java/proxy/jdk/CalculatorImpl.java | 2 +- .../tianbin/java/proxy/jdk/HelloService.java | 2 +- .../java/proxy/jdk/HelloServiceImpl.java | 2 +- .../DynamicProxy.java" | 8 +-- .../Main.java" | 8 +-- .../handler/LogHandler.java" | 2 +- .../handler/MyInvocationHandler.java" | 2 +- .../HelloServiceProxy.java" | 4 +- .../Main.java" | 4 +- .../CompareUtil.java" | 2 +- .../java/\345\217\215\345\260\204/Main.java" | 2 +- .../BigDecimalTest.java" | 2 +- .../BooleanTest.java" | 2 +- .../ByteTest.java" | 2 +- .../DoubleTest.java" | 2 +- .../IntegerTest.java" | 7 ++- .../MathTest.java" | 2 +- .../StringTest.java" | 12 +++- ...1_\345\205\254\345\271\263\351\224\201.md" | 0 ...36\345\205\254\345\271\263\351\224\201.md" | 0 ...36\345\205\254\345\271\263\351\224\201.md" | 0 .../JUC/JUC_AQS/CountdownLatchExample.java" | 2 +- .../JUC/JUC_AQS/CyclicBarrierExample.java" | 2 +- .../JUC/JUC_AQS/README.md" | 0 .../JUC/JUC_AQS/SemaphoreExample.java" | 2 +- .../JUC/JUC_demo/BlockedQueue.java" | 2 +- .../JUC/JUC_demo/Cache.java" | 2 +- .../JUC/JUC_demo/DisruptorDemo.java" | 2 +- .../JUC/JUC_demo/ObjectPool.java" | 2 +- .../JUC/JUC_demo/Point.java" | 2 +- .../JUC/JUC_other/ForkJoinExample.java" | 2 +- .../JUC/JUC_other/FutureTaskExample.java" | 2 +- .../JUC/JUC_other/Main.java" | 2 +- .../JUC/JUC_other/ProducerConsumer.java" | 2 +- .../JUC/JUC_other/README.md" | 0 ...\345\217\257\350\247\201\346\200\247.java" | 2 +- .../java/\345\271\266\345\217\221/Main.java" | 2 +- .../threadpool/ExecutorsExceptionTest.java" | 2 +- ...\347\250\213\345\220\214\346\255\245.java" | 2 +- .../threadpool/a1_MyThreadPool.java" | 2 +- .../threadpool/a2_FutureTask.java" | 2 +- .../threadpool/b1_FutureTaskDemo.java" | 2 +- .../threadpool/b2_CompletableFutureDemo.java" | 2 +- .../b2_CompletableFutureDemo2.java" | 2 +- .../threadpool/b3_CompletionServiceDemo.java" | 2 +- .../threadpool/c1_FockJoinDemo.java" | 2 +- .../threadpool/c2_FockJoinDemo2.java" | 2 +- .../aThreadJoinDemo.java" | 2 +- .../bThreadMainJoinDemo.java" | 2 +- .../cThreadWaitNotifyDemo.java" | 2 +- .../dThreadAwaitSingalDemo.java" | 2 +- .../eSingleThreadPoolDemo.java" | 2 +- .../fCountDownLatchDemo.java" | 2 +- .../gCyclicBarrierDemo.java" | 2 +- .../CAS/AtomicIntegerExample.java" | 2 +- .../CAS/AtomicReferenceExample.java" | 2 +- .../README.md" | 0 .../reentrantLock/LockExample.java" | 2 +- .../reentrantLock/Main.java" | 2 +- .../AwaitSignalExample.java" | 2 +- .../JoinExample.java" | 2 +- .../Main.java" | 2 +- .../README.md" | 0 .../WaitNotifyExample.java" | 2 +- .../synchronize/Main.java" | 2 +- .../synchronize/SynchronizedExample.java" | 2 +- .../java/\345\274\202\345\270\270/Main.java" | 2 +- .../List\347\261\273.java" | 2 +- .../Map\347\261\273.java" | 2 +- .../tianbin/jvm/GCRoots/GCRootsTest01.java | 2 +- .../tianbin/jvm/GCRoots/GCRootsTest02.java | 2 +- .../tianbin/jvm/GCRoots/GCRootsTest03.java | 2 +- .../tianbin/jvm/GCRoots/GCRootsTest04.java | 2 +- .../{org => cc}/tianbin/jvm/GCRoots/README.md | 0 .../GC\344\274\230\345\214\226/HeapOOM.java" | 2 +- .../jvm/classloader/ClassLoaderDemo.java | 2 +- .../jvm/classloader/LoadStringDemo.java | 2 +- .../LoadDemo.java" | 2 +- .../Main.java" | 4 +- .../MyClassLoader.java" | 2 +- .../\345\274\225\347\224\250/Reference.java" | 2 +- .../java/{org => cc}/tianbin/netty/Main.java | 2 +- .../java/{org => cc}/tianbin/netty/README.md | 0 .../{org => cc}/tianbin/netty/http/App.java | 2 +- .../tianbin/netty/http/HttpServer.java | 2 +- .../tianbin/netty/http/ServerHandler.java | 2 +- .../tianbin/netty/http/ServerInitializer.java | 2 +- .../tianbin/netty/rpc/ClientApp.java | 10 +-- .../tianbin/netty/rpc/ServerApp.java | 10 +-- .../tianbin/netty/rpc/client/RPCClient.java | 8 +-- .../rpc/client/request/RPCException.java | 2 +- .../netty/rpc/client/request/RPCRequest.java | 2 +- .../netty/rpc/client/request/RPCResponse.java | 2 +- .../netty/rpc/client/request/RequestId.java | 2 +- .../rpc/client/request/ResponseRegistry.java | 2 +- .../netty/rpc/customHandler/ExpRequest.java | 2 +- .../rpc/customHandler/ExpRequestHandler.java | 6 +- .../netty/rpc/customHandler/ExpResponse.java | 2 +- .../rpc/customHandler/FibRequestHandler.java | 6 +- .../tianbin/netty/rpc/server/RPCServer.java | 8 +-- .../netty/rpc/server/ServerHandler.java | 10 +-- .../rpc/server/message/DefaultHandler.java | 2 +- .../rpc/server/message/IMessageHandler.java | 2 +- .../rpc/server/message/MessageHandlers.java | 2 +- .../rpc/server/message/MessageInput.java | 2 +- .../rpc/server/message/MessageOutput.java | 2 +- .../rpc/server/message/MessageRegistry.java | 2 +- .../netty/webSocket/client/ClientApp.java | 2 +- .../netty/webSocket/client/ClientHandler.java | 2 +- .../webSocket/client/ClientInitializer.java | 2 +- .../netty/webSocket/client/SocketClient.java | 2 +- .../netty/webSocket/server/ServerApp.java | 2 +- .../netty/webSocket/server/ServerHandler.java | 2 +- .../webSocket/server/ServerInitializer.java | 2 +- .../netty/webSocket/server/SocketServer.java | 2 +- .../HyperLogLog/HyperLogLogCounting.java | 2 +- .../HyperLogLog/HyperLogLogCountingDemo.java | 2 +- .../tianbin/redis/RateLimiter/README.md | 0 .../redis/RateLimiter/RedisRateLimiter.java | 4 +- src/main/java/common/util/CompareUtils.java | 27 ++++++++ src/main/java/common/util/SysRandom.java | 33 +++------- src/main/java/common/util/SystemUtil.java | 8 +++ src/main/test/{org => cc}/tianbin/Main.java | 2 +- .../{org => cc}/tianbin/excel/ExcelGen.java | 2 +- .../{org => cc}/tianbin/excel/ParseJson.java | 2 +- .../{org => cc}/tianbin/excel/StockDTO.java | 2 +- .../{org => cc}/tianbin/java/ObjectTest.java | 2 +- .../tianbin/java/OptionalTest.java | 2 +- .../tianbin/java/SwitchCaseTest.java | 2 +- .../CommonBeanUtilTest.java" | 2 +- ...\350\203\275\346\265\213\350\257\225.java" | 2 +- .../java/\345\217\215\345\260\204/README.md" | 0 .../ReflectTest.java" | 2 +- .../ListStreamTest.java" | 29 +++++++-- .../\351\233\206\345\220\210/ListTest.java" | 29 +++++++-- .../\351\233\206\345\220\210/MapTest.java" | 15 ++++- .../\351\233\206\345\220\210/SetTest.java" | 2 +- .../RateLimiter/RedisRateLimiterTest.java | 2 +- .../{org => cc}/tianbin/temp/DataGen.java | 2 +- .../tianbin/temp/JsonParseTest.java | 2 +- .../test/common/util/ExcelReadUtilsTest.java | 17 +++++ src/main/test/javalang/test/FinallyTest.java | 45 +++++++++++++ .../test/org/tianbin/excel/ExcelRead.java | 10 --- 187 files changed, 836 insertions(+), 229 deletions(-) create mode 100644 src/main/java/algorithm_practice/algorithmzuo/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/for_great_offer/README.md rename src/main/java/{org => cc}/tianbin/design_pattern/Singleton.java (78%) rename src/main/java/{org => cc}/tianbin/hessian/HessianDemo.java (98%) rename src/main/java/{org => cc}/tianbin/hessian/README.md (100%) rename "src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" => "src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" (97%) rename "src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" => "src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" (88%) rename src/main/java/{org => cc}/tianbin/java/IO/1.txt (100%) rename src/main/java/{org => cc}/tianbin/java/IO/FileReaderTest.java (99%) rename src/main/java/{org => cc}/tianbin/java/IO/classpath/Main.java (94%) rename src/main/java/{org => cc}/tianbin/java/IO/classpath/ResourcesReaderUtil.java (87%) rename src/main/java/{org => cc}/tianbin/java/IO/classpath/RpcConfig.java (79%) rename src/main/java/{org => cc}/tianbin/java/proxy/README.md (100%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/Main.java (99%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/Person.java (95%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/TargetInterceptor.java (96%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java (95%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/TargetResultFixed.java (94%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java (92%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java (95%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/lazyloader/LazyBean.java (97%) rename src/main/java/{org => cc}/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java (83%) rename src/main/java/{org => cc}/tianbin/java/proxy/jdk/Calculator.java (74%) rename src/main/java/{org => cc}/tianbin/java/proxy/jdk/CalculatorImpl.java (83%) rename src/main/java/{org => cc}/tianbin/java/proxy/jdk/HelloService.java (84%) rename src/main/java/{org => cc}/tianbin/java/proxy/jdk/HelloServiceImpl.java (91%) rename "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" => "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" (72%) rename "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" => "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" (91%) rename "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" => "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" (93%) rename "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" => "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" (94%) rename "src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" => "src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" (81%) rename "src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" => "src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" (72%) rename "src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" => "src/main/java/cc/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" (99%) rename "src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" => "src/main/java/cc/tianbin/java/\345\217\215\345\260\204/Main.java" (98%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" (97%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" (83%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" (83%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" (94%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" (90%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" (82%) rename "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" => "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" (76%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" (96%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" (96%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" (96%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" (95%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" (98%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" (98%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" (95%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" (96%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" (95%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" (99%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/Main.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" (96%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" (99%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" (92%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" (98%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" (98%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" (96%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" (98%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" (95%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" (91%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" (92%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" (94%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" (94%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" (79%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" (86%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" (93%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" (94%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" (85%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" (95%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" (100%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" (84%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" (97%) rename "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" => "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" (94%) rename "src/main/java/org/tianbin/java/\345\274\202\345\270\270/Main.java" => "src/main/java/cc/tianbin/java/\345\274\202\345\270\270/Main.java" (91%) rename "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" => "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" (93%) rename "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" => "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" (94%) rename src/main/java/{org => cc}/tianbin/jvm/GCRoots/GCRootsTest01.java (98%) rename src/main/java/{org => cc}/tianbin/jvm/GCRoots/GCRootsTest02.java (98%) rename src/main/java/{org => cc}/tianbin/jvm/GCRoots/GCRootsTest03.java (97%) rename src/main/java/{org => cc}/tianbin/jvm/GCRoots/GCRootsTest04.java (97%) rename src/main/java/{org => cc}/tianbin/jvm/GCRoots/README.md (100%) rename "src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" => "src/main/java/cc/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" (96%) rename src/main/java/{org => cc}/tianbin/jvm/classloader/ClassLoaderDemo.java (93%) rename src/main/java/{org => cc}/tianbin/jvm/classloader/LoadStringDemo.java (95%) rename "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" => "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" (72%) rename "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" => "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" (92%) rename "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" => "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" (95%) rename "src/main/java/org/tianbin/jvm/\345\274\225\347\224\250/Reference.java" => "src/main/java/cc/tianbin/jvm/\345\274\225\347\224\250/Reference.java" (98%) rename src/main/java/{org => cc}/tianbin/netty/Main.java (86%) rename src/main/java/{org => cc}/tianbin/netty/README.md (100%) rename src/main/java/{org => cc}/tianbin/netty/http/App.java (88%) rename src/main/java/{org => cc}/tianbin/netty/http/HttpServer.java (98%) rename src/main/java/{org => cc}/tianbin/netty/http/ServerHandler.java (99%) rename src/main/java/{org => cc}/tianbin/netty/http/ServerInitializer.java (95%) rename src/main/java/{org => cc}/tianbin/netty/rpc/ClientApp.java (83%) rename src/main/java/{org => cc}/tianbin/netty/rpc/ServerApp.java (58%) rename src/main/java/{org => cc}/tianbin/netty/rpc/client/RPCClient.java (94%) rename src/main/java/{org => cc}/tianbin/netty/rpc/client/request/RPCException.java (90%) rename src/main/java/{org => cc}/tianbin/netty/rpc/client/request/RPCRequest.java (84%) rename src/main/java/{org => cc}/tianbin/netty/rpc/client/request/RPCResponse.java (84%) rename src/main/java/{org => cc}/tianbin/netty/rpc/client/request/RequestId.java (81%) rename src/main/java/{org => cc}/tianbin/netty/rpc/client/request/ResponseRegistry.java (90%) rename src/main/java/{org => cc}/tianbin/netty/rpc/customHandler/ExpRequest.java (85%) rename src/main/java/{org => cc}/tianbin/netty/rpc/customHandler/ExpRequestHandler.java (79%) rename src/main/java/{org => cc}/tianbin/netty/rpc/customHandler/ExpResponse.java (86%) rename src/main/java/{org => cc}/tianbin/netty/rpc/customHandler/FibRequestHandler.java (80%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/RPCServer.java (94%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/ServerHandler.java (93%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/message/DefaultHandler.java (90%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/message/IMessageHandler.java (85%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/message/MessageHandlers.java (92%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/message/MessageInput.java (91%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/message/MessageOutput.java (83%) rename src/main/java/{org => cc}/tianbin/netty/rpc/server/message/MessageRegistry.java (89%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/client/ClientApp.java (77%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/client/ClientHandler.java (90%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/client/ClientInitializer.java (95%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/client/SocketClient.java (96%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/server/ServerApp.java (85%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/server/ServerHandler.java (98%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/server/ServerInitializer.java (95%) rename src/main/java/{org => cc}/tianbin/netty/webSocket/server/SocketServer.java (95%) rename src/main/java/{org => cc}/tianbin/redis/HyperLogLog/HyperLogLogCounting.java (98%) rename src/main/java/{org => cc}/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java (98%) rename src/main/java/{org => cc}/tianbin/redis/RateLimiter/README.md (100%) rename src/main/java/{org => cc}/tianbin/redis/RateLimiter/RedisRateLimiter.java (98%) rename src/main/test/{org => cc}/tianbin/Main.java (92%) rename src/main/test/{org => cc}/tianbin/excel/ExcelGen.java (98%) rename src/main/test/{org => cc}/tianbin/excel/ParseJson.java (97%) rename src/main/test/{org => cc}/tianbin/excel/StockDTO.java (97%) rename src/main/test/{org => cc}/tianbin/java/ObjectTest.java (91%) rename src/main/test/{org => cc}/tianbin/java/OptionalTest.java (92%) rename src/main/test/{org => cc}/tianbin/java/SwitchCaseTest.java (94%) rename "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" => "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" (98%) rename "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" => "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" (99%) rename "src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" => "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/README.md" (100%) rename "src/main/test/org/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" => "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" (97%) rename "src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" => "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" (54%) rename "src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" => "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListTest.java" (92%) rename "src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" => "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" (78%) rename "src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" => "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" (97%) rename src/main/test/{org => cc}/tianbin/redis/RateLimiter/RedisRateLimiterTest.java (98%) rename src/main/test/{org => cc}/tianbin/temp/DataGen.java (99%) rename src/main/test/{org => cc}/tianbin/temp/JsonParseTest.java (97%) create mode 100644 src/main/test/common/util/ExcelReadUtilsTest.java create mode 100644 src/main/test/javalang/test/FinallyTest.java delete mode 100644 src/main/test/org/tianbin/excel/ExcelRead.java diff --git a/README.md b/README.md index 892a5da0..dadec3cb 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ [数据结构](src/main/java/data_struct/README.md) # 操作系统 -[jvm](src/main/java/org/tianbin/jvm) +[jvm](src/main/java/cc/tianbin/jvm) # 网络编程 -[org.tianbin.netty](src/main/java/org/tianbin/netty/README.md) \ No newline at end of file +[org.tianbin.netty](src/main/java/cc/tianbin/netty/README.md) \ No newline at end of file diff --git a/pom.xml b/pom.xml index 05d041b9..303a5a6d 100644 --- a/pom.xml +++ b/pom.xml @@ -77,6 +77,11 @@ junit 4.13.2 + + org.slf4j + slf4j-simple + 1.7.36 + diff --git a/src/main/java/algorithm_practice/a_Sorting/a_Selection.java b/src/main/java/algorithm_practice/a_Sorting/a_Selection.java index 43e6b1b5..e8a057b6 100644 --- a/src/main/java/algorithm_practice/a_Sorting/a_Selection.java +++ b/src/main/java/algorithm_practice/a_Sorting/a_Selection.java @@ -15,11 +15,10 @@ */ public class a_Selection { public static void main(String[] args) { - int[] a = new int[10]; - a = SysRandom.random(a); + int[] a = SysRandom.randomArr(); SysOut.printArray(a); - a = Selection_Sort(a); + Selection_Sort(a); SysOut.printArray(a); } diff --git a/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java b/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java index 30c94883..fc805a3e 100644 --- a/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java +++ b/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java @@ -9,8 +9,7 @@ */ public class b_Insertion { public static void main(String[] args) { - int[] a = new int[10]; - a = SysRandom.random(a); + int[] a = SysRandom.randomArr(); SysOut.printArray(a); a = Insertion_Sort(a); diff --git a/src/main/java/algorithm_practice/a_Sorting/d_Merge.java b/src/main/java/algorithm_practice/a_Sorting/d_Merge.java index 471cf7c3..1e8ea0dc 100644 --- a/src/main/java/algorithm_practice/a_Sorting/d_Merge.java +++ b/src/main/java/algorithm_practice/a_Sorting/d_Merge.java @@ -10,8 +10,7 @@ public class d_Merge { public static void main(String[] args) { - int[] a = new int[7]; - a = SysRandom.random(a); + int[] a = SysRandom.randomArr(); SysOut.printArray(a); divide(a, 0, a.length - 1); diff --git a/src/main/java/algorithm_practice/algorithmzuo/README.md b/src/main/java/algorithm_practice/algorithmzuo/README.md new file mode 100644 index 00000000..e8df862d --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/README.md @@ -0,0 +1,4 @@ +# 跟着左神写算法 + + +笔记: \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md new file mode 100644 index 00000000..e7d95698 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md @@ -0,0 +1,2 @@ +# 新手班 + \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java new file mode 100644 index 00000000..657a0040 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java @@ -0,0 +1,60 @@ +package algorithm_practice.algorithmzuo.a_primary.class01; + +import common.util.SystemUtil; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.math.BigDecimal; + +/** + * Created by nibnait on 2022/06/20 + */ +@Slf4j +public class Code01_PrintBinary { + + @Test + public void testCase() { + + int num = 4; + print(num); + print(0); + + print(Integer.MAX_VALUE); + print(Integer.MIN_VALUE); + print(Integer.MIN_VALUE + 1); + print(Integer.MIN_VALUE + 2); + print(Integer.MIN_VALUE + 3); + print(Integer.MIN_VALUE + 4); + print(Integer.MIN_VALUE + 5); + + print(-1); + + print(BigDecimal.valueOf(Math.pow(2, 32)).intValue()); + print(BigDecimal.valueOf(Math.pow(2, 31)).intValue()); + print(BigDecimal.valueOf(Math.pow(2, 30)).intValue()); + + SystemUtil.printCuttingLine(); + + // 带符号右移 和 不带符号右移 + num = 1024; + print(num >> 1); + print(num >>> 1); + SystemUtil.printCuttingLine(); + + // 为什么负数的二进制要取反加1? + // 为了加法 正+正 与 正+负。。走一套逻辑。 + num = 5; + print(num); + print(-num); + print(~num + 1); + } + + private void print(int num) { + System.out.print(num + "\t"); + for (int i = 31; i >= 0; i--) { + System.out.print( (num & (1 << i)) == 0 ? "0" : "1"); + } + System.out.println(); + } + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java new file mode 100644 index 00000000..d6482de4 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java @@ -0,0 +1,37 @@ +package algorithm_practice.algorithmzuo.a_primary.class01; + +public class Code02_SumOfFactorial { + + public static long f1(int N) { + long ans = 0; + for (int i = 1; i <= N; i++) { + ans += factorial(i); + } + return ans; + } + + public static long factorial(int N) { + long ans = 1; + for (int i = 1; i <= N; i++) { + ans *= i; + } + return ans; + } + + public static long f2(int N) { + long ans = 0; + long cur = 1; + for (int i = 1; i <= N; i++) { + cur = cur * i; + ans += cur; + } + return ans; + } + + public static void main(String[] args) { + int N = 10; + System.out.println(f1(N)); + System.out.println(f2(N)); + } + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java new file mode 100644 index 00000000..e36ae15f --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java @@ -0,0 +1,49 @@ +package algorithm_practice.algorithmzuo.a_primary.class01; + +import common.util.CompareUtils; +import common.util.SysOut; +import common.util.SysRandom; +import common.util.SystemUtil; +import org.junit.Test; + +import static common.util.SwapUtil.swap; + +/** + * Created by nibnait on 2022/06/21 + */ +public class Code03_SelectionSort { + + @Test + public void testCase() { + for (int i = 0; i < 10; i++) { + int arr[] = SysRandom.randomArr(); + SysOut.printArray(arr); + int[] tmp = CompareUtils.copyArray(arr); + selectSort(arr); + SysOut.printArray(arr); + if (!CompareUtils.isSortAsc(arr)) { + System.out.println("!!!有问题:"); + SysOut.printArray(tmp); + } + + SystemUtil.printLiteCuttingLine(); + } + } + + private void selectSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + int length = arr.length; + for (int i = 0; i < length - 1; i++) { + int minValueIndex = i; + for (int j = i+1; j < length; j++) { + minValueIndex = arr[j] < arr[minValueIndex] ? j : minValueIndex; + } + swap(arr, i, minValueIndex); + } + + } + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java new file mode 100644 index 00000000..bf466253 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java @@ -0,0 +1,49 @@ +package algorithm_practice.algorithmzuo.a_primary.class01; + +import common.util.CompareUtils; +import common.util.SysOut; +import common.util.SysRandom; +import common.util.SystemUtil; +import org.junit.Test; + +import static common.util.SwapUtil.swap; + +/** + * Created by nibnait on 2022/06/21 + */ +public class Code04_BubbleSort { + + @Test + public void testCase() { + for (int i = 0; i < 10; i++) { + int arr[] = SysRandom.randomArr(); + SysOut.printArray(arr); + int[] tmp = CompareUtils.copyArray(arr); + bubbleSort(arr); + SysOut.printArray(arr); + if (!CompareUtils.isSortAsc(arr)) { + System.out.println("!!!有问题:"); + SysOut.printArray(tmp); + } + + SystemUtil.printLiteCuttingLine(); + } + } + + private void bubbleSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + int length = arr.length; + for (int end = length - 1; end > 0; end--) { + for (int i = 0; i < end; i++) { + if (arr[i] > arr[i + 1]) { + swap(arr, i, i + 1); + } + } + } + + } + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java new file mode 100644 index 00000000..f3861615 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java @@ -0,0 +1,49 @@ +package algorithm_practice.algorithmzuo.a_primary.class01; + +import common.util.CompareUtils; +import common.util.SysOut; +import common.util.SysRandom; +import common.util.SystemUtil; +import org.junit.Test; + +import static common.util.SwapUtil.swap; + +/** + * Created by nibnait on 2022/06/21 + */ +public class Code05_InsertionSort { + + @Test + public void testCase() { + for (int i = 0; i < 10; i++) { + int arr[] = SysRandom.randomArr(); + SysOut.printArray(arr); + int[] tmp = CompareUtils.copyArray(arr); + + insertSort(arr); + SysOut.printArray(arr); + if (!CompareUtils.isSortAsc(arr)) { + System.out.println("!!!有问题:"); + SysOut.printArray(tmp); + } + + SystemUtil.printLiteCuttingLine(); + } + } + + private void insertSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + int length = arr.length; + for (int end = 1; end < length; end++) { + int newNumIndex = end; + while (newNumIndex - 1 >= 0 && arr[newNumIndex - 1] > arr[newNumIndex]) { + swap(arr, newNumIndex - 1, newNumIndex); + newNumIndex--; + } + } + } + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md new file mode 100644 index 00000000..f28b9b54 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md @@ -0,0 +1,63 @@ +## 内容: +- 讲解二进制、位运算 +- 介绍什么是算法 +- 讲解冒泡、选择、插入排序 +## 题目: +### 实现打印一个整数的二进制 +```java +/** + * 无符号整数 + */ +public void print(int num) { + for(int i=31; i>=0; i--) { + System.out.print( num & (1< 0; end--) { + for (int i = 0; i < end; i++) { + if (arr[i] > arr[i + 1]) { + swap(arr, i, i + 1); + } + } +} +``` +### 实现插入排序 +打扑克 抓牌、码牌 +```java +for (int end = 1; end < length; end++) { + int newNumIndex = end; + while (newNumIndex - 1 >= 0 && arr[newNumIndex - 1] > arr[newNumIndex]) { + swap(arr, newNumIndex - 1, newNumIndex); + newNumIndex--; + } +} +``` diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md new file mode 100644 index 00000000..3f247bf7 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md @@ -0,0 +1,15 @@ +## 内容: +- 什么是数据结构、组成各种数据结构最基本的元件 +- 前缀和数组 +- 随机函数 +- 对数器的使用 +## 题目: +### 实现前缀和数组 + +### 如何用1~5的随机函数加工出1~7的随机函数 + +### 如何用a~b的随机函数加工出c~d的随机函数 + +### 展示对数器的使用 + +### 如何把不等概率随机函数变成等概率随机函数 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md new file mode 100644 index 00000000..de321050 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md @@ -0,0 +1,24 @@ +# 03 介绍二分法,介绍时间复杂度、动态数组、哈希表和有序表 + +## 内容: + - 二分法 + - 使用二分法解决不同的题目 + - 时间复杂度 + - 动态数组 + - 按值传递、按引用传递 + - 哈希表 + - 有序表 + +## 题目: + +### 有序数组中找到num + +### 有序数组中找到>=num最左的位置 + +### 有序数组中找到<=num最右的位置 + +### 局部最小值问题 + +### 哈希表使用的code讲解 + +### 有序表使用的code讲解 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md new file mode 100644 index 00000000..2de6cfba --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md @@ -0,0 +1,38 @@ +# 04 链表相关的简单面试题 + +## 内容: + - 单双链表的定义 + - 栈、队列 + - 双端队列 + +## 题目: + +### 反转单链表 + +### 反转双链表 + +### 用单链表实现队列 + +### 用单链表实现栈 + +### 用双链表实现双端队列 + +### K个节点的组内逆序调整问题: +给定一个单链表的头节点head,和一个正数k +实现k个节点的小组内部逆序,如果最后一组不够k个就不调整 +例子: +调整前:1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8,k = 3 +调整后:3 -> 2 -> 1 -> 6 -> 5 -> 4 -> 7 -> 8 + +### 两个链表相加问题 +给定两个链表的头节点head1和head2, +认为从左到右是某个数字从低位到高位,返回相加之后的链表 +例子 4 -> 3 -> 6 2 -> 5 -> 3 +返回 6 -> 8 -> 9 +解释 634 + 352 = 986 + +### 两个有序链表的合并 +给定两个有序链表的头节点head1和head2, +返回合并之后的大链表,要求依然有序 +例子 1 -> 3 -> 3 -> 5 -> 7 2 -> 2 -> 3 -> 3-> 7 +返回 1 -> 2 -> 2 -> 3 -> 3 -> 3 -> 3 -> 5 -> 7 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md new file mode 100644 index 00000000..8cce247d --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md @@ -0,0 +1,11 @@ +# 05 位图、位运算实现加减乘除 + +## 内容: + - 位图 + - 位运算使用的进一步学习:实现加减乘除 + +## 题目: + +### 现场写位图的code、讲解 + +## 位运算的加减乘除 \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md new file mode 100644 index 00000000..a2327112 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md @@ -0,0 +1,27 @@ +# 06 比较器、优先级队列、二叉树 + +## 内容: + - 比较器 + - 优先级队列 + - 二叉树的基本遍历 + - 二叉树的递归套路 + +## 题目: + +### 合并多个有序链表 +Leetcode原题,https://leetcode.com/problems/merge-k-sorted-lists + +### 判断两颗树是否结构相同 +Leetcode原题,https://leetcode.com/problems/same-tree + +### 判断一棵树是否是镜面树 +Leetcode原题,https://leetcode.com/problems/symmetric-tree + +### 返回一棵树的最大深度 +Leetcode原题,https://leetcode.com/problems/maximum-depth-of-binary-tree + +### 用先序数组和中序数组重建一棵树 +Leetcode原题,https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal + +### 用code展示比较器的使用 +二叉树先序、中序、后序遍历的代码实现、介绍递归序 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md new file mode 100644 index 00000000..2912366d --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md @@ -0,0 +1,20 @@ +# 07 继续二叉树的很多题目 + +## 内容: + - 进一步讲解二叉树题目,来熟悉二叉树 + +## 题目: + +### 二叉树按层遍历并收集节点 +Leetcode原题,https://leetcode.com/problems/binary-tree-level-order-traversal-ii + +### 判断是否是平衡搜索二叉树 +Leetcode原题,https://leetcode.com/problems/balanced-binary-tree + +### 在二叉树上能否组成路径和 +Leetcode原题,https://leetcode.com/problems/path-sum + +### 在二叉树上收集所有达标的路径和 +Leetcode原题,https://leetcode.com/problems/path-sum-ii + +### 判断二叉树是否是搜索二叉树 \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md new file mode 100644 index 00000000..7efeae43 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md @@ -0,0 +1,14 @@ +# 08 介绍归并排序和快速排序 + +## 内容: + - 讲解一个位运算的题目 + - 归并排序 + - 快速排序 + +## 题目: + +### 不要用任何比较判断,返回两个数中较大的数 + +### 归并排序的递归实现和非递归实现 + +### 快速排序的递归实现和非递归实现 \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/README.md b/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/README.md new file mode 100644 index 00000000..371d9071 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/README.md @@ -0,0 +1,2 @@ +# 体系学习班 + diff --git a/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md b/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md new file mode 100644 index 00000000..a9bd7fde --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md @@ -0,0 +1,2 @@ +# + diff --git a/src/main/java/algorithm_practice/algorithmzuo/for_great_offer/README.md b/src/main/java/algorithm_practice/algorithmzuo/for_great_offer/README.md new file mode 100644 index 00000000..604da471 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/for_great_offer/README.md @@ -0,0 +1,2 @@ +# 刷题班 + diff --git a/src/main/java/org/tianbin/design_pattern/Singleton.java b/src/main/java/cc/tianbin/design_pattern/Singleton.java similarity index 78% rename from src/main/java/org/tianbin/design_pattern/Singleton.java rename to src/main/java/cc/tianbin/design_pattern/Singleton.java index 25b56f6a..9c188c71 100644 --- a/src/main/java/org/tianbin/design_pattern/Singleton.java +++ b/src/main/java/cc/tianbin/design_pattern/Singleton.java @@ -1,4 +1,4 @@ -package org.tianbin.design_pattern; +package cc.tianbin.design_pattern; /* 单例模式 diff --git a/src/main/java/org/tianbin/hessian/HessianDemo.java b/src/main/java/cc/tianbin/hessian/HessianDemo.java similarity index 98% rename from src/main/java/org/tianbin/hessian/HessianDemo.java rename to src/main/java/cc/tianbin/hessian/HessianDemo.java index 60dc7401..409d8418 100644 --- a/src/main/java/org/tianbin/hessian/HessianDemo.java +++ b/src/main/java/cc/tianbin/hessian/HessianDemo.java @@ -1,4 +1,4 @@ -package org.tianbin.hessian; +package cc.tianbin.hessian; import com.caucho.hessian.io.Hessian2Input; import com.caucho.hessian.io.Hessian2Output; diff --git a/src/main/java/org/tianbin/hessian/README.md b/src/main/java/cc/tianbin/hessian/README.md similarity index 100% rename from src/main/java/org/tianbin/hessian/README.md rename to src/main/java/cc/tianbin/hessian/README.md diff --git "a/src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" "b/src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" similarity index 97% rename from "src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" rename to "src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" index 9cd0d33b..70488fe8 100644 --- "a/src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" +++ "b/src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" @@ -1,6 +1,5 @@ -package org.tianbin.hessian.序列化结果对比; +package cc.tianbin.hessian.序列化结果对比; -import com.alibaba.fastjson.JSON; import com.caucho.hessian.io.Hessian2Input; import com.caucho.hessian.io.Hessian2Output; import com.caucho.hessian.io.HessianInput; diff --git "a/src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" "b/src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" similarity index 88% rename from "src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" rename to "src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" index a0694a2f..12c7f857 100644 --- "a/src/main/java/org/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" +++ "b/src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" @@ -1,4 +1,4 @@ -package org.tianbin.hessian.序列化结果对比; +package cc.tianbin.hessian.序列化结果对比; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/org/tianbin/java/IO/1.txt b/src/main/java/cc/tianbin/java/IO/1.txt similarity index 100% rename from src/main/java/org/tianbin/java/IO/1.txt rename to src/main/java/cc/tianbin/java/IO/1.txt diff --git a/src/main/java/org/tianbin/java/IO/FileReaderTest.java b/src/main/java/cc/tianbin/java/IO/FileReaderTest.java similarity index 99% rename from src/main/java/org/tianbin/java/IO/FileReaderTest.java rename to src/main/java/cc/tianbin/java/IO/FileReaderTest.java index 19e3d566..8be81414 100644 --- a/src/main/java/org/tianbin/java/IO/FileReaderTest.java +++ b/src/main/java/cc/tianbin/java/IO/FileReaderTest.java @@ -1,4 +1,4 @@ -package org.tianbin.java.IO; +package cc.tianbin.java.IO; import com.alibaba.fastjson.JSON; import junit.framework.TestCase; diff --git a/src/main/java/org/tianbin/java/IO/classpath/Main.java b/src/main/java/cc/tianbin/java/IO/classpath/Main.java similarity index 94% rename from src/main/java/org/tianbin/java/IO/classpath/Main.java rename to src/main/java/cc/tianbin/java/IO/classpath/Main.java index 7231caa2..8357a2f3 100644 --- a/src/main/java/org/tianbin/java/IO/classpath/Main.java +++ b/src/main/java/cc/tianbin/java/IO/classpath/Main.java @@ -1,10 +1,10 @@ -package org.tianbin.java.IO.classpath; +package cc.tianbin.java.IO.classpath; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.google.common.io.ByteStreams; import org.junit.Test; -import org.tianbin.java.IO.FileReaderTest; +import cc.tianbin.java.IO.FileReaderTest; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/org/tianbin/java/IO/classpath/ResourcesReaderUtil.java b/src/main/java/cc/tianbin/java/IO/classpath/ResourcesReaderUtil.java similarity index 87% rename from src/main/java/org/tianbin/java/IO/classpath/ResourcesReaderUtil.java rename to src/main/java/cc/tianbin/java/IO/classpath/ResourcesReaderUtil.java index 83f125dd..d47ff92f 100644 --- a/src/main/java/org/tianbin/java/IO/classpath/ResourcesReaderUtil.java +++ b/src/main/java/cc/tianbin/java/IO/classpath/ResourcesReaderUtil.java @@ -1,4 +1,4 @@ -package org.tianbin.java.IO.classpath; +package cc.tianbin.java.IO.classpath; import java.io.IOException; import java.io.InputStream; diff --git a/src/main/java/org/tianbin/java/IO/classpath/RpcConfig.java b/src/main/java/cc/tianbin/java/IO/classpath/RpcConfig.java similarity index 79% rename from src/main/java/org/tianbin/java/IO/classpath/RpcConfig.java rename to src/main/java/cc/tianbin/java/IO/classpath/RpcConfig.java index 7955d28a..d0a9ad96 100644 --- a/src/main/java/org/tianbin/java/IO/classpath/RpcConfig.java +++ b/src/main/java/cc/tianbin/java/IO/classpath/RpcConfig.java @@ -1,4 +1,4 @@ -package org.tianbin.java.IO.classpath; +package cc.tianbin.java.IO.classpath; import lombok.Data; diff --git a/src/main/java/org/tianbin/java/proxy/README.md b/src/main/java/cc/tianbin/java/proxy/README.md similarity index 100% rename from src/main/java/org/tianbin/java/proxy/README.md rename to src/main/java/cc/tianbin/java/proxy/README.md diff --git a/src/main/java/org/tianbin/java/proxy/cglib/Main.java b/src/main/java/cc/tianbin/java/proxy/cglib/Main.java similarity index 99% rename from src/main/java/org/tianbin/java/proxy/cglib/Main.java rename to src/main/java/cc/tianbin/java/proxy/cglib/Main.java index 6dd52365..afe92ce5 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/Main.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/Main.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib; +package cc.tianbin.java.proxy.cglib; import junit.framework.TestCase; import net.sf.cglib.proxy.*; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/Person.java b/src/main/java/cc/tianbin/java/proxy/cglib/Person.java similarity index 95% rename from src/main/java/org/tianbin/java/proxy/cglib/Person.java rename to src/main/java/cc/tianbin/java/proxy/cglib/Person.java index e50cfd56..6f742575 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/Person.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/Person.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib; +package cc.tianbin.java.proxy.cglib; import lombok.Data; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/TargetInterceptor.java b/src/main/java/cc/tianbin/java/proxy/cglib/TargetInterceptor.java similarity index 96% rename from src/main/java/org/tianbin/java/proxy/cglib/TargetInterceptor.java rename to src/main/java/cc/tianbin/java/proxy/cglib/TargetInterceptor.java index 669476ae..79adbf40 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/TargetInterceptor.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/TargetInterceptor.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib; +package cc.tianbin.java.proxy.cglib; import com.alibaba.fastjson.JSON; import net.sf.cglib.proxy.MethodInterceptor; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java b/src/main/java/cc/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java similarity index 95% rename from src/main/java/org/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java rename to src/main/java/cc/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java index a3ce84e1..abb480f5 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/TargetMethodCallbackFilter.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib; +package cc.tianbin.java.proxy.cglib; import net.sf.cglib.proxy.CallbackFilter; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/TargetResultFixed.java b/src/main/java/cc/tianbin/java/proxy/cglib/TargetResultFixed.java similarity index 94% rename from src/main/java/org/tianbin/java/proxy/cglib/TargetResultFixed.java rename to src/main/java/cc/tianbin/java/proxy/cglib/TargetResultFixed.java index a7169dad..f78a9b0f 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/TargetResultFixed.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/TargetResultFixed.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib; +package cc.tianbin.java.proxy.cglib; import net.sf.cglib.proxy.FixedValue; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java similarity index 92% rename from src/main/java/org/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java rename to src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java index b2329750..053d2584 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib.lazyloader; +package cc.tianbin.java.proxy.cglib.lazyloader; import common.model.Person; import net.sf.cglib.proxy.Dispatcher; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java similarity index 95% rename from src/main/java/org/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java rename to src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java index b44c9511..f8289d58 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib.lazyloader; +package cc.tianbin.java.proxy.cglib.lazyloader; import common.model.Person; import net.sf.cglib.proxy.LazyLoader; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/LazyBean.java b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/LazyBean.java similarity index 97% rename from src/main/java/org/tianbin/java/proxy/cglib/lazyloader/LazyBean.java rename to src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/LazyBean.java index 04aa56b6..43eaa46b 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/LazyBean.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/LazyBean.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib.lazyloader; +package cc.tianbin.java.proxy.cglib.lazyloader; import lombok.Data; import lombok.ToString; diff --git a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java similarity index 83% rename from src/main/java/org/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java rename to src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java index 9593fabe..3946d2ce 100644 --- a/src/main/java/org/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java +++ b/src/main/java/cc/tianbin/java/proxy/cglib/lazyloader/PropertyBean.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.cglib.lazyloader; +package cc.tianbin.java.proxy.cglib.lazyloader; import lombok.Data; import lombok.ToString; diff --git a/src/main/java/org/tianbin/java/proxy/jdk/Calculator.java b/src/main/java/cc/tianbin/java/proxy/jdk/Calculator.java similarity index 74% rename from src/main/java/org/tianbin/java/proxy/jdk/Calculator.java rename to src/main/java/cc/tianbin/java/proxy/jdk/Calculator.java index 978dbe6c..bcd2d65e 100644 --- a/src/main/java/org/tianbin/java/proxy/jdk/Calculator.java +++ b/src/main/java/cc/tianbin/java/proxy/jdk/Calculator.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.jdk; +package cc.tianbin.java.proxy.jdk; /** * Created by nibnait on 2020/11/23 diff --git a/src/main/java/org/tianbin/java/proxy/jdk/CalculatorImpl.java b/src/main/java/cc/tianbin/java/proxy/jdk/CalculatorImpl.java similarity index 83% rename from src/main/java/org/tianbin/java/proxy/jdk/CalculatorImpl.java rename to src/main/java/cc/tianbin/java/proxy/jdk/CalculatorImpl.java index b18f597a..407d8b13 100644 --- a/src/main/java/org/tianbin/java/proxy/jdk/CalculatorImpl.java +++ b/src/main/java/cc/tianbin/java/proxy/jdk/CalculatorImpl.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.jdk; +package cc.tianbin.java.proxy.jdk; /** * Created by nibnait on 2020/11/23 diff --git a/src/main/java/org/tianbin/java/proxy/jdk/HelloService.java b/src/main/java/cc/tianbin/java/proxy/jdk/HelloService.java similarity index 84% rename from src/main/java/org/tianbin/java/proxy/jdk/HelloService.java rename to src/main/java/cc/tianbin/java/proxy/jdk/HelloService.java index cf18edd7..e5b7b740 100644 --- a/src/main/java/org/tianbin/java/proxy/jdk/HelloService.java +++ b/src/main/java/cc/tianbin/java/proxy/jdk/HelloService.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.jdk; +package cc.tianbin.java.proxy.jdk; /** * @author nibnait diff --git a/src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java b/src/main/java/cc/tianbin/java/proxy/jdk/HelloServiceImpl.java similarity index 91% rename from src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java rename to src/main/java/cc/tianbin/java/proxy/jdk/HelloServiceImpl.java index 509f29c0..6b1e104c 100644 --- a/src/main/java/org/tianbin/java/proxy/jdk/HelloServiceImpl.java +++ b/src/main/java/cc/tianbin/java/proxy/jdk/HelloServiceImpl.java @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.jdk; +package cc.tianbin.java.proxy.jdk; /** * @author nibnait diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" similarity index 72% rename from "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" rename to "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" index d1b31893..427c9795 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" +++ "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" @@ -1,9 +1,9 @@ -package org.tianbin.java.proxy.jdk.动态代理; +package cc.tianbin.java.proxy.jdk.动态代理; +import cc.tianbin.java.proxy.jdk.动态代理.handler.LogHandler; import org.junit.Test; -import org.tianbin.java.proxy.jdk.Calculator; -import org.tianbin.java.proxy.jdk.CalculatorImpl; -import org.tianbin.java.proxy.jdk.动态代理.handler.LogHandler; +import cc.tianbin.java.proxy.jdk.Calculator; +import cc.tianbin.java.proxy.jdk.CalculatorImpl; import java.lang.reflect.Proxy; diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" similarity index 91% rename from "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" rename to "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" index cb3e6890..99996d78 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" +++ "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" @@ -1,10 +1,10 @@ -package org.tianbin.java.proxy.jdk.动态代理; +package cc.tianbin.java.proxy.jdk.动态代理; +import cc.tianbin.java.proxy.jdk.动态代理.handler.MyInvocationHandler; import junit.framework.TestCase; import org.junit.Test; -import org.tianbin.java.proxy.jdk.HelloService; -import org.tianbin.java.proxy.jdk.HelloServiceImpl; -import org.tianbin.java.proxy.jdk.动态代理.handler.MyInvocationHandler; +import cc.tianbin.java.proxy.jdk.HelloService; +import cc.tianbin.java.proxy.jdk.HelloServiceImpl; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationHandler; diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" similarity index 93% rename from "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" rename to "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" index 4983b3be..ad1d9d80 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" +++ "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.jdk.动态代理.handler; +package cc.tianbin.java.proxy.jdk.动态代理.handler; import com.alibaba.fastjson.JSON; diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" similarity index 94% rename from "src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" rename to "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" index ff1aa16e..010ce650 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" +++ "b/src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.proxy.jdk.动态代理.handler; +package cc.tianbin.java.proxy.jdk.动态代理.handler; import com.alibaba.fastjson.JSON; diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" "b/src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" similarity index 81% rename from "src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" rename to "src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" index 3c47761c..85568500 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" +++ "b/src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" @@ -1,6 +1,6 @@ -package org.tianbin.java.proxy.jdk.静态代理; +package cc.tianbin.java.proxy.jdk.静态代理; -import org.tianbin.java.proxy.jdk.HelloService; +import cc.tianbin.java.proxy.jdk.HelloService; /** * Created by nibnait on 2020/11/23 diff --git "a/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" "b/src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" similarity index 72% rename from "src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" rename to "src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" index babac41d..e5441ccd 100644 --- "a/src/main/java/org/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" +++ "b/src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" @@ -1,7 +1,7 @@ -package org.tianbin.java.proxy.jdk.静态代理; +package cc.tianbin.java.proxy.jdk.静态代理; import org.junit.Test; -import org.tianbin.java.proxy.jdk.HelloServiceImpl; +import cc.tianbin.java.proxy.jdk.HelloServiceImpl; /** * Created by nibnait on 2020/11/23 diff --git "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" "b/src/main/java/cc/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" similarity index 99% rename from "src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" rename to "src/main/java/cc/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" index 18a925e0..0a475254 100644 --- "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" +++ "b/src/main/java/cc/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.反射; +package cc.tianbin.java.反射; import cn.hutool.log.Log; import cn.hutool.log.LogFactory; diff --git "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" "b/src/main/java/cc/tianbin/java/\345\217\215\345\260\204/Main.java" similarity index 98% rename from "src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" rename to "src/main/java/cc/tianbin/java/\345\217\215\345\260\204/Main.java" index 83c22cf4..3edc1879 100644 --- "a/src/main/java/org/tianbin/java/\345\217\215\345\260\204/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\217\215\345\260\204/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.反射; +package cc.tianbin.java.反射; import com.alibaba.fastjson.JSON; import com.google.common.collect.Lists; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" index c4702e5a..94eba78f 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" similarity index 83% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" index 0b4d4efd..b7ed07b6 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" similarity index 83% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" index bb4d0212..ba04dcf1 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" similarity index 94% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" index 9853dd51..d47b8d75 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" similarity index 90% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" index 6489633c..cf3db175 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import org.junit.Test; @@ -7,6 +7,11 @@ */ public class IntegerTest { + @Test + public void max() { + System.out.println(Integer.MAX_VALUE); + } + @Test public void testCompareTo() { Integer old = 110; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" similarity index 82% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" index b64b7ed3..8c03404d 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" similarity index 76% rename from "src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" rename to "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" index b10fad13..91b54b25 100644 --- "a/src/main/java/org/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" @@ -1,11 +1,14 @@ -package org.tianbin.java.基本数据类型; +package cc.tianbin.java.基本数据类型; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; +import io.github.nibnait.common.constants.CommonConstants; import junit.framework.TestCase; import org.apache.commons.lang3.StringUtils; import org.junit.Test; +import java.util.HashSet; +import java.util.Set; import java.util.Stack; /** @@ -13,6 +16,13 @@ */ public class StringTest extends TestCase { + @Test + public void testJoin() { + Set set = new HashSet<>(); + String join = String.join(CommonConstants.COMMA_SEPARATOR, set); + System.out.println(join); + } + @Test public void testStringUtils() { StringUtils.isEmpty(""); diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" index 9ee250f3..6a7f362b 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_AQS; +package cc.tianbin.java.并发.JUC.JUC_AQS; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" index b16e8f2f..b5ab0805 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_AQS; +package cc.tianbin.java.并发.JUC.JUC_AQS; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" index 7c2cdbf0..47902c45 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_AQS; +package cc.tianbin.java.并发.JUC.JUC_AQS; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" index a7c1703f..2a1863fc 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_demo; +package cc.tianbin.java.并发.JUC.JUC_demo; import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" index ece1723a..33f0151d 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_demo; +package cc.tianbin.java.并发.JUC.JUC_demo; import java.util.HashMap; import java.util.Map; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" index afe48196..4ae172cb 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_demo; +package cc.tianbin.java.并发.JUC.JUC_demo; import com.lmax.disruptor.BlockingWaitStrategy; import com.lmax.disruptor.EventFactory; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" similarity index 98% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" index 0a4d77ba..4e10abc5 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_demo; +package cc.tianbin.java.并发.JUC.JUC_demo; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" similarity index 98% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" index 0cb0f274..3f51510b 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_demo; +package cc.tianbin.java.并发.JUC.JUC_demo; import java.util.concurrent.locks.LockSupport; import java.util.concurrent.locks.StampedLock; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" index 224167ca..9f6b8b79 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_other; +package cc.tianbin.java.并发.JUC.JUC_other; import java.util.concurrent.RecursiveTask; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" index c9e22736..819d13a5 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_other; +package cc.tianbin.java.并发.JUC.JUC_other; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" index 07080659..dfa8a423 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_other; +package cc.tianbin.java.并发.JUC.JUC_other; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" index 613eb1f1..9b6b0f6b 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC.JUC_other; +package cc.tianbin.java.并发.JUC.JUC_other; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.BlockingQueue; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" similarity index 99% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" index d1637ce6..e7361bcb 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.JUC; +package cc.tianbin.java.并发.JUC; import com.alibaba.fastjson.JSON; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/Main.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" index 63dee564..5145f3be 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发; +package cc.tianbin.java.并发; import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" index 7c5887d3..70e26f79 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import java.util.concurrent.*; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" similarity index 99% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" index 1001e98a..5f56fa83 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" index 86fc5294..624ab0b4 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" similarity index 92% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" index 4b613524..e1abdd2e 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" similarity index 98% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" index 36c390c1..add74e69 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" index 0f4f5e47..6bab384b 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" similarity index 98% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" index eb2d6ec3..570210ca 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" index 65270165..2cab260e 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import common.util.SystemUtil; import junit.framework.TestCase; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" similarity index 96% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" index b8370ac9..2dd5895d 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" similarity index 98% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" index 344eff22..8d3a0b8d 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool; +package cc.tianbin.java.并发.threadpool; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" index 49ba5eb3..e3479cc0 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" similarity index 91% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" index b3b9f83e..e9c31948 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" index 6e3399da..2e4c2624 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import lombok.SneakyThrows; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" index 9dea82be..888d1d8d 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import lombok.SneakyThrows; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" similarity index 92% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" index 6b94fba2..d2e44741 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" similarity index 94% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" index 33009a35..f49e4fb7 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import lombok.SneakyThrows; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" similarity index 94% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" index f9685dc6..c7515c1b 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.threadpool.让3个线程顺序执行; +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; import lombok.SneakyThrows; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" similarity index 79% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" index 485a1671..4d84d037 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.CAS; +package cc.tianbin.java.并发.悲观锁vs乐观锁.CAS; import java.util.concurrent.atomic.AtomicInteger; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" index 296e2828..cd066240 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.CAS; +package cc.tianbin.java.并发.悲观锁vs乐观锁.CAS; import common.model.Person; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" similarity index 86% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" index 235b4219..75a0a044 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock; +package cc.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock; import java.util.concurrent.locks.Lock; import java.util.concurrent.locks.ReentrantLock; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" similarity index 93% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" index f679a154..bf0830fe 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock; +package cc.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" similarity index 94% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" index 6a3860f2..be5aad43 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; +package cc.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; import java.util.concurrent.TimeUnit; import java.util.concurrent.locks.Condition; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" similarity index 85% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" index fe8bff52..57f6325a 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; +package cc.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; public class JoinExample { static class A extends Thread { diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" similarity index 95% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" index 3d08e8e8..cef13f52 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; +package cc.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" similarity index 100% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" similarity index 84% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" index e19f3ed5..250cc07f 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; +package cc.tianbin.java.并发.悲观锁vs乐观锁.reentrantLock.线程间的协作; public class WaitNotifyExample { diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" similarity index 97% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" index a7339ca6..54dac3bb 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.synchronize; +package cc.tianbin.java.并发.悲观锁vs乐观锁.synchronize; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" similarity index 94% rename from "src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" rename to "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" index 3fe38713..6ca58ffd 100644 --- "a/src/main/java/org/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.并发.悲观锁vs乐观锁.synchronize; +package cc.tianbin.java.并发.悲观锁vs乐观锁.synchronize; public class SynchronizedExample { diff --git "a/src/main/java/org/tianbin/java/\345\274\202\345\270\270/Main.java" "b/src/main/java/cc/tianbin/java/\345\274\202\345\270\270/Main.java" similarity index 91% rename from "src/main/java/org/tianbin/java/\345\274\202\345\270\270/Main.java" rename to "src/main/java/cc/tianbin/java/\345\274\202\345\270\270/Main.java" index e3aeeb08..79709990 100644 --- "a/src/main/java/org/tianbin/java/\345\274\202\345\270\270/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\274\202\345\270\270/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.异常; +package cc.tianbin.java.异常; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" similarity index 93% rename from "src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" rename to "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" index c20781f5..48dc04eb 100644 --- "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.集合; +package cc.tianbin.java.集合; import java.util.*; import java.util.concurrent.BlockingQueue; diff --git "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" similarity index 94% rename from "src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" rename to "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" index cdb2e63e..028db407 100644 --- "a/src/main/java/org/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.集合; +package cc.tianbin.java.集合; import java.util.*; import java.util.concurrent.ConcurrentHashMap; diff --git a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest01.java b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest01.java similarity index 98% rename from src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest01.java rename to src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest01.java index a22f8770..cef58945 100644 --- a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest01.java +++ b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest01.java @@ -1,4 +1,4 @@ -package org.tianbin.jvm.GCRoots; +package cc.tianbin.jvm.GCRoots; /** * 测试:虚拟机栈(栈帧中的局部变量)中引用的对象作为GCRoots diff --git a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest02.java b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest02.java similarity index 98% rename from src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest02.java rename to src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest02.java index e0094851..19119c6f 100644 --- a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest02.java +++ b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest02.java @@ -1,4 +1,4 @@ -package org.tianbin.jvm.GCRoots; +package cc.tianbin.jvm.GCRoots; /** * 测试:方法区中的静态变量引用的对象作为GCRoots diff --git a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest03.java b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest03.java similarity index 97% rename from src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest03.java rename to src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest03.java index 0cf401ff..d77f631d 100644 --- a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest03.java +++ b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest03.java @@ -1,4 +1,4 @@ -package org.tianbin.jvm.GCRoots; +package cc.tianbin.jvm.GCRoots; /** * 测试:常量引用对象作为GCRoots diff --git a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest04.java b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest04.java similarity index 97% rename from src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest04.java rename to src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest04.java index 1e68b002..f3aa4515 100644 --- a/src/main/java/org/tianbin/jvm/GCRoots/GCRootsTest04.java +++ b/src/main/java/cc/tianbin/jvm/GCRoots/GCRootsTest04.java @@ -1,4 +1,4 @@ -package org.tianbin.jvm.GCRoots; +package cc.tianbin.jvm.GCRoots; /** * 测试:成员变量引用对象是否可作为GCRoots diff --git a/src/main/java/org/tianbin/jvm/GCRoots/README.md b/src/main/java/cc/tianbin/jvm/GCRoots/README.md similarity index 100% rename from src/main/java/org/tianbin/jvm/GCRoots/README.md rename to src/main/java/cc/tianbin/jvm/GCRoots/README.md diff --git "a/src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" "b/src/main/java/cc/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" similarity index 96% rename from "src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" rename to "src/main/java/cc/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" index 55e798ee..202b356f 100644 --- "a/src/main/java/org/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" +++ "b/src/main/java/cc/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" @@ -1,4 +1,4 @@ -package org.tianbin.jvm.GC优化; +package cc.tianbin.jvm.GC优化; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/tianbin/jvm/classloader/ClassLoaderDemo.java b/src/main/java/cc/tianbin/jvm/classloader/ClassLoaderDemo.java similarity index 93% rename from src/main/java/org/tianbin/jvm/classloader/ClassLoaderDemo.java rename to src/main/java/cc/tianbin/jvm/classloader/ClassLoaderDemo.java index eefed400..7a172a6c 100644 --- a/src/main/java/org/tianbin/jvm/classloader/ClassLoaderDemo.java +++ b/src/main/java/cc/tianbin/jvm/classloader/ClassLoaderDemo.java @@ -1,4 +1,4 @@ -package org.tianbin.jvm.classloader; +package cc.tianbin.jvm.classloader; /** * Created by nibnait on 2020/11/11 diff --git a/src/main/java/org/tianbin/jvm/classloader/LoadStringDemo.java b/src/main/java/cc/tianbin/jvm/classloader/LoadStringDemo.java similarity index 95% rename from src/main/java/org/tianbin/jvm/classloader/LoadStringDemo.java rename to src/main/java/cc/tianbin/jvm/classloader/LoadStringDemo.java index 0263cf28..e8fe2a94 100644 --- a/src/main/java/org/tianbin/jvm/classloader/LoadStringDemo.java +++ b/src/main/java/cc/tianbin/jvm/classloader/LoadStringDemo.java @@ -1,4 +1,4 @@ -package org.tianbin.jvm.classloader; +package cc.tianbin.jvm.classloader; import org.junit.Test; diff --git "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" "b/src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" similarity index 72% rename from "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" rename to "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" index a67fda6e..2165e7c1 100644 --- "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" +++ "b/src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" @@ -1,4 +1,4 @@ -package org.tianbin.jvm.classloader.自定义类加载器; +package cc.tianbin.jvm.classloader.自定义类加载器; /** * Created by nibnait on 2020/11/11 diff --git "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" "b/src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" similarity index 92% rename from "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" rename to "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" index 9eed5b77..1271a55c 100644 --- "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" +++ "b/src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" @@ -1,4 +1,4 @@ -package org.tianbin.jvm.classloader.自定义类加载器; +package cc.tianbin.jvm.classloader.自定义类加载器; import org.junit.Test; @@ -26,7 +26,7 @@ public void testLoadDemo() throws Exception { MyClassLoader classLoader = new MyClassLoader(ClassLoader.getSystemClassLoader().getParent()); classLoader.setRoot("/Users/nibnait/github/algorithms/src/main/java/org/tianbin/jvm/classloader/自定义类加载器"); - Class clz = Class.forName("org.tianbin.jvm.classloader.自定义类加载器.LoadDemo", true, classLoader); + Class clz = Class.forName("cc.tianbin.jvm.classloader.自定义类加载器.LoadDemo", true, classLoader); Object instance = clz.newInstance(); Method test = clz.getDeclaredMethod("test"); test.setAccessible(true); diff --git "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" "b/src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" similarity index 95% rename from "src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" rename to "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" index bc65051a..4c4a5656 100644 --- "a/src/main/java/org/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" +++ "b/src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" @@ -1,4 +1,4 @@ -package org.tianbin.jvm.classloader.自定义类加载器; +package cc.tianbin.jvm.classloader.自定义类加载器; import lombok.Data; import lombok.NoArgsConstructor; diff --git "a/src/main/java/org/tianbin/jvm/\345\274\225\347\224\250/Reference.java" "b/src/main/java/cc/tianbin/jvm/\345\274\225\347\224\250/Reference.java" similarity index 98% rename from "src/main/java/org/tianbin/jvm/\345\274\225\347\224\250/Reference.java" rename to "src/main/java/cc/tianbin/jvm/\345\274\225\347\224\250/Reference.java" index 035d3625..9930c8a0 100644 --- "a/src/main/java/org/tianbin/jvm/\345\274\225\347\224\250/Reference.java" +++ "b/src/main/java/cc/tianbin/jvm/\345\274\225\347\224\250/Reference.java" @@ -1,4 +1,4 @@ -package org.tianbin.jvm.引用; +package cc.tianbin.jvm.引用; import com.caucho.hessian.io.SerializerFactory; import org.junit.Test; diff --git a/src/main/java/org/tianbin/netty/Main.java b/src/main/java/cc/tianbin/netty/Main.java similarity index 86% rename from src/main/java/org/tianbin/netty/Main.java rename to src/main/java/cc/tianbin/netty/Main.java index 71ad19a9..d11783ee 100644 --- a/src/main/java/org/tianbin/netty/Main.java +++ b/src/main/java/cc/tianbin/netty/Main.java @@ -1,4 +1,4 @@ -package org.tianbin.netty; +package cc.tianbin.netty; /** * @author nibnait diff --git a/src/main/java/org/tianbin/netty/README.md b/src/main/java/cc/tianbin/netty/README.md similarity index 100% rename from src/main/java/org/tianbin/netty/README.md rename to src/main/java/cc/tianbin/netty/README.md diff --git a/src/main/java/org/tianbin/netty/http/App.java b/src/main/java/cc/tianbin/netty/http/App.java similarity index 88% rename from src/main/java/org/tianbin/netty/http/App.java rename to src/main/java/cc/tianbin/netty/http/App.java index f65fadb8..ca4191cb 100644 --- a/src/main/java/org/tianbin/netty/http/App.java +++ b/src/main/java/cc/tianbin/netty/http/App.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.http; +package cc.tianbin.netty.http; /** * @author nibnait diff --git a/src/main/java/org/tianbin/netty/http/HttpServer.java b/src/main/java/cc/tianbin/netty/http/HttpServer.java similarity index 98% rename from src/main/java/org/tianbin/netty/http/HttpServer.java rename to src/main/java/cc/tianbin/netty/http/HttpServer.java index 8de9c8ad..dda259df 100644 --- a/src/main/java/org/tianbin/netty/http/HttpServer.java +++ b/src/main/java/cc/tianbin/netty/http/HttpServer.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.http; +package cc.tianbin.netty.http; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.nio.NioEventLoopGroup; diff --git a/src/main/java/org/tianbin/netty/http/ServerHandler.java b/src/main/java/cc/tianbin/netty/http/ServerHandler.java similarity index 99% rename from src/main/java/org/tianbin/netty/http/ServerHandler.java rename to src/main/java/cc/tianbin/netty/http/ServerHandler.java index 6743aec0..292a528a 100644 --- a/src/main/java/org/tianbin/netty/http/ServerHandler.java +++ b/src/main/java/cc/tianbin/netty/http/ServerHandler.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.http; +package cc.tianbin.netty.http; import io.netty.buffer.ByteBuf; import io.netty.buffer.Unpooled; diff --git a/src/main/java/org/tianbin/netty/http/ServerInitializer.java b/src/main/java/cc/tianbin/netty/http/ServerInitializer.java similarity index 95% rename from src/main/java/org/tianbin/netty/http/ServerInitializer.java rename to src/main/java/cc/tianbin/netty/http/ServerInitializer.java index f8a9daed..78796a06 100644 --- a/src/main/java/org/tianbin/netty/http/ServerInitializer.java +++ b/src/main/java/cc/tianbin/netty/http/ServerInitializer.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.http; +package cc.tianbin.netty.http; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; diff --git a/src/main/java/org/tianbin/netty/rpc/ClientApp.java b/src/main/java/cc/tianbin/netty/rpc/ClientApp.java similarity index 83% rename from src/main/java/org/tianbin/netty/rpc/ClientApp.java rename to src/main/java/cc/tianbin/netty/rpc/ClientApp.java index 467bc6e7..0098d09c 100644 --- a/src/main/java/org/tianbin/netty/rpc/ClientApp.java +++ b/src/main/java/cc/tianbin/netty/rpc/ClientApp.java @@ -1,9 +1,9 @@ -package org.tianbin.netty.rpc; +package cc.tianbin.netty.rpc; -import org.tianbin.netty.rpc.client.RPCClient; -import org.tianbin.netty.rpc.client.request.RPCException; -import org.tianbin.netty.rpc.customHandler.ExpRequest; -import org.tianbin.netty.rpc.customHandler.ExpResponse; +import cc.tianbin.netty.rpc.customHandler.ExpRequest; +import cc.tianbin.netty.rpc.client.RPCClient; +import cc.tianbin.netty.rpc.client.request.RPCException; +import cc.tianbin.netty.rpc.customHandler.ExpResponse; /** * Created by nibnait on 2019-08-21 diff --git a/src/main/java/org/tianbin/netty/rpc/ServerApp.java b/src/main/java/cc/tianbin/netty/rpc/ServerApp.java similarity index 58% rename from src/main/java/org/tianbin/netty/rpc/ServerApp.java rename to src/main/java/cc/tianbin/netty/rpc/ServerApp.java index a8e9c1aa..61abeeb0 100644 --- a/src/main/java/org/tianbin/netty/rpc/ServerApp.java +++ b/src/main/java/cc/tianbin/netty/rpc/ServerApp.java @@ -1,9 +1,9 @@ -package org.tianbin.netty.rpc; +package cc.tianbin.netty.rpc; -import org.tianbin.netty.rpc.customHandler.ExpRequest; -import org.tianbin.netty.rpc.customHandler.ExpRequestHandler; -import org.tianbin.netty.rpc.customHandler.FibRequestHandler; -import org.tianbin.netty.rpc.server.RPCServer; +import cc.tianbin.netty.rpc.customHandler.ExpRequest; +import cc.tianbin.netty.rpc.customHandler.ExpRequestHandler; +import cc.tianbin.netty.rpc.customHandler.FibRequestHandler; +import cc.tianbin.netty.rpc.server.RPCServer; /** * Created by nibnait on 2019-08-21 diff --git a/src/main/java/org/tianbin/netty/rpc/client/RPCClient.java b/src/main/java/cc/tianbin/netty/rpc/client/RPCClient.java similarity index 94% rename from src/main/java/org/tianbin/netty/rpc/client/RPCClient.java rename to src/main/java/cc/tianbin/netty/rpc/client/RPCClient.java index 1dcb2b09..92b5b717 100644 --- a/src/main/java/org/tianbin/netty/rpc/client/RPCClient.java +++ b/src/main/java/cc/tianbin/netty/rpc/client/RPCClient.java @@ -1,10 +1,10 @@ -package org.tianbin.netty.rpc.client; +package cc.tianbin.netty.rpc.client; +import cc.tianbin.netty.rpc.client.request.RPCException; +import cc.tianbin.netty.rpc.client.request.RequestId; +import cc.tianbin.netty.rpc.client.request.ResponseRegistry; import com.alibaba.fastjson.JSON; import io.netty.util.CharsetUtil; -import org.tianbin.netty.rpc.client.request.RPCException; -import org.tianbin.netty.rpc.client.request.RequestId; -import org.tianbin.netty.rpc.client.request.ResponseRegistry; import java.io.*; import java.net.InetSocketAddress; diff --git a/src/main/java/org/tianbin/netty/rpc/client/request/RPCException.java b/src/main/java/cc/tianbin/netty/rpc/client/request/RPCException.java similarity index 90% rename from src/main/java/org/tianbin/netty/rpc/client/request/RPCException.java rename to src/main/java/cc/tianbin/netty/rpc/client/request/RPCException.java index 9a36a8cb..2ebbf9b6 100644 --- a/src/main/java/org/tianbin/netty/rpc/client/request/RPCException.java +++ b/src/main/java/cc/tianbin/netty/rpc/client/request/RPCException.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.client.request; +package cc.tianbin.netty.rpc.client.request; /** * 定义客户端异常,用于统一抛出RPC错误 diff --git a/src/main/java/org/tianbin/netty/rpc/client/request/RPCRequest.java b/src/main/java/cc/tianbin/netty/rpc/client/request/RPCRequest.java similarity index 84% rename from src/main/java/org/tianbin/netty/rpc/client/request/RPCRequest.java rename to src/main/java/cc/tianbin/netty/rpc/client/request/RPCRequest.java index 951cda87..a6ded960 100644 --- a/src/main/java/org/tianbin/netty/rpc/client/request/RPCRequest.java +++ b/src/main/java/cc/tianbin/netty/rpc/client/request/RPCRequest.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.client.request; +package cc.tianbin.netty.rpc.client.request; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/org/tianbin/netty/rpc/client/request/RPCResponse.java b/src/main/java/cc/tianbin/netty/rpc/client/request/RPCResponse.java similarity index 84% rename from src/main/java/org/tianbin/netty/rpc/client/request/RPCResponse.java rename to src/main/java/cc/tianbin/netty/rpc/client/request/RPCResponse.java index 388dcb71..f6d2b0b0 100644 --- a/src/main/java/org/tianbin/netty/rpc/client/request/RPCResponse.java +++ b/src/main/java/cc/tianbin/netty/rpc/client/request/RPCResponse.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.client.request; +package cc.tianbin.netty.rpc.client.request; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/org/tianbin/netty/rpc/client/request/RequestId.java b/src/main/java/cc/tianbin/netty/rpc/client/request/RequestId.java similarity index 81% rename from src/main/java/org/tianbin/netty/rpc/client/request/RequestId.java rename to src/main/java/cc/tianbin/netty/rpc/client/request/RequestId.java index f7623d93..718c1e0f 100644 --- a/src/main/java/org/tianbin/netty/rpc/client/request/RequestId.java +++ b/src/main/java/cc/tianbin/netty/rpc/client/request/RequestId.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.client.request; +package cc.tianbin.netty.rpc.client.request; import java.util.UUID; diff --git a/src/main/java/org/tianbin/netty/rpc/client/request/ResponseRegistry.java b/src/main/java/cc/tianbin/netty/rpc/client/request/ResponseRegistry.java similarity index 90% rename from src/main/java/org/tianbin/netty/rpc/client/request/ResponseRegistry.java rename to src/main/java/cc/tianbin/netty/rpc/client/request/ResponseRegistry.java index dc2c2fef..6bc12741 100644 --- a/src/main/java/org/tianbin/netty/rpc/client/request/ResponseRegistry.java +++ b/src/main/java/cc/tianbin/netty/rpc/client/request/ResponseRegistry.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.client.request; +package cc.tianbin.netty.rpc.client.request; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/tianbin/netty/rpc/customHandler/ExpRequest.java b/src/main/java/cc/tianbin/netty/rpc/customHandler/ExpRequest.java similarity index 85% rename from src/main/java/org/tianbin/netty/rpc/customHandler/ExpRequest.java rename to src/main/java/cc/tianbin/netty/rpc/customHandler/ExpRequest.java index cb7bc473..bbb37a4b 100644 --- a/src/main/java/org/tianbin/netty/rpc/customHandler/ExpRequest.java +++ b/src/main/java/cc/tianbin/netty/rpc/customHandler/ExpRequest.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.customHandler; +package cc.tianbin.netty.rpc.customHandler; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/org/tianbin/netty/rpc/customHandler/ExpRequestHandler.java b/src/main/java/cc/tianbin/netty/rpc/customHandler/ExpRequestHandler.java similarity index 79% rename from src/main/java/org/tianbin/netty/rpc/customHandler/ExpRequestHandler.java rename to src/main/java/cc/tianbin/netty/rpc/customHandler/ExpRequestHandler.java index 55ada1bf..1823e195 100644 --- a/src/main/java/org/tianbin/netty/rpc/customHandler/ExpRequestHandler.java +++ b/src/main/java/cc/tianbin/netty/rpc/customHandler/ExpRequestHandler.java @@ -1,8 +1,8 @@ -package org.tianbin.netty.rpc.customHandler; +package cc.tianbin.netty.rpc.customHandler; import io.netty.channel.ChannelHandlerContext; -import org.tianbin.netty.rpc.server.message.IMessageHandler; -import org.tianbin.netty.rpc.server.message.MessageOutput; +import cc.tianbin.netty.rpc.server.message.IMessageHandler; +import cc.tianbin.netty.rpc.server.message.MessageOutput; /** * Created by nibnait on 2019-08-21 diff --git a/src/main/java/org/tianbin/netty/rpc/customHandler/ExpResponse.java b/src/main/java/cc/tianbin/netty/rpc/customHandler/ExpResponse.java similarity index 86% rename from src/main/java/org/tianbin/netty/rpc/customHandler/ExpResponse.java rename to src/main/java/cc/tianbin/netty/rpc/customHandler/ExpResponse.java index d1682822..b0782f98 100644 --- a/src/main/java/org/tianbin/netty/rpc/customHandler/ExpResponse.java +++ b/src/main/java/cc/tianbin/netty/rpc/customHandler/ExpResponse.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.customHandler; +package cc.tianbin.netty.rpc.customHandler; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/org/tianbin/netty/rpc/customHandler/FibRequestHandler.java b/src/main/java/cc/tianbin/netty/rpc/customHandler/FibRequestHandler.java similarity index 80% rename from src/main/java/org/tianbin/netty/rpc/customHandler/FibRequestHandler.java rename to src/main/java/cc/tianbin/netty/rpc/customHandler/FibRequestHandler.java index cdfb0b08..da748025 100644 --- a/src/main/java/org/tianbin/netty/rpc/customHandler/FibRequestHandler.java +++ b/src/main/java/cc/tianbin/netty/rpc/customHandler/FibRequestHandler.java @@ -1,8 +1,8 @@ -package org.tianbin.netty.rpc.customHandler; +package cc.tianbin.netty.rpc.customHandler; import io.netty.channel.ChannelHandlerContext; -import org.tianbin.netty.rpc.server.message.IMessageHandler; -import org.tianbin.netty.rpc.server.message.MessageOutput; +import cc.tianbin.netty.rpc.server.message.IMessageHandler; +import cc.tianbin.netty.rpc.server.message.MessageOutput; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/org/tianbin/netty/rpc/server/RPCServer.java b/src/main/java/cc/tianbin/netty/rpc/server/RPCServer.java similarity index 94% rename from src/main/java/org/tianbin/netty/rpc/server/RPCServer.java rename to src/main/java/cc/tianbin/netty/rpc/server/RPCServer.java index bb2b9978..7ae87585 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/RPCServer.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/RPCServer.java @@ -1,5 +1,8 @@ -package org.tianbin.netty.rpc.server; +package cc.tianbin.netty.rpc.server; +import cc.tianbin.netty.rpc.server.message.IMessageHandler; +import cc.tianbin.netty.rpc.server.message.MessageHandlers; +import cc.tianbin.netty.rpc.server.message.MessageRegistry; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.Channel; import io.netty.channel.ChannelInitializer; @@ -16,9 +19,6 @@ import io.netty.util.CharsetUtil; import lombok.AllArgsConstructor; import lombok.Data; -import org.tianbin.netty.rpc.server.message.IMessageHandler; -import org.tianbin.netty.rpc.server.message.MessageHandlers; -import org.tianbin.netty.rpc.server.message.MessageRegistry; /** * Created by nibnait on 2019-08-20 diff --git a/src/main/java/org/tianbin/netty/rpc/server/ServerHandler.java b/src/main/java/cc/tianbin/netty/rpc/server/ServerHandler.java similarity index 93% rename from src/main/java/org/tianbin/netty/rpc/server/ServerHandler.java rename to src/main/java/cc/tianbin/netty/rpc/server/ServerHandler.java index a487dee6..51de58d1 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/ServerHandler.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/ServerHandler.java @@ -1,12 +1,12 @@ -package org.tianbin.netty.rpc.server; +package cc.tianbin.netty.rpc.server; +import cc.tianbin.netty.rpc.server.message.IMessageHandler; +import cc.tianbin.netty.rpc.server.message.MessageHandlers; +import cc.tianbin.netty.rpc.server.message.MessageInput; +import cc.tianbin.netty.rpc.server.message.MessageRegistry; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.ChannelInboundHandlerAdapter; -import org.tianbin.netty.rpc.server.message.IMessageHandler; -import org.tianbin.netty.rpc.server.message.MessageHandlers; -import org.tianbin.netty.rpc.server.message.MessageInput; -import org.tianbin.netty.rpc.server.message.MessageRegistry; import java.util.concurrent.ArrayBlockingQueue; import java.util.concurrent.ThreadFactory; diff --git a/src/main/java/org/tianbin/netty/rpc/server/message/DefaultHandler.java b/src/main/java/cc/tianbin/netty/rpc/server/message/DefaultHandler.java similarity index 90% rename from src/main/java/org/tianbin/netty/rpc/server/message/DefaultHandler.java rename to src/main/java/cc/tianbin/netty/rpc/server/message/DefaultHandler.java index 9cc71dc2..a1a2ee7b 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/message/DefaultHandler.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/message/DefaultHandler.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.server.message; +package cc.tianbin.netty.rpc.server.message; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/org/tianbin/netty/rpc/server/message/IMessageHandler.java b/src/main/java/cc/tianbin/netty/rpc/server/message/IMessageHandler.java similarity index 85% rename from src/main/java/org/tianbin/netty/rpc/server/message/IMessageHandler.java rename to src/main/java/cc/tianbin/netty/rpc/server/message/IMessageHandler.java index 61649098..95e4157f 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/message/IMessageHandler.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/message/IMessageHandler.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.server.message; +package cc.tianbin.netty.rpc.server.message; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/org/tianbin/netty/rpc/server/message/MessageHandlers.java b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageHandlers.java similarity index 92% rename from src/main/java/org/tianbin/netty/rpc/server/message/MessageHandlers.java rename to src/main/java/cc/tianbin/netty/rpc/server/message/MessageHandlers.java index ac306f2f..9f093e1c 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/message/MessageHandlers.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageHandlers.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.server.message; +package cc.tianbin.netty.rpc.server.message; import junit.framework.TestCase; diff --git a/src/main/java/org/tianbin/netty/rpc/server/message/MessageInput.java b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageInput.java similarity index 91% rename from src/main/java/org/tianbin/netty/rpc/server/message/MessageInput.java rename to src/main/java/cc/tianbin/netty/rpc/server/message/MessageInput.java index 14e97397..9a92d317 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/message/MessageInput.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageInput.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.server.message; +package cc.tianbin.netty.rpc.server.message; import com.alibaba.fastjson.JSON; import lombok.AllArgsConstructor; diff --git a/src/main/java/org/tianbin/netty/rpc/server/message/MessageOutput.java b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageOutput.java similarity index 83% rename from src/main/java/org/tianbin/netty/rpc/server/message/MessageOutput.java rename to src/main/java/cc/tianbin/netty/rpc/server/message/MessageOutput.java index 76c1a2a2..8562928c 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/message/MessageOutput.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageOutput.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.server.message; +package cc.tianbin.netty.rpc.server.message; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/org/tianbin/netty/rpc/server/message/MessageRegistry.java b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageRegistry.java similarity index 89% rename from src/main/java/org/tianbin/netty/rpc/server/message/MessageRegistry.java rename to src/main/java/cc/tianbin/netty/rpc/server/message/MessageRegistry.java index cd34b970..ebd412fa 100644 --- a/src/main/java/org/tianbin/netty/rpc/server/message/MessageRegistry.java +++ b/src/main/java/cc/tianbin/netty/rpc/server/message/MessageRegistry.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.rpc.server.message; +package cc.tianbin.netty.rpc.server.message; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/org/tianbin/netty/webSocket/client/ClientApp.java b/src/main/java/cc/tianbin/netty/webSocket/client/ClientApp.java similarity index 77% rename from src/main/java/org/tianbin/netty/webSocket/client/ClientApp.java rename to src/main/java/cc/tianbin/netty/webSocket/client/ClientApp.java index f07ffdc3..208524d9 100644 --- a/src/main/java/org/tianbin/netty/webSocket/client/ClientApp.java +++ b/src/main/java/cc/tianbin/netty/webSocket/client/ClientApp.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.client; +package cc.tianbin.netty.webSocket.client; /** * Created by nibnait on 2019-08-21 diff --git a/src/main/java/org/tianbin/netty/webSocket/client/ClientHandler.java b/src/main/java/cc/tianbin/netty/webSocket/client/ClientHandler.java similarity index 90% rename from src/main/java/org/tianbin/netty/webSocket/client/ClientHandler.java rename to src/main/java/cc/tianbin/netty/webSocket/client/ClientHandler.java index 1b32eb32..67bfcfad 100644 --- a/src/main/java/org/tianbin/netty/webSocket/client/ClientHandler.java +++ b/src/main/java/cc/tianbin/netty/webSocket/client/ClientHandler.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.client; +package cc.tianbin.netty.webSocket.client; import io.netty.channel.ChannelHandlerContext; import io.netty.channel.SimpleChannelInboundHandler; diff --git a/src/main/java/org/tianbin/netty/webSocket/client/ClientInitializer.java b/src/main/java/cc/tianbin/netty/webSocket/client/ClientInitializer.java similarity index 95% rename from src/main/java/org/tianbin/netty/webSocket/client/ClientInitializer.java rename to src/main/java/cc/tianbin/netty/webSocket/client/ClientInitializer.java index f0a92971..fb14a717 100644 --- a/src/main/java/org/tianbin/netty/webSocket/client/ClientInitializer.java +++ b/src/main/java/cc/tianbin/netty/webSocket/client/ClientInitializer.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.client; +package cc.tianbin.netty.webSocket.client; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; diff --git a/src/main/java/org/tianbin/netty/webSocket/client/SocketClient.java b/src/main/java/cc/tianbin/netty/webSocket/client/SocketClient.java similarity index 96% rename from src/main/java/org/tianbin/netty/webSocket/client/SocketClient.java rename to src/main/java/cc/tianbin/netty/webSocket/client/SocketClient.java index 523a6fe8..8f63b8ff 100644 --- a/src/main/java/org/tianbin/netty/webSocket/client/SocketClient.java +++ b/src/main/java/cc/tianbin/netty/webSocket/client/SocketClient.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.client; +package cc.tianbin.netty.webSocket.client; import io.netty.bootstrap.Bootstrap; import io.netty.channel.Channel; diff --git a/src/main/java/org/tianbin/netty/webSocket/server/ServerApp.java b/src/main/java/cc/tianbin/netty/webSocket/server/ServerApp.java similarity index 85% rename from src/main/java/org/tianbin/netty/webSocket/server/ServerApp.java rename to src/main/java/cc/tianbin/netty/webSocket/server/ServerApp.java index 127ed41c..1bd5dbe4 100644 --- a/src/main/java/org/tianbin/netty/webSocket/server/ServerApp.java +++ b/src/main/java/cc/tianbin/netty/webSocket/server/ServerApp.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.server; +package cc.tianbin.netty.webSocket.server; /** * @author nibnait diff --git a/src/main/java/org/tianbin/netty/webSocket/server/ServerHandler.java b/src/main/java/cc/tianbin/netty/webSocket/server/ServerHandler.java similarity index 98% rename from src/main/java/org/tianbin/netty/webSocket/server/ServerHandler.java rename to src/main/java/cc/tianbin/netty/webSocket/server/ServerHandler.java index af333229..8adbc750 100644 --- a/src/main/java/org/tianbin/netty/webSocket/server/ServerHandler.java +++ b/src/main/java/cc/tianbin/netty/webSocket/server/ServerHandler.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.server; +package cc.tianbin.netty.webSocket.server; import io.netty.channel.Channel; import io.netty.channel.ChannelHandlerContext; diff --git a/src/main/java/org/tianbin/netty/webSocket/server/ServerInitializer.java b/src/main/java/cc/tianbin/netty/webSocket/server/ServerInitializer.java similarity index 95% rename from src/main/java/org/tianbin/netty/webSocket/server/ServerInitializer.java rename to src/main/java/cc/tianbin/netty/webSocket/server/ServerInitializer.java index eee06e41..8bb5421d 100644 --- a/src/main/java/org/tianbin/netty/webSocket/server/ServerInitializer.java +++ b/src/main/java/cc/tianbin/netty/webSocket/server/ServerInitializer.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.server; +package cc.tianbin.netty.webSocket.server; import io.netty.channel.ChannelInitializer; import io.netty.channel.ChannelPipeline; diff --git a/src/main/java/org/tianbin/netty/webSocket/server/SocketServer.java b/src/main/java/cc/tianbin/netty/webSocket/server/SocketServer.java similarity index 95% rename from src/main/java/org/tianbin/netty/webSocket/server/SocketServer.java rename to src/main/java/cc/tianbin/netty/webSocket/server/SocketServer.java index 9c15ed33..659f5697 100644 --- a/src/main/java/org/tianbin/netty/webSocket/server/SocketServer.java +++ b/src/main/java/cc/tianbin/netty/webSocket/server/SocketServer.java @@ -1,4 +1,4 @@ -package org.tianbin.netty.webSocket.server; +package cc.tianbin.netty.webSocket.server; import io.netty.bootstrap.ServerBootstrap; import io.netty.channel.nio.NioEventLoopGroup; diff --git a/src/main/java/org/tianbin/redis/HyperLogLog/HyperLogLogCounting.java b/src/main/java/cc/tianbin/redis/HyperLogLog/HyperLogLogCounting.java similarity index 98% rename from src/main/java/org/tianbin/redis/HyperLogLog/HyperLogLogCounting.java rename to src/main/java/cc/tianbin/redis/HyperLogLog/HyperLogLogCounting.java index 59f2139e..0256ed1b 100644 --- a/src/main/java/org/tianbin/redis/HyperLogLog/HyperLogLogCounting.java +++ b/src/main/java/cc/tianbin/redis/HyperLogLog/HyperLogLogCounting.java @@ -1,4 +1,4 @@ -package org.tianbin.redis.HyperLogLog; +package cc.tianbin.redis.HyperLogLog; import java.util.concurrent.ThreadLocalRandom; diff --git a/src/main/java/org/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java b/src/main/java/cc/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java similarity index 98% rename from src/main/java/org/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java rename to src/main/java/cc/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java index 1ba8c619..88d7f300 100644 --- a/src/main/java/org/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java +++ b/src/main/java/cc/tianbin/redis/HyperLogLog/HyperLogLogCountingDemo.java @@ -1,4 +1,4 @@ -package org.tianbin.redis.HyperLogLog; +package cc.tianbin.redis.HyperLogLog; import java.util.concurrent.ThreadLocalRandom; diff --git a/src/main/java/org/tianbin/redis/RateLimiter/README.md b/src/main/java/cc/tianbin/redis/RateLimiter/README.md similarity index 100% rename from src/main/java/org/tianbin/redis/RateLimiter/README.md rename to src/main/java/cc/tianbin/redis/RateLimiter/README.md diff --git a/src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java b/src/main/java/cc/tianbin/redis/RateLimiter/RedisRateLimiter.java similarity index 98% rename from src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java rename to src/main/java/cc/tianbin/redis/RateLimiter/RedisRateLimiter.java index 1dc95048..63c4b9ee 100644 --- a/src/main/java/org/tianbin/redis/RateLimiter/RedisRateLimiter.java +++ b/src/main/java/cc/tianbin/redis/RateLimiter/RedisRateLimiter.java @@ -1,8 +1,8 @@ -package org.tianbin.redis.RateLimiter; +package cc.tianbin.redis.RateLimiter; +import cc.tianbin.java.IO.classpath.ResourcesReaderUtil; import com.google.common.io.ByteStreams; import io.github.nibnait.common.constants.CommonConstants; -import org.tianbin.java.IO.classpath.ResourcesReaderUtil; import redis.clients.jedis.Jedis; import redis.clients.jedis.JedisCluster; import redis.clients.jedis.JedisPool; diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java index b52137cc..5b1ee204 100644 --- a/src/main/java/common/util/CompareUtils.java +++ b/src/main/java/common/util/CompareUtils.java @@ -18,4 +18,31 @@ public static boolean compareListNode(ListNode left, ListNode right) { return left == right; } + /** + * 正序排列 + */ + public static boolean isSortAsc(int[] arr) { + if (arr == null || arr.length < 2) { + return true; + } + + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i] > arr[i + 1]) { + return false; + } + } + + return true; + } + + /** + * copy + */ + public static int[] copyArray(int[] arr) { + int[] ans = new int[arr.length]; + for (int i = 0; i < arr.length; i++) { + ans[i] = arr[i]; + } + return ans; + } } diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index 8293905a..ae807f82 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -15,8 +15,6 @@ private static double random(){ /** * 随机返回 [0,n)之间的一个int值 - * @param n - * @return */ public static int random(int n) { if (n <= 0) { @@ -27,12 +25,9 @@ public static int random(int n) { /** * 随机返回 [a,b)之间的一个double值 - * @param a - * @param b - * @return */ - public static double random(double a, double b) { - if (!(a < b)) { + public static double randomDouble(double a, double b) { + if (a >= b) { throw new IllegalArgumentException("Invalid range"); } return a + random() * (b-a); @@ -40,11 +35,8 @@ public static double random(double a, double b) { /** * 随机返回 [a,b)之间的一个int值 - * @param a - * @param b - * @return */ - public static int random(int a, int b) { + public static int randomInt(int a, int b) { if (b <= a) { throw new IllegalArgumentException("Invalid range"); } @@ -56,23 +48,16 @@ public static int random(int a, int b) { /** * 返回一个[0,100)范围的随机int型数组 - * @param a - * @return */ - public static int[] random(int[] a){ + public static int[] randomArr() { + return randomArr(random(50)); + } + + public static int[] randomArr(int arrLength) { + int[] a = new int[arrLength]; for (int i = 0; i < a.length; i++) { a[i] = random(100); } return a; } -/* public static int[] random(int[] a){ - int length = a.length; - IntStream intStream = random.ints(0,100); //创建一个int型 [0,100)范围的数字流 - - List list = intStream.limit(length).boxed().collect(Collectors.toList()); - for (int i = 0; i < length; i++) { - a[i] = list.get(i); - } - return a; - }*/ } diff --git a/src/main/java/common/util/SystemUtil.java b/src/main/java/common/util/SystemUtil.java index f2f9c84d..93fb3285 100644 --- a/src/main/java/common/util/SystemUtil.java +++ b/src/main/java/common/util/SystemUtil.java @@ -23,4 +23,12 @@ public static void sleep(int t, TimeUnit u) { } catch (InterruptedException e) { } } + + public static void printCuttingLine() { + System.out.println("================================================"); + } + + public static void printLiteCuttingLine() { + System.out.println("--------------------------------------------------"); + } } diff --git a/src/main/test/org/tianbin/Main.java b/src/main/test/cc/tianbin/Main.java similarity index 92% rename from src/main/test/org/tianbin/Main.java rename to src/main/test/cc/tianbin/Main.java index 2c45612f..7c54b82c 100644 --- a/src/main/test/org/tianbin/Main.java +++ b/src/main/test/cc/tianbin/Main.java @@ -1,4 +1,4 @@ -package org.tianbin; +package cc.tianbin; import junit.framework.TestCase; diff --git a/src/main/test/org/tianbin/excel/ExcelGen.java b/src/main/test/cc/tianbin/excel/ExcelGen.java similarity index 98% rename from src/main/test/org/tianbin/excel/ExcelGen.java rename to src/main/test/cc/tianbin/excel/ExcelGen.java index 97d8db4f..65beead4 100644 --- a/src/main/test/org/tianbin/excel/ExcelGen.java +++ b/src/main/test/cc/tianbin/excel/ExcelGen.java @@ -1,4 +1,4 @@ -package org.tianbin.excel; +package cc.tianbin.excel; import com.google.common.collect.Lists; import io.github.nibnait.common.bo.email.EmailAccount; diff --git a/src/main/test/org/tianbin/excel/ParseJson.java b/src/main/test/cc/tianbin/excel/ParseJson.java similarity index 97% rename from src/main/test/org/tianbin/excel/ParseJson.java rename to src/main/test/cc/tianbin/excel/ParseJson.java index bf5ce761..00843d96 100644 --- a/src/main/test/org/tianbin/excel/ParseJson.java +++ b/src/main/test/cc/tianbin/excel/ParseJson.java @@ -1,4 +1,4 @@ -package org.tianbin.excel; +package cc.tianbin.excel; import com.google.common.collect.Lists; import io.github.nibnait.common.bo.excel.SheetBO; diff --git a/src/main/test/org/tianbin/excel/StockDTO.java b/src/main/test/cc/tianbin/excel/StockDTO.java similarity index 97% rename from src/main/test/org/tianbin/excel/StockDTO.java rename to src/main/test/cc/tianbin/excel/StockDTO.java index 3bce28f0..620acf43 100644 --- a/src/main/test/org/tianbin/excel/StockDTO.java +++ b/src/main/test/cc/tianbin/excel/StockDTO.java @@ -1,4 +1,4 @@ -package org.tianbin.excel; +package cc.tianbin.excel; import lombok.Data; diff --git a/src/main/test/org/tianbin/java/ObjectTest.java b/src/main/test/cc/tianbin/java/ObjectTest.java similarity index 91% rename from src/main/test/org/tianbin/java/ObjectTest.java rename to src/main/test/cc/tianbin/java/ObjectTest.java index 1d174137..187138c2 100644 --- a/src/main/test/org/tianbin/java/ObjectTest.java +++ b/src/main/test/cc/tianbin/java/ObjectTest.java @@ -1,4 +1,4 @@ -package org.tianbin.java; +package cc.tianbin.java; import org.junit.Test; diff --git a/src/main/test/org/tianbin/java/OptionalTest.java b/src/main/test/cc/tianbin/java/OptionalTest.java similarity index 92% rename from src/main/test/org/tianbin/java/OptionalTest.java rename to src/main/test/cc/tianbin/java/OptionalTest.java index 311cb247..ec0e7389 100644 --- a/src/main/test/org/tianbin/java/OptionalTest.java +++ b/src/main/test/cc/tianbin/java/OptionalTest.java @@ -1,4 +1,4 @@ -package org.tianbin.java; +package cc.tianbin.java; import org.junit.Test; diff --git a/src/main/test/org/tianbin/java/SwitchCaseTest.java b/src/main/test/cc/tianbin/java/SwitchCaseTest.java similarity index 94% rename from src/main/test/org/tianbin/java/SwitchCaseTest.java rename to src/main/test/cc/tianbin/java/SwitchCaseTest.java index f801b6ca..290b91d4 100644 --- a/src/main/test/org/tianbin/java/SwitchCaseTest.java +++ b/src/main/test/cc/tianbin/java/SwitchCaseTest.java @@ -1,4 +1,4 @@ -package org.tianbin.java; +package cc.tianbin.java; import org.junit.Test; diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" similarity index 98% rename from "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" rename to "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" index 00e1b69f..084d8e42 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" +++ "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.反射; +package cc.tianbin.java.反射; import com.alibaba.fastjson.JSON; import common.model.Person; diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" similarity index 99% rename from "src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" rename to "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" index eb86ead5..7ac47540 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" +++ "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.反射; +package cc.tianbin.java.反射; import common.model.Person; import common.model.PersonDTO; diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/README.md" similarity index 100% rename from "src/main/test/org/tianbin/java/\345\217\215\345\260\204/README.md" rename to "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/README.md" diff --git "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" similarity index 97% rename from "src/main/test/org/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" rename to "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" index 814ffcdd..80518262 100644 --- "a/src/main/test/org/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" +++ "b/src/main/test/cc/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.反射; +package cc.tianbin.java.反射; import junit.framework.TestCase; import lombok.AllArgsConstructor; diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" similarity index 54% rename from "src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" rename to "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" index 24053c3c..c6704b00 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" @@ -1,22 +1,42 @@ -package org.tianbin.java.集合; +package cc.tianbin.java.集合; +import com.google.common.collect.Lists; import common.model.Person; +import io.github.nibnait.common.utils.DataUtils; +import lombok.extern.slf4j.Slf4j; import org.junit.Test; import java.util.ArrayList; import java.util.Comparator; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; /** * Created by nibnait on 2021/05/20 */ +@Slf4j public class ListStreamTest { @Test - public void test01() { + public void groupBy() { + List personList = Lists.newArrayList( + new Person("tom", 1), + new Person("jerry", 2), +// new Person(null, 4), + new Person("", 3) + ); + Map> owner2ItemsIdMap = personList.stream() + .collect(Collectors.groupingBy(Person::getName, Collectors.mapping(Person::getAge, Collectors.toList()))); + log.info(DataUtils.toJsonStringObject(owner2ItemsIdMap)); + + } + + + @Test + public void comparing() { List personList = new ArrayList<>(); Person p1 = new Person(); @@ -29,19 +49,18 @@ public void test01() { p2.setAge(2); personList.add(p2); - System.out.println(personList); List collect = personList.stream() .sorted(Comparator.comparing(Person::getAge)) .map(Person::getAge) .collect(Collectors.toList()); - System.out.println(collect); + System.out.println("(默认)正序: " + collect); List collectReversed = personList.stream() .sorted(Comparator.comparing(Person::getAge).reversed()) .map(Person::getAge) .collect(Collectors.toList()); - System.out.println(collectReversed); + System.out.println("倒序: "+ collectReversed); } } diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListTest.java" similarity index 92% rename from "src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" rename to "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListTest.java" index 3d774962..110e7978 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/ListTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.集合; +package cc.tianbin.java.集合; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; @@ -7,6 +7,8 @@ import com.google.common.collect.Sets; import common.model.Person; import io.github.nibnait.common.utils.DataUtils; +import io.github.nibnait.common.utils.compare.CompareUtils; +import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; @@ -186,11 +188,30 @@ public void copyListProperties() { @Test public void testSubList() { + List imgList = Lists.newArrayList(1, 2, 3, 4, 5); + List subImgList = imgList.subList(1, imgList.size()); + Assert.assertTrue(CompareUtils.match(subImgList, Lists.newArrayList(2,3,4,5))); + + imgList = Lists.newArrayList(1); + subImgList = imgList.subList(1, imgList.size()); + Assert.assertTrue(CompareUtils.match(subImgList, Lists.newArrayList())); + List list = Lists.newArrayList(); - for (int i = 1; i < 33; i++) { + for (int i = 0; i < 33; i++) { list.add(i); } + /** + * subList 是 左闭右开区间 + */ + List result = list.subList(0, 2); + List expect = Lists.newArrayList(0, 1); + Assert.assertTrue(CompareUtils.match(result, expect)); + + result = list.subList(1, 2); + expect = Lists.newArrayList(1); + Assert.assertTrue(CompareUtils.match(result, expect)); + int pageNum = 1; int pageSize = 10; int fromIndex = pageNum * pageSize; @@ -205,12 +226,12 @@ public void testSubList() { pageNum = 3; fromIndex = pageNum * pageSize; toIndex = fromIndex + pageSize; - System.out.println(list.subList(fromIndex, toIndex)); +// System.out.println(list.subList(fromIndex, toIndex)); pageNum = 4; fromIndex = pageNum * pageSize; toIndex = fromIndex + pageSize; - System.out.println(list.subList(fromIndex, toIndex)); +// System.out.println(list.subList(fromIndex, toIndex)); } @Test diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" similarity index 78% rename from "src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" rename to "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" index ac8a9211..de586032 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/MapTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" @@ -1,6 +1,5 @@ -package org.tianbin.java.集合; +package cc.tianbin.java.集合; -import junit.framework.TestCase; import common.model.Person; import org.junit.Test; @@ -14,6 +13,18 @@ */ public class MapTest { + @Test + public void test01() { + HashMap map = new HashMap<>(); + System.out.println(map); + buildMap(map); + System.out.println(map); + } + + private void buildMap(HashMap map) { + map.put(1, 1); + } + @Test public void testMapValue() { diff --git "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" similarity index 97% rename from "src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" rename to "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" index ebd0ad4a..aac4d5e5 100644 --- "a/src/main/test/org/tianbin/java/\351\233\206\345\220\210/SetTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" @@ -1,4 +1,4 @@ -package org.tianbin.java.集合; +package cc.tianbin.java.集合; import com.google.common.collect.Lists; import com.google.common.collect.Sets; diff --git a/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java b/src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java similarity index 98% rename from src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java rename to src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java index a291706e..9617de5a 100644 --- a/src/main/test/org/tianbin/redis/RateLimiter/RedisRateLimiterTest.java +++ b/src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java @@ -1,4 +1,4 @@ -package org.tianbin.redis.RateLimiter; +package cc.tianbin.redis.RateLimiter; import io.github.nibnait.common.utils.date.DateTimeConvertUtils; import org.junit.After; diff --git a/src/main/test/org/tianbin/temp/DataGen.java b/src/main/test/cc/tianbin/temp/DataGen.java similarity index 99% rename from src/main/test/org/tianbin/temp/DataGen.java rename to src/main/test/cc/tianbin/temp/DataGen.java index b87f2cd6..dc0951a4 100644 --- a/src/main/test/org/tianbin/temp/DataGen.java +++ b/src/main/test/cc/tianbin/temp/DataGen.java @@ -1,4 +1,4 @@ -package org.tianbin.temp; +package cc.tianbin.temp; import org.junit.Test; diff --git a/src/main/test/org/tianbin/temp/JsonParseTest.java b/src/main/test/cc/tianbin/temp/JsonParseTest.java similarity index 97% rename from src/main/test/org/tianbin/temp/JsonParseTest.java rename to src/main/test/cc/tianbin/temp/JsonParseTest.java index a0a54216..77fe3a8e 100644 --- a/src/main/test/org/tianbin/temp/JsonParseTest.java +++ b/src/main/test/cc/tianbin/temp/JsonParseTest.java @@ -1,4 +1,4 @@ -package org.tianbin.temp; +package cc.tianbin.temp; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; diff --git a/src/main/test/common/util/ExcelReadUtilsTest.java b/src/main/test/common/util/ExcelReadUtilsTest.java new file mode 100644 index 00000000..6b94fd66 --- /dev/null +++ b/src/main/test/common/util/ExcelReadUtilsTest.java @@ -0,0 +1,17 @@ +package common.util; + +import org.junit.Test; + +import java.io.IOException; + +/** + * Created by nibnait on 2021/03/26 + */ +public class ExcelReadUtilsTest { + + @Test + public void read() throws IOException { + + } + +} diff --git a/src/main/test/javalang/test/FinallyTest.java b/src/main/test/javalang/test/FinallyTest.java new file mode 100644 index 00000000..83fe27bc --- /dev/null +++ b/src/main/test/javalang/test/FinallyTest.java @@ -0,0 +1,45 @@ +package javalang.test; + +import io.github.nibnait.common.exception.ClientViewException; +import org.junit.Test; + +/** + * Created by nibnait on 2022/05/11 + */ +public class FinallyTest { + + @Test + public void test01() { + try { + System.out.println("try"); + throw new RuntimeException("123"); + } catch (Exception e) { + System.out.println("catch"); + return; + } finally { + System.out.println("finally"); + } + } + + @Test + public void test02() { + try { + System.out.println("try"); + return; + } catch (Exception e) { + System.out.println("catch"); + } finally { + System.out.println("finally"); + } + } + + @Test + public void test03() { + try { + throw new ClientViewException("123"); + } finally { + System.out.println(111); + } + + } +} diff --git a/src/main/test/org/tianbin/excel/ExcelRead.java b/src/main/test/org/tianbin/excel/ExcelRead.java deleted file mode 100644 index a8c1d99d..00000000 --- a/src/main/test/org/tianbin/excel/ExcelRead.java +++ /dev/null @@ -1,10 +0,0 @@ -package org.tianbin.excel; - -import org.junit.Test; - -/** - * Created by nibnait on 2021/03/26 - */ -public class ExcelRead { - -} From c273bbbb00cc41eb16fc7c5dcf5e797034e18cbb Mon Sep 17 00:00:00 2001 From: tianbin Date: Fri, 24 Jun 2022 07:51:50 +0800 Subject: [PATCH 12/36] =?UTF-8?q?=E5=B7=A6=E7=A5=9E=20=E4=BD=93=E7=B3=BB?= =?UTF-8?q?=E5=AD=A6=E4=B9=A0=E7=8F=AD=20day1,=20=E4=BA=8C=E5=88=86?= =?UTF-8?q?=E6=B3=95=E3=80=81=E5=BC=82=E6=88=96=E8=BF=90=E7=AE=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class01/Code03_SelectionSort.java | 3 +- .../a_primary/class01/Code04_BubbleSort.java | 3 +- .../class01/Code05_InsertionSort.java | 3 +- .../algorithmzuo/a_primary/class01/README.md | 63 ------------- .../algorithmzuo/a_primary/class02/README.md | 15 --- .../a_primary/class03/Code01_BSExist.java | 70 ++++++++++++++ .../a_primary/class03/Code02_BSNearLeft.java | 74 +++++++++++++++ .../a_primary/class03/Code03_BSNearRight.java | 72 +++++++++++++++ .../algorithmzuo/a_primary/class03/README.md | 24 ----- .../algorithmzuo/a_primary/class04/README.md | 38 -------- .../algorithmzuo/a_primary/class05/README.md | 11 --- .../algorithmzuo/a_primary/class06/README.md | 27 ------ .../algorithmzuo/a_primary/class07/README.md | 20 ---- .../algorithmzuo/a_primary/class08/README.md | 14 --- .../algorithm_basic/class01/README.md | 2 - .../README.md | 0 .../b_algorithm_basic/class01/README.md | 1 + .../class02/Code01_Swap.java | 71 ++++++++++++++ .../class02/Code02_EvenTimesOddTimes.java | 66 +++++++++++++ .../b_algorithm_basic/class02/Code03_KM.java | 92 +++++++++++++++++++ .../README.md | 0 src/main/java/common/CommonConstants.java | 12 +++ src/main/java/common/util/SysOut.java | 4 + src/main/java/common/util/SysRandom.java | 19 ++-- 24 files changed, 480 insertions(+), 224 deletions(-) delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md delete mode 100644 src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md rename src/main/java/algorithm_practice/algorithmzuo/{algorithm_basic => b_algorithm_basic}/README.md (100%) create mode 100644 src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md create mode 100644 src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java create mode 100644 src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java rename src/main/java/algorithm_practice/algorithmzuo/{for_great_offer => c_for_great_offer}/README.md (100%) create mode 100644 src/main/java/common/CommonConstants.java diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java index e36ae15f..5890f1f0 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java @@ -1,5 +1,6 @@ package algorithm_practice.algorithmzuo.a_primary.class01; +import common.CommonConstants; import common.util.CompareUtils; import common.util.SysOut; import common.util.SysRandom; @@ -15,7 +16,7 @@ public class Code03_SelectionSort { @Test public void testCase() { - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { int arr[] = SysRandom.randomArr(); SysOut.printArray(arr); int[] tmp = CompareUtils.copyArray(arr); diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java index bf466253..c88ba6a5 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java @@ -1,5 +1,6 @@ package algorithm_practice.algorithmzuo.a_primary.class01; +import common.CommonConstants; import common.util.CompareUtils; import common.util.SysOut; import common.util.SysRandom; @@ -15,7 +16,7 @@ public class Code04_BubbleSort { @Test public void testCase() { - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { int arr[] = SysRandom.randomArr(); SysOut.printArray(arr); int[] tmp = CompareUtils.copyArray(arr); diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java index f3861615..15aff3ea 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java @@ -1,5 +1,6 @@ package algorithm_practice.algorithmzuo.a_primary.class01; +import common.CommonConstants; import common.util.CompareUtils; import common.util.SysOut; import common.util.SysRandom; @@ -15,7 +16,7 @@ public class Code05_InsertionSort { @Test public void testCase() { - for (int i = 0; i < 10; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { int arr[] = SysRandom.randomArr(); SysOut.printArray(arr); int[] tmp = CompareUtils.copyArray(arr); diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md index f28b9b54..e69de29b 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md @@ -1,63 +0,0 @@ -## 内容: -- 讲解二进制、位运算 -- 介绍什么是算法 -- 讲解冒泡、选择、插入排序 -## 题目: -### 实现打印一个整数的二进制 -```java -/** - * 无符号整数 - */ -public void print(int num) { - for(int i=31; i>=0; i--) { - System.out.print( num & (1< 0; end--) { - for (int i = 0; i < end; i++) { - if (arr[i] > arr[i + 1]) { - swap(arr, i, i + 1); - } - } -} -``` -### 实现插入排序 -打扑克 抓牌、码牌 -```java -for (int end = 1; end < length; end++) { - int newNumIndex = end; - while (newNumIndex - 1 >= 0 && arr[newNumIndex - 1] > arr[newNumIndex]) { - swap(arr, newNumIndex - 1, newNumIndex); - newNumIndex--; - } -} -``` diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md deleted file mode 100644 index 3f247bf7..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class02/README.md +++ /dev/null @@ -1,15 +0,0 @@ -## 内容: -- 什么是数据结构、组成各种数据结构最基本的元件 -- 前缀和数组 -- 随机函数 -- 对数器的使用 -## 题目: -### 实现前缀和数组 - -### 如何用1~5的随机函数加工出1~7的随机函数 - -### 如何用a~b的随机函数加工出c~d的随机函数 - -### 展示对数器的使用 - -### 如何把不等概率随机函数变成等概率随机函数 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java new file mode 100644 index 00000000..615e5216 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java @@ -0,0 +1,70 @@ +package algorithm_practice.algorithmzuo.a_primary.class03; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import io.github.nibnait.common.utils.DataUtils; +import org.junit.Test; + +import java.util.Arrays; + +/** + * 二分查找 + * Created by nibnait on 2022/06/21 + */ +public class Code01_BSExist { + + @Test + public void testCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + int[] arr = SysRandom.randomArr(); + Arrays.sort(arr); + int num = 11; + int ans = find(arr, num); + int violenceAns = violenceBreak(arr, num); + if (violenceAns != ans) { + SysOut.println("\n arr: %s \n num: %s \n violenceAns: %s, ans: %s", DataUtils.toJsonStringArray(arr), + num, + violenceAns, ans); + } else { + SysOut.println("OK"); + } + } + + } + + private int find(int[]arr, int num) { + if (arr == null || arr.length == 0) { + return -1; + } + + int left = 0; + int right = arr.length - 1; + while (left <= right) { + int mid = (left + right) / 2; + if (arr[mid] == num) { + return mid; + } else if (arr[mid] > num) { + right = mid - 1; + } else { + left = mid + 1; + } + } + return -1; + } + + /** + * 暴力查找 + */ + private int violenceBreak(int[]arr, int num) { + if (arr == null || arr.length == 0) { + return -1; + } + for (int i = 0; i < arr.length; i++) { + if (arr[i] == num) { + return i; + } + } + return -1; + } +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java new file mode 100644 index 00000000..b3178597 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java @@ -0,0 +1,74 @@ +package algorithm_practice.algorithmzuo.a_primary.class03; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import io.github.nibnait.common.utils.DataUtils; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/06/21 + */ +public class Code02_BSNearLeft { + + @Test + public void testCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + int[] arr = SysRandom.randomArr(); + Arrays.sort(arr); + int num = 11; + int ans = mostLeftNoLessNumIndex(arr, num); + int violenceAns = violenceBreak(arr, num); + if (violenceAns != ans) { + SysOut.println("\n arr: %s \n num: %s \n violenceAns: %s, ans: %s", DataUtils.toJsonStringArray(arr), + num, + violenceAns, ans); + } else { + SysOut.println("OK"); + } + } + + } + + /** + * arr有序的,求 =num 最左 + */ + private int mostLeftNoLessNumIndex(int[]arr, int num) { + if (arr == null || arr.length == 0) { + return -1; + } + + int left = 0; + int right = arr.length - 1; + int ans = -1; + while (left <= right) { + int mid = (left + right) / 2; + if (arr[mid] >= num) { + if (arr[mid] == num) { + ans = mid; + } + right = mid - 1; + } else { + left = mid + 1; + } + } + return ans; + } + + /** + * 暴力查找 + */ + private int violenceBreak(int[]arr, int num) { + if (arr == null || arr.length == 0) { + return -1; + } + for (int i = 0; i < arr.length; i++) { + if (arr[i] == num) { + return i; + } + } + return -1; + } +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java new file mode 100644 index 00000000..09da1d19 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java @@ -0,0 +1,72 @@ +package algorithm_practice.algorithmzuo.a_primary.class03; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import io.github.nibnait.common.utils.DataUtils; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/06/21 + */ +public class Code03_BSNearRight { + + @Test + public void testCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + int[] arr = SysRandom.randomArr(); + Arrays.sort(arr); + int num = 11; + int ans = nearestIndex(arr, num); + int violenceAns = violenceBreak(arr, num); + if (violenceAns != ans) { + SysOut.println("\n arr: %s \n num: %s \n violenceAns: %s, ans: %s", DataUtils.toJsonStringArray(arr), + num, + violenceAns, ans); + } else { + SysOut.println("OK"); + } + } + + } + + /** + * 在arr上,找满足<=value的最右位置 + */ + private int nearestIndex(int[] arr, int num) { + if (arr == null || arr.length == 0) { + return -1; + } + + int left = 0; + int right = arr.length - 1; + int ans = -1; + while (left <= right) { + int mid = (left + right) / 2; + if (arr[mid] <= num) { + ans = mid; + left = mid + 1; + } else { + right = mid - 1; + } + } + return ans; + } + + /** + * 暴力查找 + */ + private int violenceBreak(int[] arr, int num) { + if (arr == null || arr.length == 0) { + return -1; + } + for (int i = arr.length - 1; i >= 0; i--) { + if (arr[i] <= num) { + return i; + } + } + return -1; + } +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md deleted file mode 100644 index de321050..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/README.md +++ /dev/null @@ -1,24 +0,0 @@ -# 03 介绍二分法,介绍时间复杂度、动态数组、哈希表和有序表 - -## 内容: - - 二分法 - - 使用二分法解决不同的题目 - - 时间复杂度 - - 动态数组 - - 按值传递、按引用传递 - - 哈希表 - - 有序表 - -## 题目: - -### 有序数组中找到num - -### 有序数组中找到>=num最左的位置 - -### 有序数组中找到<=num最右的位置 - -### 局部最小值问题 - -### 哈希表使用的code讲解 - -### 有序表使用的code讲解 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md deleted file mode 100644 index 2de6cfba..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class04/README.md +++ /dev/null @@ -1,38 +0,0 @@ -# 04 链表相关的简单面试题 - -## 内容: - - 单双链表的定义 - - 栈、队列 - - 双端队列 - -## 题目: - -### 反转单链表 - -### 反转双链表 - -### 用单链表实现队列 - -### 用单链表实现栈 - -### 用双链表实现双端队列 - -### K个节点的组内逆序调整问题: -给定一个单链表的头节点head,和一个正数k -实现k个节点的小组内部逆序,如果最后一组不够k个就不调整 -例子: -调整前:1 -> 2 -> 3 -> 4 -> 5 -> 6 -> 7 -> 8,k = 3 -调整后:3 -> 2 -> 1 -> 6 -> 5 -> 4 -> 7 -> 8 - -### 两个链表相加问题 -给定两个链表的头节点head1和head2, -认为从左到右是某个数字从低位到高位,返回相加之后的链表 -例子 4 -> 3 -> 6 2 -> 5 -> 3 -返回 6 -> 8 -> 9 -解释 634 + 352 = 986 - -### 两个有序链表的合并 -给定两个有序链表的头节点head1和head2, -返回合并之后的大链表,要求依然有序 -例子 1 -> 3 -> 3 -> 5 -> 7 2 -> 2 -> 3 -> 3-> 7 -返回 1 -> 2 -> 2 -> 3 -> 3 -> 3 -> 3 -> 5 -> 7 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md deleted file mode 100644 index 8cce247d..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class05/README.md +++ /dev/null @@ -1,11 +0,0 @@ -# 05 位图、位运算实现加减乘除 - -## 内容: - - 位图 - - 位运算使用的进一步学习:实现加减乘除 - -## 题目: - -### 现场写位图的code、讲解 - -## 位运算的加减乘除 \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md deleted file mode 100644 index a2327112..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class06/README.md +++ /dev/null @@ -1,27 +0,0 @@ -# 06 比较器、优先级队列、二叉树 - -## 内容: - - 比较器 - - 优先级队列 - - 二叉树的基本遍历 - - 二叉树的递归套路 - -## 题目: - -### 合并多个有序链表 -Leetcode原题,https://leetcode.com/problems/merge-k-sorted-lists - -### 判断两颗树是否结构相同 -Leetcode原题,https://leetcode.com/problems/same-tree - -### 判断一棵树是否是镜面树 -Leetcode原题,https://leetcode.com/problems/symmetric-tree - -### 返回一棵树的最大深度 -Leetcode原题,https://leetcode.com/problems/maximum-depth-of-binary-tree - -### 用先序数组和中序数组重建一棵树 -Leetcode原题,https://leetcode.com/problems/construct-binary-tree-from-preorder-and-inorder-traversal - -### 用code展示比较器的使用 -二叉树先序、中序、后序遍历的代码实现、介绍递归序 diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md deleted file mode 100644 index 2912366d..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class07/README.md +++ /dev/null @@ -1,20 +0,0 @@ -# 07 继续二叉树的很多题目 - -## 内容: - - 进一步讲解二叉树题目,来熟悉二叉树 - -## 题目: - -### 二叉树按层遍历并收集节点 -Leetcode原题,https://leetcode.com/problems/binary-tree-level-order-traversal-ii - -### 判断是否是平衡搜索二叉树 -Leetcode原题,https://leetcode.com/problems/balanced-binary-tree - -### 在二叉树上能否组成路径和 -Leetcode原题,https://leetcode.com/problems/path-sum - -### 在二叉树上收集所有达标的路径和 -Leetcode原题,https://leetcode.com/problems/path-sum-ii - -### 判断二叉树是否是搜索二叉树 \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md b/src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md deleted file mode 100644 index 7efeae43..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class08/README.md +++ /dev/null @@ -1,14 +0,0 @@ -# 08 介绍归并排序和快速排序 - -## 内容: - - 讲解一个位运算的题目 - - 归并排序 - - 快速排序 - -## 题目: - -### 不要用任何比较判断,返回两个数中较大的数 - -### 归并排序的递归实现和非递归实现 - -### 快速排序的递归实现和非递归实现 \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md b/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md deleted file mode 100644 index a9bd7fde..00000000 --- a/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/class01/README.md +++ /dev/null @@ -1,2 +0,0 @@ -# - diff --git a/src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/README.md b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/README.md similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/algorithm_basic/README.md rename to src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/README.md diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md new file mode 100644 index 00000000..dfa9cbdb --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md @@ -0,0 +1 @@ +# [01 时间复杂度、空间复杂度、对数器和二分法](https://tianbin.cc) \ No newline at end of file diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java new file mode 100644 index 00000000..3d0a3938 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java @@ -0,0 +1,71 @@ +package algorithm_practice.algorithmzuo.b_algorithm_basic.class02; + +public class Code01_Swap { + + public static void main(String[] args) { + + + + + + + int a = 16; + int b = 603; + + System.out.println(a); + System.out.println(b); + + + a = a ^ b; + b = a ^ b; + a = a ^ b; + + + System.out.println(a); + System.out.println(b); + + + + + int[] arr = {3,1,100}; + + int i = 0; + int j = 0; + + arr[i] = arr[i] ^ arr[j]; + arr[j] = arr[i] ^ arr[j]; + arr[i] = arr[i] ^ arr[j]; + + System.out.println(arr[i] + " , " + arr[j]); + + + + + + + + + + System.out.println(arr[0]); + System.out.println(arr[2]); + + swap(arr, 0, 0); + + System.out.println(arr[0]); + System.out.println(arr[2]); + + + + } + + + public static void swap (int[] arr, int i, int j) { + // arr[0] = arr[0] ^ arr[0]; + arr[i] = arr[i] ^ arr[j]; + arr[j] = arr[i] ^ arr[j]; + arr[i] = arr[i] ^ arr[j]; + } + + + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java new file mode 100644 index 00000000..045bd5a3 --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java @@ -0,0 +1,66 @@ +package algorithm_practice.algorithmzuo.b_algorithm_basic.class02; + +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/06/22 + */ +public class Code02_EvenTimesOddTimes { + + // arr中,只有一种数,出现奇数次 + @Test + public void printOddTimesNum1() { + int[] arr = {3, 3, 2, 3, 1, 1, 1, 3, 1, 1, 1}; + + if (arr.length == 0) { + return; + } + if (arr.length == 1) { + SysOut.println(arr[0]); + } + int eor = arr[0]; + for (int i = 1; i < arr.length; i++) { + eor ^= arr[i]; + } + SysOut.println(eor); + } + + // 一个int类型的数,提取出它二进制中最右侧的1来 + @Test + public void bit1counts() { + int num = 1744; + // 011011010000 + // 100100110000 + + int rightOne = num & (~num + 1); + // 000000010000 + + SysOut.println(rightOne); + + } + + // arr中,有两种数,出现奇数次 + @Test + public void printOddTimesNum2() { + int[] arr = {4, 3, 4, 2, 2, 2, 4, 1, 1, 1, 3, 3, 1, 1, 1, 4, 2, 2}; + + int eor = arr[0]; + for (int i = 1; i < arr.length; i++) { + eor ^= arr[i]; + } + + // 此时 eor = a ^ b + // 找出 eor 的二进制最右面的那个1的位置。a 和 b 在 rightOne 位置一定一个是0,一个是1 + int rightOne = eor & (-eor); + int a = 0; + for (int i = 0; i < arr.length; i++) { + if ((arr[i] & rightOne) != 0) { + a ^= arr[i]; + } + } + + SysOut.println("a = %s, b = %s", a, a ^ eor); + } + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java new file mode 100644 index 00000000..b8963edd --- /dev/null +++ b/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java @@ -0,0 +1,92 @@ +package algorithm_practice.algorithmzuo.b_algorithm_basic.class02; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import io.github.nibnait.common.utils.DataUtils; +import org.junit.Test; + +import static common.util.SwapUtil.swap; + +/** + * Created by nibnait on 2022/06/23 + */ +public class Code03_KM { + + @Test + public void testCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_MIN; i++) { + int a = SysRandom.random(9) + 1; + int b = SysRandom.random(9) + 1; + int k = Math.min(a, b); + int m = Math.max(a, b); + if (k == m) { + m++; + } + + int mTimeNumCount = SysRandom.random(9); + int arrLength = k + m * mTimeNumCount; + int[] arr = new int[arrLength]; + + // 填充出现了 k 次的数 + int kTimesNum = SysRandom.randomInt(-200, 200); + for (int j = 0; j < k; j++) { + arr[j] = kTimesNum; + } + // 填充出现了 m 次的数 + int index = k; + int mTimesNum = SysRandom.randomInt(-200, 200); + for (int l = 0; l < m; l++) { + for (int n = 0; n < mTimeNumCount; n++) { + arr[index++] = mTimesNum; + } + } + + // j 位置的数和 arr里任意位置的的一个数 + for (int j = 0; j < arrLength; j++) { + int randomIndex = SysRandom.random(arrLength); + swap(arr, j, randomIndex); + } + + int ans = onlyKTimes(arr, k, m); + if (ans != kTimesNum) { + SysOut.println("%s, %s, %s \n kTimesNum=%s, ans=%s", + "new int[]" + DataUtils.toJsonStringArray(arr).replace("[", "{").replace("]", "}"), k, m, + kTimesNum, ans); + } + } + } + + @Test + public void testSpecialCase() { + int ans = onlyKTimes( + new int[]{1, 1, 2, 3, 2}, 1, 2 + ); + + SysOut.println(ans); + } + + // 请保证arr中,只有一种数出现了K次,其他数都出现了M次 + private int onlyKTimes(int[] arr, int k, int m) { + + int[] t = new int[32]; + for (int num : arr) { + for (int i = 0; i < 32; i++) { + if (((num >> i) & 1) == 1) { + // num 在 i 位置上是1,则 t[i] ++ + t[i]++; + } + } + } + + int ans = 0; + for (int i = 0; i < 32; i++) { + if (t[i] % m != 0) { + // ans 的第i位置上有1 + ans |= (1 << i); + } + } + + return ans; + } +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/for_great_offer/README.md b/src/main/java/algorithm_practice/algorithmzuo/c_for_great_offer/README.md similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/for_great_offer/README.md rename to src/main/java/algorithm_practice/algorithmzuo/c_for_great_offer/README.md diff --git a/src/main/java/common/CommonConstants.java b/src/main/java/common/CommonConstants.java new file mode 100644 index 00000000..c4deec72 --- /dev/null +++ b/src/main/java/common/CommonConstants.java @@ -0,0 +1,12 @@ +package common; + +/** + * Created by nibnait on 2022/06/21 + */ +public class CommonConstants { + + public static final Integer TEST_CASE_COUNT_MIN = 10; + public static final Integer TEST_CASE_COUNT = 500000; + + +} diff --git a/src/main/java/common/util/SysOut.java b/src/main/java/common/util/SysOut.java index 85c0fc45..0b5302dd 100644 --- a/src/main/java/common/util/SysOut.java +++ b/src/main/java/common/util/SysOut.java @@ -14,6 +14,10 @@ public static void print(String format, Object... args) { System.out.print(String.format(format, args)); } + public static void println(Object o) { + System.out.println(o); + } + public static void println(String format, Object... args) { System.out.println(String.format(format, args)); } diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index ae807f82..e8e566ed 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -1,5 +1,7 @@ package common.util; +import io.github.nibnait.common.utils.DataUtils; + import java.util.Random; /** @@ -7,10 +9,13 @@ */ public class SysRandom { - private static Random random = new Random(); //伪随机数发生器 + private static final Random random = new Random(); //伪随机数发生器 + + private static final Integer RANDOM_MAX_VALUE = 1000; + private static final String INVALID_RANGE = "Invalid range, a: {}, b: {}"; - private static double random(){ - return random.nextDouble(); + private static double random() { + return Math.random() * RANDOM_MAX_VALUE; } /** @@ -28,9 +33,9 @@ public static int random(int n) { */ public static double randomDouble(double a, double b) { if (a >= b) { - throw new IllegalArgumentException("Invalid range"); + throw new IllegalArgumentException(DataUtils.format(INVALID_RANGE, a, b)); } - return a + random() * (b-a); + return a + random() * (b - a); } /** @@ -38,10 +43,10 @@ public static double randomDouble(double a, double b) { */ public static int randomInt(int a, int b) { if (b <= a) { - throw new IllegalArgumentException("Invalid range"); + throw new IllegalArgumentException(DataUtils.format(INVALID_RANGE, a, b)); } if ((long) b - a >= Integer.MAX_VALUE) { - throw new IllegalArgumentException("Invalid range"); + throw new IllegalArgumentException(DataUtils.format(INVALID_RANGE, a, b)); } return a + random(b - a); } From 9d6bccc9b3f59907cabfa71e2df9bcd9f964df2a Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 4 Jul 2022 07:59:41 +0800 Subject: [PATCH 13/36] =?UTF-8?q?feat=20=E8=B0=83=E6=95=B4=E7=9B=AE?= =?UTF-8?q?=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../algorithm_practice/algorithmzuo/README.md | 3 ++- .../README.md" | 0 .../class01/Code01_PrintBinary.java" | 2 +- .../class01/Code02_SumOfFactorial.java" | 2 +- .../class01/Code03_SelectionSort.java" | 2 +- .../class01/Code04_BubbleSort.java" | 2 +- .../class01/Code05_InsertionSort.java" | 2 +- .../class01/README.md" | 0 .../class03/Code01_BSExist.java" | 2 +- .../class03/Code02_BSNearLeft.java" | 2 +- .../class03/Code03_BSNearRight.java" | 2 +- .../README.md" | 0 .../class01/README.md" | 0 .../class02/Code01_Swap.java" | 2 +- .../class02/Code02_EvenTimesOddTimes.java" | 2 +- .../class02/Code03_KM.java" | 2 +- .../class03/Code01_ReverseList.java" | 17 +++++++++++++++++ .../README.md" | 0 18 files changed, 30 insertions(+), 12 deletions(-) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" (100%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" (95%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" (90%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" (95%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" (95%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" (95%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/README.md" (100%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" (96%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" (96%) rename src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java => "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" (96%) rename src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/README.md => "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" (100%) rename src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md => "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" (100%) rename src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java => "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" (92%) rename src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java => "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" (96%) rename src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java => "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" (97%) create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" rename src/main/java/algorithm_practice/algorithmzuo/c_for_great_offer/README.md => "src/main/java/algorithm_practice/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" (100%) diff --git a/src/main/java/algorithm_practice/algorithmzuo/README.md b/src/main/java/algorithm_practice/algorithmzuo/README.md index e8df862d..2ab6457f 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/README.md +++ b/src/main/java/algorithm_practice/algorithmzuo/README.md @@ -1,4 +1,5 @@ # 跟着左神写算法 -笔记: \ No newline at end of file +笔记: + diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/README.md rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" similarity index 95% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" index 657a0040..95ade597 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code01_PrintBinary.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class01; +package algorithm_practice.algorithmzuo.a_新手班.class01; import common.util.SystemUtil; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" similarity index 90% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" index d6482de4..17fe8ba3 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code02_SumOfFactorial.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class01; +package algorithm_practice.algorithmzuo.a_新手班.class01; public class Code02_SumOfFactorial { diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" similarity index 95% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" index 5890f1f0..db653a0e 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code03_SelectionSort.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class01; +package algorithm_practice.algorithmzuo.a_新手班.class01; import common.CommonConstants; import common.util.CompareUtils; diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" similarity index 95% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" index c88ba6a5..f7ecc138 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code04_BubbleSort.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class01; +package algorithm_practice.algorithmzuo.a_新手班.class01; import common.CommonConstants; import common.util.CompareUtils; diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" similarity index 95% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" index 15aff3ea..b1fac591 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/Code05_InsertionSort.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class01; +package algorithm_practice.algorithmzuo.a_新手班.class01; import common.CommonConstants; import common.util.CompareUtils; diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/README.md" similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class01/README.md rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/README.md" diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" similarity index 96% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" index 615e5216..f51d7438 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code01_BSExist.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class03; +package algorithm_practice.algorithmzuo.a_新手班.class03; import common.CommonConstants; import common.util.SysOut; diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" similarity index 96% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" index b3178597..76933ad9 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code02_BSNearLeft.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class03; +package algorithm_practice.algorithmzuo.a_新手班.class03; import common.CommonConstants; import common.util.SysOut; diff --git a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" similarity index 96% rename from src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java rename to "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" index 09da1d19..3b60c9f8 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/a_primary/class03/Code03_BSNearRight.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_primary.class03; +package algorithm_practice.algorithmzuo.a_新手班.class03; import common.CommonConstants; import common.util.SysOut; diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/README.md "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/README.md rename to "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class01/README.md rename to "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" similarity index 92% rename from src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java rename to "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" index 3d0a3938..f9cd64b2 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code01_Swap.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_algorithm_basic.class02; +package algorithm_practice.algorithmzuo.b_体系学习班.class02; public class Code01_Swap { diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" similarity index 96% rename from src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java rename to "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" index 045bd5a3..55940e57 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code02_EvenTimesOddTimes.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_algorithm_basic.class02; +package algorithm_practice.algorithmzuo.b_体系学习班.class02; import common.util.SysOut; import org.junit.Test; diff --git a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" similarity index 97% rename from src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java rename to "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" index b8963edd..44833745 100644 --- a/src/main/java/algorithm_practice/algorithmzuo/b_algorithm_basic/class02/Code03_KM.java +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_algorithm_basic.class02; +package algorithm_practice.algorithmzuo.b_体系学习班.class02; import common.CommonConstants; import common.util.SysOut; diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" new file mode 100644 index 00000000..4a140aa9 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" @@ -0,0 +1,17 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import org.junit.Test; + +/** + * Created by nibnait on 2022/06/24 + */ +public class Code01_ReverseList { + + @Test + public void testCase() { + + } + + + +} diff --git a/src/main/java/algorithm_practice/algorithmzuo/c_for_great_offer/README.md "b/src/main/java/algorithm_practice/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/c_for_great_offer/README.md rename to "src/main/java/algorithm_practice/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" From 1a9aea19e49affe1eb3d0e309a74d903b2048893 Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 6 Jul 2022 07:01:28 +0800 Subject: [PATCH 14/36] =?UTF-8?q?class03=20=E7=BF=BB=E8=BD=AC=E9=93=BE?= =?UTF-8?q?=E8=A1=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\345\244\215\345\205\203\347\264\240.java" | 16 +- ...\346\225\260\347\233\270\345\212\240.java" | 50 +++--- ...\344\270\252\350\212\202\347\202\271.java" | 26 +-- ...\347\232\204\350\212\202\347\202\271.java" | 32 ++-- ...\350\275\254\351\223\276\350\241\250.java" | 26 +-- ...350\275\254\351\223\276\350\241\2502.java" | 40 ++--- ...\345\205\245\346\216\222\345\272\217.java" | 34 ++-- ...\345\272\217\351\223\276\350\241\250.java" | 34 ++-- ...\350\275\254\351\223\276\350\241\250.java" | 32 ++-- ...\347\232\204\347\273\223\347\202\271.java" | 16 +- ...\345\201\266\351\223\276\350\241\250.java" | 62 +++---- ...\351\227\264\347\273\223\347\202\271.java" | 12 +- ...\345\215\260\351\223\276\350\241\250.java" | 26 +-- ...\350\241\250\347\273\223\347\202\271.java" | 29 ++-- ...\344\270\252\347\273\223\347\202\271.java" | 20 +-- ...\350\275\254\351\223\276\350\241\250.java" | 44 ++--- ...\347\232\204\351\223\276\350\241\250.java" | 68 ++++---- ...\345\205\261\347\273\223\347\202\271.java" | 72 ++++---- ...\345\217\243\347\273\223\347\202\271.java" | 44 ++--- ...\347\232\204\347\273\223\347\202\271.java" | 162 +++++++++--------- .../class03/Code01_1_ReverseListNode.java" | 73 ++++++++ .../Code01_2_ReverseDoubleListNode.java" | 78 +++++++++ .../class03/Code01_ReverseList.java" | 17 -- src/main/java/common/CommonConstants.java | 1 + .../common/datastruct/DoubleLinkedNode.java | 33 ---- .../{ListNode.java => LinkedNode.java} | 19 +- src/main/java/common/util/CompareUtils.java | 19 +- .../java/common/util/ConstructLinkedNode.java | 76 ++++++++ .../java/common/util/ConstructListNode.java | 25 --- src/main/java/common/util/SysOut.java | 90 +++++++--- .../test/algorithm_practice/TempTest.java | 18 +- 31 files changed, 749 insertions(+), 545 deletions(-) create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" delete mode 100644 src/main/java/common/datastruct/DoubleLinkedNode.java rename src/main/java/common/datastruct/{ListNode.java => LinkedNode.java} (54%) create mode 100644 src/main/java/common/util/ConstructLinkedNode.java delete mode 100644 src/main/java/common/util/ConstructListNode.java diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" "b/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" index 4a6e873f..9fd9178b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; @@ -39,10 +39,10 @@ public void testCase() { } private void soutTest(int[] list) { - ListNode before = ConstructListNode.construct(list); - SysOut.printList(before); - ListNode after = deleteDuplicates(before); - SysOut.printList(after); + LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list); + SysOut.printLinkedNode(before); + LinkedNode after = deleteDuplicates(before); + SysOut.printLinkedNode(after); System.out.println(); } @@ -51,8 +51,8 @@ private void soutTest(int[] list) { * @param head * @return */ - public ListNode deleteDuplicates(ListNode head) { - ListNode currentNode = head; + public LinkedNode deleteDuplicates(LinkedNode head) { + LinkedNode currentNode = head; while (currentNode != null && currentNode.next != null) { if (currentNode.val == currentNode.next.val) { currentNode.next = currentNode.next.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" index a2bd32ce..871a188c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; /* 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个结点只能存储 一位 数字。 @@ -23,18 +23,18 @@ public class M002_两数相加 { public static void main(String[] args) { //1,8 0 //1, 9,9 - ListNode firstListNode = new ListNode(2); - firstListNode.next = new ListNode(7); - firstListNode.next.next = new ListNode(1); + LinkedNode firstLinkedNode = new LinkedNode(2); + firstLinkedNode.next = new LinkedNode(7); + firstLinkedNode.next.next = new LinkedNode(1); - ListNode secondListNode = new ListNode(3); - secondListNode.next = new ListNode(2); - secondListNode.next.next = new ListNode(9); - secondListNode.next.next.next = new ListNode(9); + LinkedNode secondLinkedNode = new LinkedNode(3); + secondLinkedNode.next = new LinkedNode(2); + secondLinkedNode.next.next = new LinkedNode(9); + secondLinkedNode.next.next.next = new LinkedNode(9); - addTwoNumbers(firstListNode, secondListNode).print(); + addTwoNumbers(firstLinkedNode, secondLinkedNode).printListNode(); System.out.println(); - addTwoNumbers_v2(firstListNode, secondListNode).print(); + addTwoNumbers_v2(firstLinkedNode, secondLinkedNode).printListNode(); } @@ -44,24 +44,24 @@ public static void main(String[] args) { * @param l2 * @return */ - private static ListNode addTwoNumbers_v2(ListNode l1, ListNode l2) { + private static LinkedNode addTwoNumbers_v2(LinkedNode l1, LinkedNode l2) { int carry = 0; - ListNode result = new ListNode(0); + LinkedNode result = new LinkedNode(0); result.next = sumListNode(l1, l2, carry); return result.next; } static int TEN = 10; - private static ListNode sumListNode(ListNode l1, ListNode l2, int carry) { + private static LinkedNode sumListNode(LinkedNode l1, LinkedNode l2, int carry) { if (l1 == null && l2 == null) { - return carry > 0 ? new ListNode(carry) : null; + return carry > 0 ? new LinkedNode(carry) : null; } int x = l1 == null ? 0 : l1.val; int y = l2 == null ? 0 : l2.val; int sum = x + y + carry; carry = sum / TEN; - ListNode sumNode = new ListNode(sum % TEN); + LinkedNode sumNode = new LinkedNode(sum % TEN); sumNode.next = sumListNode(l1 != null ? l1.next : null, l2 != null ? l2.next : null, carry); return sumNode; } @@ -76,17 +76,17 @@ private static ListNode sumListNode(ListNode l1, ListNode l2, int carry) { * @param l2 * @return */ - private static ListNode addTwoNumbers(ListNode l1, ListNode l2) { + private static LinkedNode addTwoNumbers(LinkedNode l1, LinkedNode l2) { int TEN = 10; - ListNode result = null; + LinkedNode result = null; int carry = 0; - ListNode valNode = new ListNode(0); + LinkedNode valNode = new LinkedNode(0); while (l1 != null || l2 != null) { int x = l1 == null ? 0 : l1.val; int y = l2 == null ? 0 : l2.val; int sum = x + y + carry; carry = sum / TEN; - valNode.next = new ListNode(sum % TEN); + valNode.next = new LinkedNode(sum % TEN); if (result == null) { result = valNode.next; } @@ -95,7 +95,7 @@ private static ListNode addTwoNumbers(ListNode l1, ListNode l2) { l2 = l2 != null ? l2.next : null; } if (carry > 0) { - valNode.next = new ListNode(carry); + valNode.next = new LinkedNode(carry); } return result; } @@ -109,23 +109,23 @@ private static ListNode addTwoNumbers(ListNode l1, ListNode l2) { * @param l2 * @return */ - private static ListNode daan(ListNode l1, ListNode l2) { + private static LinkedNode daan(LinkedNode l1, LinkedNode l2) { int TEN = 10; int carry = 0; - ListNode currentNode = new ListNode(0); - ListNode dummyHead = currentNode; + LinkedNode currentNode = new LinkedNode(0); + LinkedNode dummyHead = currentNode; while (l1 != null || l2 != null) { int x = l1 == null ? 0 : l1.val; int y = l2 == null ? 0 : l2.val; int sum = x + y + carry; carry = sum / TEN; - currentNode.next = new ListNode(sum % TEN); + currentNode.next = new LinkedNode(sum % TEN); currentNode = currentNode.next; l1 = l1 != null ? l1.next : null; l2 = l2 != null ? l2.next : null; } if (carry > 0) { - currentNode.next = new ListNode(carry); + currentNode.next = new LinkedNode(carry); } return dummyHead.next; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" index 44fa743d..9918f864 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; @@ -32,19 +32,19 @@ public class M019_删除链表的倒数第N个节点 extends TestCase { public void testCase() { int[] list1 = {1,2,3,4,5}; int n = 2; - ListNode before = ConstructListNode.construct(list1); - before.print(); + LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list1); + before.printListNode(); System.out.println(); - ListNode after = removeNthFromEnd(before, n); - after.print(); + LinkedNode after = removeNthFromEnd(before, n); + after.printListNode(); System.out.println(); int[] list2 = {1}; int n2 = 1; - ListNode listNode2 = ConstructListNode.construct(list2); - SysOut.printList(listNode2); - SysOut.printList(removeNthFromEnd(listNode2, n2)); + LinkedNode linkedNode2 = ConstructLinkedNode.constructSingleLinkedNode(list2); + SysOut.printLinkedNode(linkedNode2); + SysOut.printLinkedNode(removeNthFromEnd(linkedNode2, n2)); } /** @@ -53,14 +53,14 @@ public void testCase() { * @param n * @return */ - public ListNode removeNthFromEnd(ListNode head, int n) { + public LinkedNode removeNthFromEnd(LinkedNode head, int n) { //指向最后一个结点 - ListNode lastNode = head; + LinkedNode lastNode = head; for (int i = 0; i < n-1; i++) { lastNode = lastNode.next; } - ListNode preNode = head; - ListNode curNode = head.next; + LinkedNode preNode = head; + LinkedNode curNode = head.next; if (lastNode == null || lastNode.next == null) { return curNode; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" index 0a739d13..a07f1a93 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; @@ -28,12 +28,12 @@ public void testCase() { } private void soutTest(int[] list) { - ListNode before = ConstructListNode.construct(list); - SysOut.printList(before); - ListNode after_recursion = swapPairs_recursion(before); - SysOut.printList(after_recursion); - ListNode after = swapPairs(ConstructListNode.construct(list)); - SysOut.printList(after); + LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list); + SysOut.printLinkedNode(before); + LinkedNode after_recursion = swapPairs_recursion(before); + SysOut.printLinkedNode(after_recursion); + LinkedNode after = swapPairs(ConstructLinkedNode.constructSingleLinkedNode(list)); + SysOut.printLinkedNode(after); System.out.println(); } @@ -43,18 +43,18 @@ private void soutTest(int[] list) { * @param head * @return */ - public ListNode swapPairs(ListNode head) { + public LinkedNode swapPairs(LinkedNode head) { if (head == null || head.next == null) { return head; } - ListNode next = head.next; - ListNode nextNext = next.next; + LinkedNode next = head.next; + LinkedNode nextNext = next.next; next.next = head; head.next = nextNext; - ListNode pre = head; + LinkedNode pre = head; while (nextNext != null && nextNext.next != null) { - ListNode next1 = nextNext.next; - ListNode nextNext1 = next1.next; + LinkedNode next1 = nextNext.next; + LinkedNode nextNext1 = next1.next; next1.next = nextNext; nextNext.next = nextNext1; @@ -66,11 +66,11 @@ public ListNode swapPairs(ListNode head) { return next; } - public ListNode swapPairs_recursion(ListNode head) { + public LinkedNode swapPairs_recursion(LinkedNode head) { if (head == null || head.next == null) { return head; } - ListNode next = head.next; + LinkedNode next = head.next; head.next = swapPairs_recursion(next.next); next.next = head; return next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" index c0b823d1..49c62609 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; @@ -50,28 +50,28 @@ public void testCase() { } private void soutTest(int[] list, int k) { - ListNode before = ConstructListNode.construct(list); - SysOut.printList(before); - ListNode after = rotateRight(before, k); - SysOut.printList(after); + LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list); + SysOut.printLinkedNode(before); + LinkedNode after = rotateRight(before, k); + SysOut.printLinkedNode(after); System.out.println(); } - public ListNode rotateRight(ListNode head, int k) { + public LinkedNode rotateRight(LinkedNode head, int k) { if (head == null) { return null; } if (k == 0) { return head; } - ListNode newHeadPreNode = findKthToTail(head, k); - ListNode newHead = newHeadPreNode.next; + LinkedNode newHeadPreNode = findKthToTail(head, k); + LinkedNode newHead = newHeadPreNode.next; if (newHead == null) { return head; } newHeadPreNode.next = null; - ListNode lastNode = newHead; + LinkedNode lastNode = newHead; while (lastNode.next != null) { lastNode = lastNode.next; } @@ -86,9 +86,9 @@ public ListNode rotateRight(ListNode head, int k) { * @param k * @return */ - private ListNode findKthToTail(ListNode head, int k) { - ListNode p1 = head; - ListNode p2 = head; + private LinkedNode findKthToTail(LinkedNode head, int k) { + LinkedNode p1 = head; + LinkedNode p2 = head; int newK = 0; for (int i = 0; i < k; i++) { if (p2.next != null) { diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index 3739a2ba..614b9907 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.CompareUtils; -import common.util.ConstructListNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import org.junit.Assert; import org.junit.Test; @@ -28,26 +28,26 @@ public class M092_反转链表2 { @Test public void testCase() { - ListNode head = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); int m = 2, n = 4; - ListNode excepted = ConstructListNode.construct(new int[]{1, 4, 3, 2, 5}); - ListNode actual = reverseBetween(head, m, n); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 4, 3, 2, 5}); + LinkedNode actual = reverseBetween(head, m, n); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); - head = ConstructListNode.construct(new int[]{3, 5}); + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{3, 5}); m = 1; n = 2; - excepted = ConstructListNode.construct(new int[]{5, 3}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{5, 3}); actual = reverseBetween(head, m, n); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } /** * 递归 */ - public ListNode reverseBetween(ListNode head, int m, int n) { + public LinkedNode reverseBetween(LinkedNode head, int m, int n) { if (m == 1) { return reverseN(head, n); } @@ -57,17 +57,17 @@ public ListNode reverseBetween(ListNode head, int m, int n) { return head; } - ListNode lastNext = null; + LinkedNode lastNext = null; /** * reverse 前n个节点 */ - private ListNode reverseN(ListNode head, int n) { + private LinkedNode reverseN(LinkedNode head, int n) { if (n == 1) { lastNext = head.next; return head; } - ListNode last = reverseN(head.next, n-1); + LinkedNode last = reverseN(head.next, n-1); head.next.next = head; head.next = lastNext; @@ -78,13 +78,13 @@ private ListNode reverseN(ListNode head, int n) { /** * 非递归 */ - public ListNode reverseBetween2(ListNode head, int m, int n) { + public LinkedNode reverseBetween2(LinkedNode head, int m, int n) { if (head == null) { return null; } - ListNode dummyHead = new ListNode(); + LinkedNode dummyHead = new LinkedNode(); dummyHead.next = head; int index = 1; @@ -98,11 +98,11 @@ public ListNode reverseBetween2(ListNode head, int m, int n) { } // indexNode的前驱节点 - ListNode prev = dummyHead.next; - ListNode indexNode = prev.next; + LinkedNode prev = dummyHead.next; + LinkedNode indexNode = prev.next; while (indexNode != null && index+1 <= n) { // 把 indexNode 插在dummyHead 的后面。 - ListNode cur = new ListNode(indexNode.val); + LinkedNode cur = new LinkedNode(indexNode.val); prev.next = indexNode.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index be89cbbd..0c04411c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code100; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.CompareUtils; -import common.util.ConstructListNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import org.junit.Assert; import org.junit.Test; @@ -42,39 +42,39 @@ public class M147_对链表进行插入排序 { @Test public void testCase() { - ListNode head = ConstructListNode.construct(new int[]{1, 3, 5, 2, 4}); - ListNode excepted = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); - ListNode actual = insertionSortList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); - - head = ConstructListNode.construct(new int[]{-1,5,3,4,0}); - excepted = ConstructListNode.construct(new int[]{-1,0,3,4,5}); + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); + LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + LinkedNode actual = insertionSortList(head); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); + + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{-1,5,3,4,0}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{-1,0,3,4,5}); actual = insertionSortList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } /** * 双指针 */ - public ListNode insertionSortList(ListNode head) { + public LinkedNode insertionSortList(LinkedNode head) { if (head == null) { return null; } - ListNode dummyHead = new ListNode(); + LinkedNode dummyHead = new LinkedNode(); dummyHead.next = head; // 已排好序的最后一个节点 - ListNode p1 = head; + LinkedNode p1 = head; /** * p1的下一个节点 * 1. p1.val <= p2.val: 正常,已排好序,依次往后移动 * 2. p1.val > p2.val: p2应该从头开始找 第一个比p2大的值,把p2插在它前面 */ - ListNode p2 = p1.next; + LinkedNode p2 = p1.next; while (p2 != null) { @@ -82,7 +82,7 @@ public ListNode insertionSortList(ListNode head) { p1 = p1.next; } else { // 从头开始找 第一个比p2大的值,把p2插在它前面 - ListNode prev = dummyHead; + LinkedNode prev = dummyHead; while (prev.next.val < p2.val) { prev = prev.next; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 4439ebe6..166dccf7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code100; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.CompareUtils; -import common.util.ConstructListNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import org.junit.Assert; import org.junit.Test; @@ -36,34 +36,34 @@ public class M148_排序链表 { @Test public void testCase() { - ListNode head = ConstructListNode.construct(new int[]{4,2,1,3}); - ListNode excepted = ConstructListNode.construct(new int[]{1, 2, 3, 4}); - ListNode actual = sortList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); - - head = ConstructListNode.construct(new int[]{-1,5,3,4,0}); - excepted = ConstructListNode.construct(new int[]{-1,0,3,4,5}); + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{4,2,1,3}); + LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4}); + LinkedNode actual = sortList(head); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); + + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{-1,5,3,4,0}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{-1,0,3,4,5}); actual = sortList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } /** * 双指针 */ - public ListNode sortList(ListNode head) { + public LinkedNode sortList(LinkedNode head) { if (head == null || head.next == null) { return head; } - ListNode dummyHead = new ListNode(); + LinkedNode dummyHead = new LinkedNode(); dummyHead.next = head; // 指向当前 val最小的节点 - ListNode p1 = head; + LinkedNode p1 = head; // 指向当前 val最大的节点 - ListNode p2 = head.next; + LinkedNode p2 = head.next; if (p1.val > p2.val) { // 把 p2 挪到 p1 前面 p1.next = p2.next; @@ -74,7 +74,7 @@ public ListNode sortList(ListNode head) { p2 = dummyHead.next.next; } - ListNode cur = p2.next; + LinkedNode cur = p2.next; while (cur != null) { if (cur.val <= p1.val) { // 把 cur 挪到 p1 前面 diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index 8f146f7a..4f23b02a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code200; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.CompareUtils; -import common.util.ConstructListNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import org.junit.Assert; import org.junit.Test; @@ -28,23 +28,23 @@ public class E206_反转链表 { @Test public void testCase() { - ListNode head = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); - ListNode excepted = ConstructListNode.construct(new int[]{5, 4, 3, 2, 1}); - ListNode actual = reverseList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{5, 4, 3, 2, 1}); + LinkedNode actual = reverseList(head); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } /** * labuladong 递归 */ - public ListNode reverseList(ListNode head) { + public LinkedNode reverseList(LinkedNode head) { if (head == null || head.next == null) { return head; } - ListNode last = reverseList(head.next); + LinkedNode last = reverseList(head.next); head.next.next = head; head.next = null; @@ -54,13 +54,13 @@ public ListNode reverseList(ListNode head) { /** * 递归 */ - public ListNode reverseList3(ListNode head) { + public LinkedNode reverseList3(LinkedNode head) { if (head == null || head.next == null) { return head; } - ListNode prev = reverseList(head.next); - ListNode p = prev; + LinkedNode prev = reverseList(head.next); + LinkedNode p = prev; while (p.next != null) { p = p.next; } @@ -73,19 +73,19 @@ public ListNode reverseList3(ListNode head) { /** * 非递归 */ - public ListNode reverseList2(ListNode head) { + public LinkedNode reverseList2(LinkedNode head) { if (head == null) { return null; } - ListNode dummyHead = new ListNode(); + LinkedNode dummyHead = new LinkedNode(); dummyHead.next = head; - ListNode cur = head.next; + LinkedNode cur = head.next; head.next = null; while (cur != null) { - ListNode next = cur.next; + LinkedNode next = cur.next; // 把 cur 插在 dummyHead.next cur.next = dummyHead.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" index e84adc8b..4a87c878 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code200; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; @@ -37,15 +37,15 @@ public class E237_删除链表中的结点 extends TestCase { @Test public void testCase() { int[] list1 = {4,5,1,9}; - ListNode listNode1 = ConstructListNode.construct(list1); - SysOut.printList(listNode1); - deleteNode(listNode1.next); - SysOut.printList(listNode1); + LinkedNode linkedNode1 = ConstructLinkedNode.constructSingleLinkedNode(list1); + SysOut.printLinkedNode(linkedNode1); + deleteNode(linkedNode1.next); + SysOut.printLinkedNode(linkedNode1); } - public void deleteNode(ListNode node) { - ListNode nextNode = node.next; + public void deleteNode(LinkedNode node) { + LinkedNode nextNode = node.next; while (nextNode != null) { node.val = nextNode.val; nextNode = nextNode.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index bc7c02dc..92dad2ff 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code300; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.CompareUtils; -import common.util.ConstructListNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import org.junit.Assert; import org.junit.Test; @@ -35,35 +35,35 @@ public class M328_奇偶链表 { @Test public void testCase() { - ListNode head = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); - ListNode excepted = ConstructListNode.construct(new int[]{1, 3, 5, 2, 4}); - ListNode actual = oddEvenList(head); + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); + LinkedNode actual = oddEvenList(head); // SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); - head = ConstructListNode.construct(new int[]{2, 1, 3, 5, 6, 4, 7}); - excepted = ConstructListNode.construct(new int[]{2, 3, 6, 7, 1, 5, 4}); + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{2, 1, 3, 5, 6, 4, 7}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{2, 3, 6, 7, 1, 5, 4}); actual = oddEvenList(head); // SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); - head = ConstructListNode.construct(new int[]{2, 1, 3, 5, 6, 4, 7}); - excepted = ConstructListNode.construct(new int[]{1, 3, 5, 7, 2, 6, 4}); + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{2, 1, 3, 5, 6, 4, 7}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 7, 2, 6, 4}); actual = oddEvenValList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); - head = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); - excepted = ConstructListNode.construct(new int[]{1, 3, 5, 2, 4}); + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); actual = oddEvenValList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); - head = ConstructListNode.construct(new int[]{2, 1}); - excepted = ConstructListNode.construct(new int[]{1, 2}); + head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{2, 1}); + excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2}); actual = oddEvenValList(head); - SysOut.printList(actual); - Assert.assertTrue(CompareUtils.compareListNode(excepted, actual)); + SysOut.printLinkedNode(actual); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } @@ -73,21 +73,21 @@ public void testCase() { * * 双指针 屡试不爽 */ - public ListNode oddEvenValList(ListNode head) { + public LinkedNode oddEvenValList(LinkedNode head) { if (head == null || head.next == null) { return head; } - ListNode dummyHead = new ListNode(); + LinkedNode dummyHead = new LinkedNode(); dummyHead.next = head; // p1 指向奇数val 的节点 - ListNode p1 = dummyHead; + LinkedNode p1 = dummyHead; while (p1.next != null && p1.next.val % 2 == 0) { p1 = p1.next; } // p1.next 是 第一个奇数节点,把他挪到 dummyHead.next - ListNode cur = p1.next; + LinkedNode cur = p1.next; p1.next = cur.next; cur.next = dummyHead.next; @@ -96,7 +96,7 @@ public ListNode oddEvenValList(ListNode head) { p1 = cur; // p2 指向偶数val 的节点 - ListNode p2 = dummyHead.next; + LinkedNode p2 = dummyHead.next; while (p2.next != null && p2.next.val % 2 == 1) { p2 = p2.next; } @@ -112,7 +112,7 @@ public ListNode oddEvenValList(ListNode head) { cur = cur.next; while (cur != null) { if (cur.val % 2 == 1) { - ListNode next = cur.next; + LinkedNode next = cur.next; p2.next = cur.next; @@ -139,18 +139,18 @@ public ListNode oddEvenValList(ListNode head) { * 把第2、4、6...个节点放到后面 * 跟节点值的奇偶性无关。。。 */ - public ListNode oddEvenList(ListNode head) { + public LinkedNode oddEvenList(LinkedNode head) { if (head == null) { return null; } // 奇数编号 Node - ListNode p1 = head; + LinkedNode p1 = head; // 偶数编号 Node - ListNode evenHead = head.next; - ListNode p2 = head.next; + LinkedNode evenHead = head.next; + LinkedNode p2 = head.next; while (p2 != null && p2.next != null) { p1.next = p2.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" index 076b0502..fcabed3d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code800; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; @@ -46,10 +46,10 @@ public class E876_链表的中间结点 extends TestCase { public void testCase() { int[] nums = new int[]{1, 2, 3, 4, 5}; - SysOut.printList(middleNode(ConstructListNode.construct(nums))); + SysOut.printLinkedNode(middleNode(ConstructLinkedNode.constructSingleLinkedNode(nums))); int[] nums1 = new int[]{1, 2, 3, 4, 5, 6}; - SysOut.printList(middleNode(ConstructListNode.construct(nums1))); + SysOut.printLinkedNode(middleNode(ConstructLinkedNode.constructSingleLinkedNode(nums1))); } @@ -59,13 +59,13 @@ public void testCase() { * @return */ - public ListNode middleNode(ListNode head) { + public LinkedNode middleNode(LinkedNode head) { if (head == null) { return null; } - List nodeList = new ArrayList<>(); + List nodeList = new ArrayList<>(); while (head != null) { nodeList.add(head); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" index fe96daec..9e092341 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import java.util.Stack; @@ -16,7 +16,7 @@ public class b05_从尾到头打印链表 { * 递归 * @param head */ - private static void printListInverselyUsingRecursion(ListNode head) { + private static void printListInverselyUsingRecursion(LinkedNode head) { if (head == null){ return; } @@ -28,7 +28,7 @@ private static void printListInverselyUsingRecursion(ListNode head) { * 栈 * @param head */ - private static void printListInverselyUsingStack(ListNode head) { + private static void printListInverselyUsingStack(LinkedNode head) { if (head == null){ return; } @@ -46,17 +46,17 @@ private static void printListInverselyUsingStack(ListNode head) { * 利用头插法插入链表 * @param head */ - public static void reverseNode(ListNode head) { + public static void reverseNode(LinkedNode head) { if (head == null) { return ; } //最终翻转之后的 Node - ListNode node ; + LinkedNode node ; - ListNode pre = head; - ListNode cur = head.next; - ListNode next ; + LinkedNode pre = head; + LinkedNode cur = head.next; + LinkedNode next ; while(cur != null){ next = cur.next; @@ -80,11 +80,11 @@ public static void reverseNode(ListNode head) { public static void main(String[] args) { - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - head.next.next.next.next = new ListNode(5); + LinkedNode head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(4); + head.next.next.next.next = new LinkedNode(5); printListInverselyUsingStack(head); System.out.println(); printListInverselyUsingRecursion(head); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" index 1e755ed4..b1b7698b 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" @@ -1,8 +1,9 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; +import common.util.SysOut; -import static common.util.SysOut.printList; +import static common.util.SysOut.printLinkedNode; /** * 给定单向链表的头指针和一个结点指针,定义一个函数在0(1)时间删除该结点, @@ -22,35 +23,35 @@ public class c13_删除链表结点 { public static void main(String[] args) { - ListNode head = new ListNode(1); - head.next = new ListNode(2); - ListNode middle = head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - head.next.next.next.next = new ListNode(5); - ListNode last = head.next.next.next.next.next = new ListNode(6); + LinkedNode head = new LinkedNode(1); + head.next = new LinkedNode(2); + LinkedNode middle = head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(4); + head.next.next.next.next = new LinkedNode(5); + LinkedNode last = head.next.next.next.next.next = new LinkedNode(6); head = deleteNodeInList(head, head); // 删除头结点 - printList(head); + SysOut.printLinkedNode(head); head = deleteNodeInList(head, last); // 删除尾结点 - printList(head); + SysOut.printLinkedNode(head); head = deleteNodeInList(head, middle); // 删除中间结点 - printList(head); + SysOut.printLinkedNode(head); } - private static ListNode deleteNodeInList(ListNode head, ListNode nodeToBeDeleted) { + private static LinkedNode deleteNodeInList(LinkedNode head, LinkedNode nodeToBeDeleted) { if (head==null || nodeToBeDeleted==null){ return head; } if (nodeToBeDeleted.next != null){ //只要删除的不是尾结点 - ListNode tmp = nodeToBeDeleted.next; + LinkedNode tmp = nodeToBeDeleted.next; nodeToBeDeleted.val = tmp.val; nodeToBeDeleted.next = tmp.next; tmp = null; } else if (head == nodeToBeDeleted){ //链表中就这么一个结点 nodeToBeDeleted = null; } else { //多个结点的情况下,删除尾结点 - ListNode tmp = head; + LinkedNode tmp = head; while (tmp.next != nodeToBeDeleted){ tmp = tmp.next; } diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" index 7333d09b..2e88847e 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; /** * 题目:输入一个链表,输出该链表中倒数第k 个结点. @@ -31,12 +31,12 @@ public class c15_链表中倒数第k个结点 { - public static ListNode findKthToTail(ListNode head, int k) { + public static LinkedNode findKthToTail(LinkedNode head, int k) { if (head==null || k<=0){ return null; } - ListNode p1 = head; - ListNode p2 = head; + LinkedNode p1 = head; + LinkedNode p2 = head; for (int i = 1; i < k; i++) { if (p2.next != null){ p2 = p2.next; @@ -53,12 +53,12 @@ public static ListNode findKthToTail(ListNode head, int k) { } public static void main(String[] args) { - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - head.next.next.next.next = new ListNode(5); - head.next.next.next.next.next = new ListNode(6); + LinkedNode head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(4); + head.next.next.next.next = new LinkedNode(5); + head.next.next.next.next.next = new LinkedNode(6); System.out.println(findKthToTail(head, 1).val); //倒数第1个 System.out.println(findKthToTail(head, 3).val); //中间的一个 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" index cbc0fd56..072d4e37 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.SysOut; /** @@ -14,13 +14,13 @@ public class c16_反转链表 { - public static ListNode reverseList(ListNode head) { + private static LinkedNode reverseList(LinkedNode head) { if (head == null) { return null; } - ListNode root = new ListNode(); //逻辑头结点 + LinkedNode root = new LinkedNode(); //逻辑头结点 root.next = null; - ListNode next; + LinkedNode next; while (head != null){ next = head.next; head.next = root.next; @@ -35,15 +35,15 @@ public static ListNode reverseList(ListNode head) { * @param head * @return */ - private static ListNode reverseList2(ListNode head) { + private static LinkedNode reverseList2(LinkedNode head) { if (head == null) { return null; } - ListNode reverseHead = null; - ListNode cur = head; //当前结点 - ListNode pre = null; //当前结点的前一个结点 + LinkedNode reverseHead = null; + LinkedNode cur = head; //当前结点 + LinkedNode pre = null; //当前结点的前一个结点 // pre = null, 因为反转后,head.next = null; - ListNode next = null; + LinkedNode next = null; while (cur != null) { next = cur.next; if (next == null) { @@ -57,26 +57,26 @@ private static ListNode reverseList2(ListNode head) { } public static void main(String[] args) { - ListNode head = new ListNode(1); - head.next = new ListNode(2); - head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - head.next.next.next.next = new ListNode(5); - head.next.next.next.next.next = new ListNode(6); + LinkedNode head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(4); + head.next.next.next.next = new LinkedNode(5); + head.next.next.next.next.next = new LinkedNode(6); - SysOut.printList(head); + SysOut.printLinkedNode(head); head = reverseList(head); - SysOut.printList(head); + SysOut.printLinkedNode(head); head = reverseList2(head); - SysOut.printList(head); + SysOut.printLinkedNode(head); //当只有一个结点时 - ListNode head2 = new ListNode(1); - SysOut.printList(head2); + LinkedNode head2 = new LinkedNode(1); + SysOut.printLinkedNode(head2); head = reverseList(head2); - SysOut.printList(head2); + SysOut.printLinkedNode(head2); head = reverseList2(head2); - SysOut.printList(head2); + SysOut.printLinkedNode(head2); } } diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" index b4c9fca8..ae35054a 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; import common.util.SysOut; /** @@ -20,16 +20,16 @@ public class c17_合并两个排序的链表 { * @param head2 * @return */ - public static ListNode mergeSortedLists(ListNode head1, ListNode head2) { + public static LinkedNode mergeSortedLists(LinkedNode head1, LinkedNode head2) { if (head1 == null) { return head2; } else if (head2 == null) { return head1; } - ListNode head = new ListNode(); - ListNode head1tmp = new ListNode(); //永远指向head1.next - ListNode head1ttmp = new ListNode(); //永远指向head1.next.next - ListNode head2tmp = new ListNode(); //永远指向head2.next + LinkedNode head = new LinkedNode(); + LinkedNode head1tmp = new LinkedNode(); //永远指向head1.next + LinkedNode head1ttmp = new LinkedNode(); //永远指向head1.next.next + LinkedNode head2tmp = new LinkedNode(); //永远指向head2.next //不管怎样,都让head2往head1上合并! if (head2.val < head1.val) { head = head1; @@ -76,14 +76,14 @@ public static ListNode mergeSortedLists(ListNode head1, ListNode head2) { * @param head2 * @return */ - private static ListNode mergeSortedLists2(ListNode head1, ListNode head2){ + private static LinkedNode mergeSortedLists2(LinkedNode head1, LinkedNode head2){ if (head1 == null) { return head2; } else if (head2 == null) { return head1; } - ListNode head = new ListNode(); - ListNode tail = head; //永远指向root链的末尾 + LinkedNode head = new LinkedNode(); + LinkedNode tail = head; //永远指向root链的末尾 while (head1!=null && head2!=null){ if (head1.val <= head2.val){ tail.next = head1; @@ -111,14 +111,14 @@ private static ListNode mergeSortedLists2(ListNode head1, ListNode head2){ * @param head2 * @return */ - private static ListNode mergeSortedLists3(ListNode head1, ListNode head2) { + private static LinkedNode mergeSortedLists3(LinkedNode head1, LinkedNode head2) { if (head1 == null) { return head2; } else if (head2 == null) { return head1; } - ListNode tmp = new ListNode(); + LinkedNode tmp = new LinkedNode(); if (head1.val <= head2.val){ tmp = head1; //head1.next = head2; tmp.next = mergeSortedLists3(head1.next, head2); @@ -132,36 +132,36 @@ private static ListNode mergeSortedLists3(ListNode head1, ListNode head2) { public static void main(String[] args) { - ListNode head = new ListNode(2); - head.next = new ListNode(2); - head.next.next = new ListNode(3); - head.next.next.next = new ListNode(4); - head.next.next.next.next = new ListNode(5); - SysOut.printList(head); - - ListNode head2 = new ListNode(1); - head2.next = new ListNode(3); - head2.next.next = new ListNode(5); - head2.next.next.next = new ListNode(6); - head2.next.next.next.next = new ListNode(7); - SysOut.printList(head2); + LinkedNode head = new LinkedNode(2); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(4); + head.next.next.next.next = new LinkedNode(5); + SysOut.printLinkedNode(head); + + LinkedNode head2 = new LinkedNode(1); + head2.next = new LinkedNode(3); + head2.next.next = new LinkedNode(5); + head2.next.next.next = new LinkedNode(6); + head2.next.next.next.next = new LinkedNode(7); + SysOut.printLinkedNode(head2); head = mergeSortedLists2(head, head2); - SysOut.printList(head); + SysOut.printLinkedNode(head); System.out.println(); //1. head2插在head1和head1tmp中间 - ListNode head3 = new ListNode(1); - head3.next = new ListNode(6); - head3.next.next = new ListNode(7); - SysOut.printList(head3); + LinkedNode head3 = new LinkedNode(1); + head3.next = new LinkedNode(6); + head3.next.next = new LinkedNode(7); + SysOut.printLinkedNode(head3); - ListNode head4 = new ListNode(2); - head4.next = new ListNode(3); - head4.next.next = new ListNode(4); - SysOut.printList(head4); + LinkedNode head4 = new LinkedNode(2); + head4.next = new LinkedNode(3); + head4.next.next = new LinkedNode(4); + SysOut.printLinkedNode(head4); head3 = mergeSortedLists(head3, head4); - SysOut.printList(head3); + SysOut.printLinkedNode(head3); } } diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" index a75f963e..48bf64a9 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode;; +import common.datastruct.LinkedNode;; /** * 题目:输入两个链表,找出它们的第一个公共结点。 @@ -34,12 +34,12 @@ */ public class e37_两个单向链表的第一个公共结点 { - public static ListNode getIntersectListNode(ListNode head1, ListNode head2) { + public static LinkedNode getIntersectListNode(LinkedNode head1, LinkedNode head2) { if (head1 == null || head2 == null) { return null; } - ListNode loop1 = getLoopListNode(head1); - ListNode loop2 = getLoopListNode(head2); + LinkedNode loop1 = getLoopListNode(head1); + LinkedNode loop2 = getLoopListNode(head2); if (loop1 == null && loop2 == null) { return noLoop(head1, head2); } @@ -55,12 +55,12 @@ public static ListNode getIntersectListNode(ListNode head1, ListNode head2) { * @param head * @return */ - public static ListNode getLoopListNode(ListNode head) { + public static LinkedNode getLoopListNode(LinkedNode head) { if (head == null || head.next == null || head.next.next == null) { return null; } - ListNode n1 = head.next; // n1 -> slow - ListNode n2 = head.next.next; // n2 -> fast 一次走两步 + LinkedNode n1 = head.next; // n1 -> slow + LinkedNode n2 = head.next.next; // n2 -> fast 一次走两步 while (n1 != n2) { if (n2.next == null || n2.next.next == null) { return null; @@ -83,12 +83,12 @@ public static ListNode getLoopListNode(ListNode head) { * @param head2 * @return */ - public static ListNode noLoop(ListNode head1, ListNode head2) { + public static LinkedNode noLoop(LinkedNode head1, LinkedNode head2) { if (head1 == null || head2 == null) { return null; } - ListNode cur1 = head1; - ListNode cur2 = head2; + LinkedNode cur1 = head1; + LinkedNode cur2 = head2; int n = 0; while (cur1.next != null) { n++; @@ -124,9 +124,9 @@ public static ListNode noLoop(ListNode head1, ListNode head2) { * @param loop2 链表2的 第一个入环结点 * @return */ - public static ListNode bothLoop(ListNode head1, ListNode loop1, ListNode head2, ListNode loop2) { - ListNode cur1 = null; - ListNode cur2 = null; + public static LinkedNode bothLoop(LinkedNode head1, LinkedNode loop1, LinkedNode head2, LinkedNode loop2) { + LinkedNode cur1 = null; + LinkedNode cur2 = null; if (loop1 == loop2) { cur1 = head1; cur2 = head2; @@ -165,42 +165,42 @@ public static ListNode bothLoop(ListNode head1, ListNode loop1, ListNode head2, public static void main(String[] args) { // 1->2->3->4->5->6->7->null - ListNode head1 = new ListNode(1); - head1.next = new ListNode(2); - head1.next.next = new ListNode(3); - head1.next.next.next = new ListNode(4); - head1.next.next.next.next = new ListNode(5); - head1.next.next.next.next.next = new ListNode(6); - head1.next.next.next.next.next.next = new ListNode(7); + LinkedNode head1 = new LinkedNode(1); + head1.next = new LinkedNode(2); + head1.next.next = new LinkedNode(3); + head1.next.next.next = new LinkedNode(4); + head1.next.next.next.next = new LinkedNode(5); + head1.next.next.next.next.next = new LinkedNode(6); + head1.next.next.next.next.next.next = new LinkedNode(7); // 0->9->8->6->7->null - ListNode head2 = new ListNode(0); - head2.next = new ListNode(9); - head2.next.next = new ListNode(8); + LinkedNode head2 = new LinkedNode(0); + head2.next = new LinkedNode(9); + head2.next.next = new LinkedNode(8); head2.next.next.next = head1.next.next.next.next.next; // 8->6 System.out.println(getIntersectListNode(head1, head2).val); // 1->2->3->4->5->6->7->4... - head1 = new ListNode(1); - head1.next = new ListNode(2); - head1.next.next = new ListNode(3); - head1.next.next.next = new ListNode(4); - head1.next.next.next.next = new ListNode(5); - head1.next.next.next.next.next = new ListNode(6); - head1.next.next.next.next.next.next = new ListNode(7); + head1 = new LinkedNode(1); + head1.next = new LinkedNode(2); + head1.next.next = new LinkedNode(3); + head1.next.next.next = new LinkedNode(4); + head1.next.next.next.next = new LinkedNode(5); + head1.next.next.next.next.next = new LinkedNode(6); + head1.next.next.next.next.next.next = new LinkedNode(7); head1.next.next.next.next.next.next = head1.next.next.next; // 7->4 // 0->9->8->2... - head2 = new ListNode(0); - head2.next = new ListNode(9); - head2.next.next = new ListNode(8); + head2 = new LinkedNode(0); + head2.next = new LinkedNode(9); + head2.next.next = new LinkedNode(8); head2.next.next.next = head1.next; // 8->2 System.out.println(getIntersectListNode(head1, head2).val); // 0->9->8->6->4->5->6.. - head2 = new ListNode(0); - head2.next = new ListNode(9); - head2.next.next = new ListNode(8); + head2 = new LinkedNode(0); + head2.next = new LinkedNode(9); + head2.next.next = new LinkedNode(8); head2.next.next.next = head1.next.next.next.next.next; // 8->6 System.out.println(getIntersectListNode(head1, head2).val); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" index 51de3dc2..226719f7 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; /** * 题目:一个链表中包含环,如何找出环的入口结点? @@ -17,9 +17,9 @@ * Created by nibnait on 2016/10/3. */ public class h56_链表中环的入口结点 { - private static ListNode meetingNode(ListNode head) { - ListNode fast = head; - ListNode slow = head; + private static LinkedNode meetingNode(LinkedNode head) { + LinkedNode fast = head; + LinkedNode slow = head; while (fast != null && fast.next != null) { fast = fast.next.next; slow = slow.next; @@ -46,12 +46,12 @@ public static void main(String[] args) { } // 1->2->3->4->5->6 private static void test01() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); - ListNode n3 = new ListNode(3); - ListNode n4 = new ListNode(4); - ListNode n5 = new ListNode(5); - ListNode n6 = new ListNode(6); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(2); + LinkedNode n3 = new LinkedNode(3); + LinkedNode n4 = new LinkedNode(4); + LinkedNode n5 = new LinkedNode(5); + LinkedNode n6 = new LinkedNode(6); n1.next = n2; n2.next = n3; n3.next = n4; @@ -64,12 +64,12 @@ private static void test01() { // | | // +--------+ private static void test02() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); - ListNode n3 = new ListNode(3); - ListNode n4 = new ListNode(4); - ListNode n5 = new ListNode(5); - ListNode n6 = new ListNode(6); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(2); + LinkedNode n3 = new LinkedNode(3); + LinkedNode n4 = new LinkedNode(4); + LinkedNode n5 = new LinkedNode(5); + LinkedNode n6 = new LinkedNode(6); n1.next = n2; n2.next = n3; n3.next = n4; @@ -82,12 +82,12 @@ private static void test02() { // | | // +---+ private static void test03() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); - ListNode n3 = new ListNode(3); - ListNode n4 = new ListNode(4); - ListNode n5 = new ListNode(5); - ListNode n6 = new ListNode(6); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(2); + LinkedNode n3 = new LinkedNode(3); + LinkedNode n4 = new LinkedNode(4); + LinkedNode n5 = new LinkedNode(5); + LinkedNode n6 = new LinkedNode(6); n1.next = n2; n2.next = n3; n3.next = n4; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" index 972a2471..98932205 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode;; +import common.datastruct.LinkedNode;; import common.util.SysOut; /** @@ -16,16 +16,16 @@ */ public class h57_删除链表中重复的结点 { - private static ListNode deleteDuplication(ListNode head) { + private static LinkedNode deleteDuplication(LinkedNode head) { if (head == null) { return null; } - ListNode root = new ListNode(); + LinkedNode root = new LinkedNode(); root.next = head; // 临时的头结点 - ListNode prev = root; // 当前结点的前驱结点 - ListNode node = head; // 当前处理的结点 + LinkedNode prev = root; // 当前结点的前驱结点 + LinkedNode node = head; // 当前处理的结点 while (node != null && node.next != null) { if (node.val == node.next.val) { while (node.next != null && node.next.val == node.val) { @@ -55,86 +55,86 @@ public static void main(String[] args) { } // 1->2->3->3->4->4->5 private static void test01() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); - ListNode n3 = new ListNode(3); - ListNode n4 = new ListNode(3); - ListNode n5 = new ListNode(4); - ListNode n6 = new ListNode(4); - ListNode n7 = new ListNode(5); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(2); + LinkedNode n3 = new LinkedNode(3); + LinkedNode n4 = new LinkedNode(3); + LinkedNode n5 = new LinkedNode(4); + LinkedNode n6 = new LinkedNode(4); + LinkedNode n7 = new LinkedNode(5); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->2->3->4->5->6->7 private static void test02() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); - ListNode n3 = new ListNode(3); - ListNode n4 = new ListNode(4); - ListNode n5 = new ListNode(5); - ListNode n6 = new ListNode(6); - ListNode n7 = new ListNode(7); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(2); + LinkedNode n3 = new LinkedNode(3); + LinkedNode n4 = new LinkedNode(4); + LinkedNode n5 = new LinkedNode(5); + LinkedNode n6 = new LinkedNode(6); + LinkedNode n7 = new LinkedNode(7); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->1->1->1->1->1->2 private static void test03() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(1); - ListNode n3 = new ListNode(1); - ListNode n4 = new ListNode(1); - ListNode n5 = new ListNode(1); - ListNode n6 = new ListNode(1); - ListNode n7 = new ListNode(2); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(1); + LinkedNode n3 = new LinkedNode(1); + LinkedNode n4 = new LinkedNode(1); + LinkedNode n5 = new LinkedNode(1); + LinkedNode n6 = new LinkedNode(1); + LinkedNode n7 = new LinkedNode(2); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->1->1->1->1->1->1 private static void test04() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(1); - ListNode n3 = new ListNode(1); - ListNode n4 = new ListNode(1); - ListNode n5 = new ListNode(1); - ListNode n6 = new ListNode(1); - ListNode n7 = new ListNode(1); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(1); + LinkedNode n3 = new LinkedNode(1); + LinkedNode n4 = new LinkedNode(1); + LinkedNode n5 = new LinkedNode(1); + LinkedNode n6 = new LinkedNode(1); + LinkedNode n7 = new LinkedNode(1); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->1->2->2->3->3->4->4 private static void test05() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(1); - ListNode n3 = new ListNode(2); - ListNode n4 = new ListNode(2); - ListNode n5 = new ListNode(3); - ListNode n6 = new ListNode(3); - ListNode n7 = new ListNode(4); - ListNode n8 = new ListNode(4); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(1); + LinkedNode n3 = new LinkedNode(2); + LinkedNode n4 = new LinkedNode(2); + LinkedNode n5 = new LinkedNode(3); + LinkedNode n6 = new LinkedNode(3); + LinkedNode n7 = new LinkedNode(4); + LinkedNode n8 = new LinkedNode(4); n1.next = n2; n2.next = n3; n3.next = n4; @@ -142,19 +142,19 @@ private static void test05() { n5.next = n6; n6.next = n7; n7.next = n8; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->1->2->3->3->4->5->5 private static void test06() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(1); - ListNode n3 = new ListNode(2); - ListNode n4 = new ListNode(3); - ListNode n5 = new ListNode(3); - ListNode n6 = new ListNode(4); - ListNode n7 = new ListNode(5); - ListNode n8 = new ListNode(5); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(1); + LinkedNode n3 = new LinkedNode(2); + LinkedNode n4 = new LinkedNode(3); + LinkedNode n5 = new LinkedNode(3); + LinkedNode n6 = new LinkedNode(4); + LinkedNode n7 = new LinkedNode(5); + LinkedNode n8 = new LinkedNode(5); n1.next = n2; n2.next = n3; n3.next = n4; @@ -162,20 +162,20 @@ private static void test06() { n5.next = n6; n6.next = n7; n7.next = n8; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->1->2->2->3->3->4->5->5 private static void test07() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(1); - ListNode n3 = new ListNode(2); - ListNode n4 = new ListNode(2); - ListNode n5 = new ListNode(3); - ListNode n6 = new ListNode(3); - ListNode n7 = new ListNode(4); - ListNode n8 = new ListNode(5); - ListNode n9 = new ListNode(5); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(1); + LinkedNode n3 = new LinkedNode(2); + LinkedNode n4 = new LinkedNode(2); + LinkedNode n5 = new LinkedNode(3); + LinkedNode n6 = new LinkedNode(3); + LinkedNode n7 = new LinkedNode(4); + LinkedNode n8 = new LinkedNode(5); + LinkedNode n9 = new LinkedNode(5); n1.next = n2; n2.next = n3; n3.next = n4; @@ -184,26 +184,26 @@ private static void test07() { n6.next = n7; n7.next = n8; n8.next = n9; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1->2 private static void test08() { - ListNode n1 = new ListNode(1); - ListNode n2 = new ListNode(2); + LinkedNode n1 = new LinkedNode(1); + LinkedNode n2 = new LinkedNode(2); n1.next = n2; - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // 1 private static void test09() { - ListNode n1 = new ListNode(1); - ListNode result = deleteDuplication(n1); - SysOut.printList(result); + LinkedNode n1 = new LinkedNode(1); + LinkedNode result = deleteDuplication(n1); + SysOut.printLinkedNode(result); } // null private static void test10() { - ListNode result = deleteDuplication(null); - SysOut.printList(result); + LinkedNode result = deleteDuplication(null); + SysOut.printLinkedNode(result); } } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" new file mode 100644 index 00000000..7bae96ac --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" @@ -0,0 +1,73 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import common.datastruct.LinkedNode; +import common.util.CompareUtils; +import common.util.ConstructLinkedNode; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by nibnait on 2022/06/24 + */ +public class Code01_1_ReverseListNode { + + @Test + public void loolTestCase() { + for (int i = 0; i < 1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr()); + LinkedNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); + SysOut.printLinkedNode("origin: ", head); + + LinkedNode actual = reverseList(head); + SysOut.printLinkedNode("reverse: ", actual); + LinkedNode excepted = expectReverseListNode(copyHead); + SysOut.printLinkedNode("excepted: ", excepted); + Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); + } + + /** + * 反转链表 + */ + private LinkedNode reverseList(LinkedNode head) { + LinkedNode pre = null; + LinkedNode next = null; + while (head != null) { + next = head.next; + head.next = pre; + + pre = head; + head = next; + } + return pre; + } + + + /** + * 用数组对数器,验证反转链表 + */ + private LinkedNode expectReverseListNode(LinkedNode head) { + List list = new ArrayList<>(); + while (head != null) { + list.add(head); + head = head.next; + } + + for (int i = list.size() - 1; i >= 1; i--) { + list.get(i).next = list.get(i - 1); + } + list.get(0).next = null; + return list.get(list.size() - 1); + } +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" new file mode 100644 index 00000000..6dee7a1b --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" @@ -0,0 +1,78 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import common.CommonConstants; +import common.datastruct.LinkedNode; +import common.util.CompareUtils; +import common.util.ConstructLinkedNode; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + + +/** + * Created by nibnait on 2022/06/24 + */ +public class Code01_2_ReverseDoubleListNode { + + @Test + public void loolTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + testCase(); + } + } + + @Test + public void testCase() { + LinkedNode head = ConstructLinkedNode.constructDoubleLinkedNode(SysRandom.randomArr()); + SysOut.printDoubleLinkedNode("origin: ", head); + LinkedNode copyHead = ConstructLinkedNode.copyDoubleLinkedNode(head); + + LinkedNode actual = reverseList(head); + SysOut.printDoubleLinkedNode("reverse: ", actual); + LinkedNode excepted = expectReverseListNode(copyHead); + SysOut.printDoubleLinkedNode("excepted: ", excepted); + Assert.assertTrue(CompareUtils.compareDoubleListNode(excepted, actual)); + } + + /** + * 反转双向链表 + */ + private LinkedNode reverseList(LinkedNode head) { + LinkedNode pre = null; + LinkedNode next = null; + while (head != null) { + next = head.next; + head.next = pre; + head.prev = next; + + pre = head; + head = next; + } + return pre; + } + + /** + * 用数组对数器,验证反转链表 + */ + private LinkedNode expectReverseListNode(LinkedNode head) { + List list = new ArrayList<>(); + while (head != null) { + list.add(head); + head = head.next; + } + + for (int i = list.size() - 1; i >= 1; i--) { + list.get(i).next = list.get(i - 1); + if (i != list.size() - 1) { + list.get(i).prev = list.get(i + 1); + } + } + list.get(0).next = null; + return list.get(list.size() - 1); + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" deleted file mode 100644 index 4a140aa9..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_ReverseList.java" +++ /dev/null @@ -1,17 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; - -import org.junit.Test; - -/** - * Created by nibnait on 2022/06/24 - */ -public class Code01_ReverseList { - - @Test - public void testCase() { - - } - - - -} diff --git a/src/main/java/common/CommonConstants.java b/src/main/java/common/CommonConstants.java index c4deec72..9e62ee4e 100644 --- a/src/main/java/common/CommonConstants.java +++ b/src/main/java/common/CommonConstants.java @@ -6,6 +6,7 @@ public class CommonConstants { public static final Integer TEST_CASE_COUNT_MIN = 10; + public static final Integer TEST_CASE_COUNT_1000 = 1000; public static final Integer TEST_CASE_COUNT = 500000; diff --git a/src/main/java/common/datastruct/DoubleLinkedNode.java b/src/main/java/common/datastruct/DoubleLinkedNode.java deleted file mode 100644 index 6740ec75..00000000 --- a/src/main/java/common/datastruct/DoubleLinkedNode.java +++ /dev/null @@ -1,33 +0,0 @@ -package common.datastruct; - -import lombok.NoArgsConstructor; - -/** - * 双向链表结点 - */ -@NoArgsConstructor -public class DoubleLinkedNode { - public int value; - public DoubleLinkedNode prev = null; - public DoubleLinkedNode next = null; - - public DoubleLinkedNode(int data){ - this.value = data; - } - - public int getValue() { - return value; - } - - @Override - public String toString() { - return value +""; - } - - void print() { - System.out.print(value + " "); - if (next != null) { - next.print(); - } - } -} diff --git a/src/main/java/common/datastruct/ListNode.java b/src/main/java/common/datastruct/LinkedNode.java similarity index 54% rename from src/main/java/common/datastruct/ListNode.java rename to src/main/java/common/datastruct/LinkedNode.java index f7c0f93a..394810ff 100644 --- a/src/main/java/common/datastruct/ListNode.java +++ b/src/main/java/common/datastruct/LinkedNode.java @@ -4,26 +4,23 @@ * LeetCode 链表结点 * Created by nibnait on 2016/9/20. */ -public class ListNode { +public class LinkedNode { public int val; - public ListNode next = null; + public LinkedNode prev = null; + public LinkedNode next = null; - public ListNode() { - } - public ListNode(int data){ - this.val = data; + public LinkedNode() { } - @Override - public String toString() { - return val +""; + public LinkedNode(int data){ + this.val = data; } - public void print() { + public void printListNode() { String arrow = next != null ? "->" : ""; System.out.print(val + arrow); if (next != null) { - next.print(); + next.printListNode(); } } } diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java index 5b1ee204..3770cdf9 100644 --- a/src/main/java/common/util/CompareUtils.java +++ b/src/main/java/common/util/CompareUtils.java @@ -1,6 +1,6 @@ package common.util; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; /** * Created by nibnait on 2022/04/11 @@ -10,7 +10,7 @@ public class CompareUtils { /** * 对比两个链表 */ - public static boolean compareListNode(ListNode left, ListNode right) { + public static boolean compareSingleListNode(LinkedNode left, LinkedNode right) { while (left != null && right != null && left.val == right.val) { left = left.next; right = right.next; @@ -18,6 +18,21 @@ public static boolean compareListNode(ListNode left, ListNode right) { return left == right; } + public static boolean compareDoubleListNode(LinkedNode left, LinkedNode right) { + while (left != null && right != null && left.val == right.val) { + left = left.next; + right = right.next; + } + if (left != right) { + return false; + } + while (left != null && right != null && left.val == right.val) { + left = left.prev; + right = right.prev; + } + return left == right; + } + /** * 正序排列 */ diff --git a/src/main/java/common/util/ConstructLinkedNode.java b/src/main/java/common/util/ConstructLinkedNode.java new file mode 100644 index 00000000..60f8761b --- /dev/null +++ b/src/main/java/common/util/ConstructLinkedNode.java @@ -0,0 +1,76 @@ +package common.util; + +import common.datastruct.LinkedNode; + +/** + * 构造链表 + * Created by nibnait on 2019-08-08 + */ +public class ConstructLinkedNode { + + public static LinkedNode constructSingleLinkedNode(int[] nums) { + LinkedNode head = new LinkedNode(); + LinkedNode curNode = head; + for (int i = 0; i < nums.length; i++) { + curNode.val = nums[i]; + if (i != nums.length - 1) { + curNode.next = new LinkedNode(); + curNode = curNode.next; + } + } + return head; + } + + public static LinkedNode copySingleLinkedNode(LinkedNode head) { + LinkedNode newHead = new LinkedNode(); + LinkedNode next = new LinkedNode(); + newHead.next = next; + while (head != null) { + next.val = head.val; + if (head.next != null) { + next.next = new LinkedNode(); + } + next = next.next; + head = head.next; + } + return newHead.next; + } + + public static LinkedNode constructDoubleLinkedNode(int[] nums) { + LinkedNode head = new LinkedNode(); + LinkedNode prevNode = null; + + LinkedNode next = new LinkedNode(); + head.next = next; + for (int i = 0; i < nums.length; i++) { + next.val = nums[i]; + next.prev = prevNode; + if (i != nums.length - 1) { + next.next = new LinkedNode(); + } + + prevNode = next; + next = next.next; + } + return head.next; + } + + public static LinkedNode copyDoubleLinkedNode(LinkedNode head) { + LinkedNode newHead = new LinkedNode(); + LinkedNode next = new LinkedNode(); + newHead.next = next; + LinkedNode prevNode = null; + while (head != null) { + next.val = head.val; + if (head.next != null) { + next.next = new LinkedNode(); + } + next.prev = prevNode; + + prevNode = next; + next = next.next; + head = head.next; + } + return newHead.next; + } +} diff --git a/src/main/java/common/util/ConstructListNode.java b/src/main/java/common/util/ConstructListNode.java deleted file mode 100644 index fff8a183..00000000 --- a/src/main/java/common/util/ConstructListNode.java +++ /dev/null @@ -1,25 +0,0 @@ -package common.util; - -import common.datastruct.ListNode; -import junit.framework.TestCase; -import org.junit.Test; - -/** - * 构造链表 - * Created by nibnait on 2019-08-08 - */ -public class ConstructListNode { - - public static ListNode construct(int[] nums) { - ListNode head = new ListNode(); - ListNode curNode = head; - for (int i = 0; i < nums.length; i++) { - curNode.val = nums[i]; - if (i != nums.length - 1) { - curNode.next = new ListNode(); - curNode = curNode.next; - } - } - return head; - } -} diff --git a/src/main/java/common/util/SysOut.java b/src/main/java/common/util/SysOut.java index 0b5302dd..24334b50 100644 --- a/src/main/java/common/util/SysOut.java +++ b/src/main/java/common/util/SysOut.java @@ -1,7 +1,8 @@ package common.util; import common.datastruct.BinaryTreeNode; -import common.datastruct.ListNode; +import common.datastruct.LinkedNode; +import io.github.nibnait.common.exception.ClientViewException; import java.util.Stack; @@ -11,15 +12,23 @@ public final class SysOut { public static void print(String format, Object... args) { - System.out.print(String.format(format, args)); + print(String.format(format, args)); + } + + public static void print(String str) { + System.out.print(str); + } + + public static void println(String format, Object... args) { + println(String.format(format, args)); } public static void println(Object o) { System.out.println(o); } - public static void println(String format, Object... args) { - System.out.println(String.format(format, args)); + public static void println() { + System.out.println(); } public static void printSeparator() { @@ -37,9 +46,9 @@ public static void printArray(int[][] a) { String digitFormat_Comma = "%3d, "; int n = a.length; int m = a[0].length; - System.out.println("{"); + println("{"); for (int i = 0; i < n; i++) { - System.out.print("\t{"); + print("\t{"); for (int j = 0; j < m; j++) { if (j == m - 1) { print(digitFormat, a[i][j]); @@ -47,47 +56,76 @@ public static void printArray(int[][] a) { } print(digitFormat_Comma, a[i][j]); } - System.out.println("},"); + println("},"); } - System.out.println("}"); + println("}"); } public static void printArray(int[] a) { for (int i = 0; i < a.length; i++) { if (i == a.length - 1) { - System.out.print(a[i] + "\n"); + print(a[i] + "\n"); } else { - System.out.print(a[i] + ", "); + print(a[i] + ", "); } } } //*********** 打印链表 ************************************/ - public static void printList(ListNode head) { + public static void printLinkedNode(String format, LinkedNode head) { + print(format); + printLinkedNode(head); + } + + public static void printLinkedNode(LinkedNode head) { while (head != null) { String arrow = head != null ? " -> " : ""; - System.out.print(head.val + arrow); + print(head.val + arrow); + head = head.next; + } + println("null"); + } + + public static void printDoubleLinkedNode(String format, LinkedNode head) { + print(format); + printDoubleLinkedNode(head); + } + + public static void printDoubleLinkedNode(LinkedNode head) { + print("NULL <- "); + Integer prevVal = null; + while (head != null) { + print(head.val + ""); + if (head.prev != null && prevVal != null && !prevVal.equals(head.prev.val)) { + throw new ClientViewException("{}.prev 实际为: {}, 应该为: {}", head.val,head.prev.val, prevVal); + } + + if (head.next != null) { + print(" <-> "); + } + + prevVal = head.val; head = head.next; } - System.out.println("null"); + + println(" -> NULL"); } public static void printDoubleLinkedList(BinaryTreeNode head) { - System.out.println("Double Linked List: "); + println("Double Linked List: "); BinaryTreeNode end = null; while (head != null) { - System.out.print(head.value + " "); + print(head.value + " "); end = head; head = head.right; } - System.out.print("| "); + print("| "); while (end != null) { - System.out.print(end.value + " "); + print(end.value + " "); end = end.left; } - System.out.println(); - + println(); } //*********** 二叉树的前中后需遍历 ************************************/ @@ -95,7 +133,7 @@ public static void preOrderPrint(BinaryTreeNode head) { if (head == null) { return; } - System.out.print(head.value + " "); + print(head.value + " "); preOrderPrint(head.left); preOrderPrint(head.right); } @@ -105,7 +143,7 @@ public static void inOrderPrint(BinaryTreeNode head) { return; } inOrderPrint(head.left); - System.out.print(head.value + " "); + print(head.value + " "); inOrderPrint(head.right); } @@ -115,7 +153,7 @@ public static void posOrderPrint(BinaryTreeNode head) { } posOrderPrint(head.left); posOrderPrint(head.right); - System.out.print(head.value + " "); + print(head.value + " "); } //*********** 打印二叉树 ************************************/ @@ -123,9 +161,9 @@ public static void posOrderPrint(BinaryTreeNode head) { public static void printBinaryTree(BinaryTreeNode head) { - System.out.println("Binary Tree:"); + println("Binary Tree:"); printInOrder(head, 0, "*"); - System.out.println(); + println(); } private static void printInOrder(BinaryTreeNode head, int height, String to) { @@ -138,7 +176,7 @@ private static void printInOrder(BinaryTreeNode head, int height, String to) { int lenL = (NODE_LENGTH - lenM) / 2; int lenR = NODE_LENGTH - lenL - lenM; val = getSpace(height * NODE_LENGTH + lenL) + val + getSpace(lenR); - System.out.println(val); + println(val); printInOrder(head.right, height + 1, "_"); } @@ -156,7 +194,7 @@ public static void printStack(Stack stack) { while (!stack.isEmpty()) { Integer pop = stack.pop(); originStack.push(pop); - System.out.println(pop); + println(pop); } while (!originStack.isEmpty()) { diff --git a/src/main/test/algorithm_practice/TempTest.java b/src/main/test/algorithm_practice/TempTest.java index 0104ee8c..500f5181 100644 --- a/src/main/test/algorithm_practice/TempTest.java +++ b/src/main/test/algorithm_practice/TempTest.java @@ -1,7 +1,7 @@ package algorithm_practice; -import common.datastruct.ListNode; -import common.util.ConstructListNode; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; import common.util.SysOut; import org.junit.Test; @@ -12,19 +12,19 @@ public class TempTest { @Test public void testCase() { - ListNode head = ConstructListNode.construct(new int[]{1, 2, 3, 4, 5}); - SysOut.printList(head); + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + SysOut.printLinkedNode(head); head = reverseK(head, 2); - SysOut.printList(head); + SysOut.printLinkedNode(head); } - private ListNode reverseK(ListNode head, int k) { + private LinkedNode reverseK(LinkedNode head, int k) { if (head == null) { return null; } - ListNode dummyHead = new ListNode(); + LinkedNode dummyHead = new LinkedNode(); dummyHead.next = head; while (dummyHead.next != null) { @@ -43,12 +43,12 @@ private ListNode reverseK(ListNode head, int k) { return dummyHead.next; } - private ListNode reverseN(ListNode head, int n) { + private LinkedNode reverseN(LinkedNode head, int n) { if (n == 1) { return head; } - ListNode last = reverseN(head.next, n-1); + LinkedNode last = reverseN(head.next, n-1); head.next.next = head; head.next = null; From e5856188692d1c6812700e83fac3f112d277b629 Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 6 Jul 2022 09:52:31 +0800 Subject: [PATCH 15/36] =?UTF-8?q?class03=20=E7=94=A8=E9=93=BE=E8=A1=A8?= =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E6=A0=88=E5=92=8C=E9=98=9F=E5=88=97=EF=BC=8C?= =?UTF-8?q?=E7=94=A8=E6=95=B0=E7=BB=84=E6=97=B6=E9=97=B4=E9=98=9F=E5=88=97?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E6=A0=88=E5=AE=9E=E7=8E=B0=E9=98=9F=E5=88=97?= =?UTF-8?q?=EF=BC=8C=E7=94=A8=E9=98=9F=E5=88=97=E5=AE=9E=E7=8E=B0=E6=A0=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class03/Code01_1_ReverseListNode.java" | 3 +- .../class03/Code02_DeleteGivenValue.java" | 65 +++++++ ...ode03_DoubleEndsQueueToStackAndQueue.java" | 172 ++++++++++++++++++ .../class03/Code04_RingArray.java" | 48 +++++ .../class03/Code05_GetMinStack.java" | 17 ++ .../Code06_TwoStacksImplementQueue.java" | 67 +++++++ .../Code07_TwoQueueImplementStack.java" | 99 ++++++++++ src/main/java/common/datastruct/Node.java | 20 ++ src/main/java/common/util/SysRandom.java | 2 +- src/main/test/UnitTestDemo.java | 14 ++ 10 files changed, 505 insertions(+), 2 deletions(-) create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" create mode 100644 src/main/java/common/datastruct/Node.java create mode 100644 src/main/test/UnitTestDemo.java diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" index 7bae96ac..376f7c9f 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" @@ -1,5 +1,6 @@ package algorithm_practice.algorithmzuo.b_体系学习班.class03; +import common.CommonConstants; import common.datastruct.LinkedNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; @@ -19,7 +20,7 @@ public class Code01_1_ReverseListNode { @Test public void loolTestCase() { - for (int i = 0; i < 1000; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { testCase(); } } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" new file mode 100644 index 00000000..82cf7c19 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" @@ -0,0 +1,65 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import common.CommonConstants; +import common.datastruct.LinkedNode; +import common.util.ConstructLinkedNode; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/06 + */ +public class Code02_DeleteGivenValue { + + @Test + public void loolTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr(20)); + LinkedNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); + SysOut.printLinkedNode("before: ", head); + + LinkedNode ans = deleteGivenValue(head, 11); + SysOut.printLinkedNode("after: ", ans); + } + + @Test + public void test() { + LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{11,11,12,3,4,5}); +// head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{3,4,5,11}); + SysOut.printLinkedNode("before: ", head); + + LinkedNode ans = deleteGivenValue(head, 11); + SysOut.printLinkedNode("after: ", ans); + } + + /** + * 在链表中删除指定值的所有节点 + */ + private LinkedNode deleteGivenValue(LinkedNode head, int num) { + if (head == null) { + return head; + } + + while (head.val == num) { + head = head.next; + } + + LinkedNode cursor = head; + while (cursor != null && cursor.next != null) { + if (cursor.next.val == num) { + cursor.next = cursor.next.next; + } + cursor = cursor.next; + } + + return head; + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" new file mode 100644 index 00000000..fdf12194 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" @@ -0,0 +1,172 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import common.datastruct.Node; +import io.github.nibnait.common.utils.compare.CompareUtils; +import org.junit.Test; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +/** + * 用双链表实现栈和队列 + * Created by nibnait on 2022/07/06 + */ +public class Code03_DoubleEndsQueueToStackAndQueue { + + public static class DoubleEndsQueue { + public Node head; + public Node tail; + + public void addFromHead(T value) { + Node newHead = new Node(value); + if (head == null) { + head = newHead; + tail = newHead; + } else { + head.prev = newHead; + newHead.next = head; + + head = head.prev; + } + } + + public void addFromTail(T value) { + Node newHead = new Node(value); + if (head == null) { + head = newHead; + tail = newHead; + } else { + tail.next = newHead; + newHead.prev = tail; + + tail = tail.next; + } + } + + public T popFromHead() { + if (isEmpty()) { + return null; + } + + Node curHead = head; + if (head == tail) { + head = null; + tail = null; + } else { + head = head.next; + head.prev = null; + + curHead.next = null; + } + return curHead.value; + } + + public T popFromTail() { + if (isEmpty()) { + return null; + } + + Node curTail = tail; + if (head == tail) { + head = null; + tail = null; + } else { + tail = tail.prev; + tail.next = null; + + curTail.prev = null; + } + + return curTail.value; + } + + public boolean isEmpty() { + return head == null; + } + } + + public class MyStack { + private DoubleEndsQueue queue; + + public MyStack() { + this.queue = new DoubleEndsQueue<>(); + } + + public void push(T value) { + queue.addFromTail(value); + } + + public T pop() { + return queue.popFromTail(); + } + + public boolean isEmpty() { + return queue.isEmpty(); + } + } + + public class MyQueue { + private DoubleEndsQueue queue; + + public MyQueue() { + this.queue = new DoubleEndsQueue<>(); + } + + public void offer(T value) { + queue.addFromTail(value); + } + + public T poll() { + return queue.popFromHead(); + } + + public boolean isEmpty() { + return queue.isEmpty(); + } + } + + @Test + public void testCase() { + int oneTestDataNum = 100; + int value = 10000; + int testTimes = 100000; + for (int i = 0; i < testTimes; i++) { + MyStack myStack = new MyStack<>(); + MyQueue myQueue = new MyQueue<>(); + Stack stack = new Stack<>(); + Queue queue = new LinkedList<>(); + for (int j = 0; j < oneTestDataNum; j++) { + int nums = (int) (Math.random() * value); + if (stack.isEmpty()) { + myStack.push(nums); + stack.push(nums); + } else { + if (Math.random() < 0.5) { + myStack.push(nums); + stack.push(nums); + } else { + if (!CompareUtils.matchObject(myStack.pop(), stack.pop())) { + System.out.println("oops!"); + } + } + } + int numq = (int) (Math.random() * value); + if (queue.isEmpty()) { + myQueue.offer(numq); + queue.offer(numq); + } else { + if (Math.random() < 0.5) { + myQueue.offer(numq); + queue.offer(numq); + } else { + if (!CompareUtils.matchObject(myQueue.poll(), queue.poll())) { + System.out.println("oops!"); + } + } + } + } + } + System.out.println("finish!"); + } +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" new file mode 100644 index 00000000..c30aab3b --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" @@ -0,0 +1,48 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +/** + * 用环形数组实现队列 + * Created by nibnait on 2022/07/06 + */ +public class Code04_RingArray { + + public static class MyQueue { + private final int[] arr; + private final int limit; + private int pollIndex; + private int addIndex; + private int size; + + public MyQueue(int limit) { + arr = new int[limit]; + pollIndex = 0; + addIndex = 0; + size = 0; + this.limit = limit; + } + + public void add(int value){ + if (size == limit) { + throw new RuntimeException("队列满了"); + } + size++; + arr[addIndex] = value; + addIndex = getNext(addIndex); + } + + public int poll() { + if (size == 0) { + throw new RuntimeException("队列空了"); + } + size--; + int ans = arr[pollIndex]; + pollIndex = getNext(pollIndex); + return ans; + } + + private int getNext(int index){ + return index < limit - 1 ? index + 1 : 0; + } + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" new file mode 100644 index 00000000..bed78dfc --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" @@ -0,0 +1,17 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +/** + * 实现有getMin功能的栈 + * Created by nibnait on 2022/07/06 + */ +public class Code05_GetMinStack { + + /** + * 两个栈 + * 一个正常的数据栈 + * 一个【最小值栈】。当有新的数 push 的时候, + * 如果当前值 <【最小值栈】的栈顶, + * 则【最小值栈】push 新的数 + * 否则【最小值栈】push 原来的栈顶 + */ +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" new file mode 100644 index 00000000..8e15716d --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" @@ -0,0 +1,67 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import org.junit.Test; + +import java.util.Stack; + +/** + * 两个栈实现队列 + * Created by nibnait on 2022/07/06 + */ +public class Code06_TwoStacksImplementQueue { + + @Test + public void testCase() { + TwoStacksQueue test = new TwoStacksQueue(); + test.offer(1); + test.offer(2); + test.offer(3); + System.out.println(test.peek()); + System.out.println(test.poll()); + System.out.println(test.peek()); + System.out.println(test.poll()); + System.out.println(test.peek()); + System.out.println(test.poll()); + } + + public static class TwoStacksQueue { + private Stack pushStack; + private Stack popStack; + + public TwoStacksQueue() { + pushStack = new Stack<>(); + popStack = new Stack<>(); + } + + public void offer(T value) { + pushStack.push(value); + pushToPop(); + } + + private void pushToPop() { + if (popStack.isEmpty()) { + while (!pushStack.isEmpty()) { + popStack.push(pushStack.pop()); + } + } + } + + public T poll() { + if (popStack.isEmpty() && pushStack.isEmpty()) { + throw new RuntimeException("队列空了"); + } + pushToPop(); + return popStack.pop(); + } + + public T peek() { + if (popStack.isEmpty() && pushStack.isEmpty()) { + throw new RuntimeException("队列空了"); + } + pushToPop(); + return popStack.peek(); + } + } + + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" new file mode 100644 index 00000000..66091047 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" @@ -0,0 +1,99 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class03; + +import org.junit.Test; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +/** + * 两个队列实现栈 + * Created by nibnait on 2022/07/06 + */ +public class Code07_TwoQueueImplementStack { + + @Test + public void testCase() { + System.out.println("test begin"); + TwoQueuesStack myStack = new TwoQueuesStack<>(); + Stack test = new Stack<>(); + int testTime = 1000000; + int max = 1000000; + for (int i = 0; i < testTime; i++) { + if (myStack.isEmpty()) { + if (!test.isEmpty()) { + System.out.println("Oops"); + } + int num = (int) (Math.random() * max); + myStack.push(num); + test.push(num); + } else { + if (Math.random() < 0.25) { + int num = (int) (Math.random() * max); + myStack.push(num); + test.push(num); + } else if (Math.random() < 0.5) { + if (!myStack.peek().equals(test.peek())) { + System.out.println("Oops"); + } + } else if (Math.random() < 0.75) { + if (!myStack.poll().equals(test.pop())) { + System.out.println("Oops"); + } + } else { + if (myStack.isEmpty() != test.isEmpty()) { + System.out.println("Oops"); + } + } + } + } + + System.out.println("test finish!"); + } + + public static class TwoQueuesStack { + private Queue queue; + private Queue help; + + public TwoQueuesStack() { + queue = new LinkedList<>(); + help = new LinkedList<>(); + } + + public void push(T value) { + queue.offer(value); + } + + public T poll() { + while (queue.size() > 1) { + help.offer(queue.poll()); + } + T ans = queue.poll(); + + Queue tmp = queue; + queue = help; + help = tmp; + + return ans; + } + + public T peek() { + while (queue.size() > 1) { + help.offer(queue.poll()); + } + T ans = queue.poll(); + help.offer(ans); + + Queue tmp = queue; + queue = help; + help = tmp; + + return ans; + } + + public boolean isEmpty() { + return queue.isEmpty(); + } + } + +} diff --git a/src/main/java/common/datastruct/Node.java b/src/main/java/common/datastruct/Node.java new file mode 100644 index 00000000..0f714f71 --- /dev/null +++ b/src/main/java/common/datastruct/Node.java @@ -0,0 +1,20 @@ +package common.datastruct; + +import lombok.NoArgsConstructor; + +/** + * 双向链表的节点 + * 单向链表的节点(只要不取 prev 这个属性值就好了) + * Created by nibnait on 2022/07/06 + */ +@NoArgsConstructor +public class Node { + + public T value; + public Node prev; + public Node next; + + public Node(T value) { + this.value = value; + } +} diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index e8e566ed..caf78e4b 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -61,7 +61,7 @@ public static int[] randomArr() { public static int[] randomArr(int arrLength) { int[] a = new int[arrLength]; for (int i = 0; i < a.length; i++) { - a[i] = random(100); + a[i] = randomInt(-100, 100); } return a; } diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java new file mode 100644 index 00000000..9d7e9128 --- /dev/null +++ b/src/main/test/UnitTestDemo.java @@ -0,0 +1,14 @@ +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/06 + */ +public class UnitTestDemo { + + @Test + public void testCase() { + + } + + +} From cfcc2e883cecaff7838e88cb3bfe24686d79d549 Mon Sep 17 00:00:00 2001 From: tianbin Date: Thu, 7 Jul 2022 09:47:43 +0800 Subject: [PATCH 16/36] =?UTF-8?q?class04=20=E5=BD=92=E5=B9=B6=E6=8E=92?= =?UTF-8?q?=E5=BA=8F?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../class01/Code03_SelectionSort.java" | 6 +- .../class01/Code04_BubbleSort.java" | 6 +- .../class01/Code05_InsertionSort.java" | 6 +- .../class03/Code01_1_ReverseListNode.java" | 2 +- .../Code01_2_ReverseDoubleListNode.java" | 2 +- .../class03/Code02_DeleteGivenValue.java" | 2 +- .../class04/Code01_MergeSort.java" | 115 ++++++++++++++++++ .../class04/Code02_SmallSum.java" | 77 ++++++++++++ .../class04/Code03_ReversePair.java" | 35 ++++++ .../class04/Code04_BiggerThanRightTwice.java" | 32 +++++ .../class05/Code01_CountOfRangeSum.java" | 33 +++++ .../Code02_PartitionAndQuickSort.java" | 24 ++++ ...e03_QuickSortRecursiveAndUnrecursive.java" | 24 ++++ .../Code04_DoubleLinkedListQuickSort.java" | 24 ++++ src/main/java/common/util/SysRandom.java | 17 ++- src/main/test/UnitTestDemo.java | 8 ++ 16 files changed, 400 insertions(+), 13 deletions(-) create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" create mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" index db653a0e..db37993a 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" @@ -5,6 +5,7 @@ import common.util.SysOut; import common.util.SysRandom; import common.util.SystemUtil; +import org.junit.Assert; import org.junit.Test; import static common.util.SwapUtil.swap; @@ -19,12 +20,11 @@ public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { int arr[] = SysRandom.randomArr(); SysOut.printArray(arr); - int[] tmp = CompareUtils.copyArray(arr); selectSort(arr); SysOut.printArray(arr); if (!CompareUtils.isSortAsc(arr)) { - System.out.println("!!!有问题:"); - SysOut.printArray(tmp); + SysOut.println("。。。有问题❗️❗️❗️"); + Assert.assertTrue(false); } SystemUtil.printLiteCuttingLine(); diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" index f7ecc138..e9b39956 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" @@ -5,6 +5,7 @@ import common.util.SysOut; import common.util.SysRandom; import common.util.SystemUtil; +import org.junit.Assert; import org.junit.Test; import static common.util.SwapUtil.swap; @@ -19,12 +20,11 @@ public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { int arr[] = SysRandom.randomArr(); SysOut.printArray(arr); - int[] tmp = CompareUtils.copyArray(arr); bubbleSort(arr); SysOut.printArray(arr); if (!CompareUtils.isSortAsc(arr)) { - System.out.println("!!!有问题:"); - SysOut.printArray(tmp); + SysOut.println("。。。有问题❗️❗️❗️"); + Assert.assertTrue(false); } SystemUtil.printLiteCuttingLine(); diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" index b1fac591..8a8c817f 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" @@ -5,6 +5,7 @@ import common.util.SysOut; import common.util.SysRandom; import common.util.SystemUtil; +import org.junit.Assert; import org.junit.Test; import static common.util.SwapUtil.swap; @@ -19,13 +20,12 @@ public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { int arr[] = SysRandom.randomArr(); SysOut.printArray(arr); - int[] tmp = CompareUtils.copyArray(arr); insertSort(arr); SysOut.printArray(arr); if (!CompareUtils.isSortAsc(arr)) { - System.out.println("!!!有问题:"); - SysOut.printArray(tmp); + SysOut.println("。。。有问题❗️❗️❗️"); + Assert.assertTrue(false); } SystemUtil.printLiteCuttingLine(); diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" index 376f7c9f..7af7405e 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" @@ -19,7 +19,7 @@ public class Code01_1_ReverseListNode { @Test - public void loolTestCase() { + public void loopTestCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { testCase(); } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" index 6dee7a1b..ac7dec91 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" @@ -19,7 +19,7 @@ public class Code01_2_ReverseDoubleListNode { @Test - public void loolTestCase() { + public void loopTestCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { testCase(); } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" index 82cf7c19..a7100f4f 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" @@ -13,7 +13,7 @@ public class Code02_DeleteGivenValue { @Test - public void loolTestCase() { + public void loopTestCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { testCase(); } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" new file mode 100644 index 00000000..b02e0c12 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" @@ -0,0 +1,115 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class04; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysOut; +import common.util.SysRandom; +import common.util.SystemUtil; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/07 + */ +public class Code01_MergeSort { + + @Test + public void testCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + int arr[] = SysRandom.randomNaturalNumArr(); +// int arr[] = SysRandom.randomArr(); + SysOut.printArray(arr); +// recursiveMergeSort(arr); + mergeSort(arr); + SysOut.printArray(arr); + if (!CompareUtils.isSortAsc(arr)) { + SysOut.println("。。。有问题❗️❗️❗️"); + Assert.assertTrue(false); + } + + SystemUtil.printLiteCuttingLine(); + } + } + + /** + * 归并排序 非递归 + */ + private void mergeSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + int mergeSize = 1; + int length = arr.length; + while (mergeSize < length) { + + // 按照步长,开始 merge + int left = 0; + while (left < length) { + if (length - left < mergeSize) { + // 此时已经不存在右边了。不需要再merge了 + break; + } + + int mid = left + mergeSize - 1; + int right = mid + Math.min(mergeSize, length - mid - 1); + + merge(arr, left, mid, right); + left = right + 1; + } + + // 防止 mergeSize * 2 之后,导致 Integer 溢出 + if (mergeSize > length / 2) { + break; + } + mergeSize <<= 1; + } + + } + + /** + * 归并排序 递归版 + */ + private void recursiveMergeSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + process(arr, 0, arr.length - 1); + } + + private void process(int[] arr, int left, int right) { + if (left == right) { + return; + } + + int mid = (left + right) / 2; + process(arr, left, mid); + process(arr, mid + 1, right); + merge(arr, left, mid, right); + } + + private void merge(int[] arr, int left, int mid, int right) { + int p1 = left; + int p2 = mid + 1; + + int[] help = new int[arr.length]; + for (int i = left; i <= right; i++) { + help[i] = arr[i]; + } + + int index = left; + while (p1 <= mid && p2 <= right) { + arr[index++] = help[p1] < help[p2] ? help[p1++] : help[p2++]; + } + + while (p1 <= mid) { + arr[index++] = help[p1++]; + } + + while (p2 <= right) { + arr[index++] = help[p2++]; + } + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" new file mode 100644 index 00000000..63ebebaf --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" @@ -0,0 +1,77 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class04; + +import common.CommonConstants; +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/18 + */ +public class Code02_SmallSum { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = new int[]{1,3,4,2,5}; + int smallSum = mergeSort(arr); + SysOut.println(smallSum); + SysOut.printArray(arr); + } + + private int mergeSort(int[] arr) { + if (arr == null || arr.length < 2) { + return 0; + } + + return process(arr, 0, arr.length - 1); + } + + private int process(int[] arr, int left, int right) { + if (left == right) { + return 0; + } + + + int mid = (left + right) / 2; + return process(arr, left, mid) + + process(arr, mid + 1, right) + + merge(arr, left, mid, right); + } + + private int merge(int[] arr, int left, int mid, int right) { + int[] help = new int[arr.length]; + for (int i = left; i <= right; i++) { + help[i] = arr[i]; + } + + int p1 = left; + int p2 = mid + 1; + int index = left; + int smallSum = 0; + while (p1 <= mid && p2 <= right) { + if (help[p1] < help[p2]) { + smallSum += (right - p2 + 1) * arr[p1]; + arr[index++] = help[p1++]; + } else { + arr[index++] = help[p2++]; + } + } + + while (p1 <= mid) { + arr[index++] = help[p1++]; + } + + while (p2 <= right) { + arr[index++] = help[p2++]; + } + + return smallSum; + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" new file mode 100644 index 00000000..24ce666a --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" @@ -0,0 +1,35 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class04; + +import common.CommonConstants; +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/21 + */ +public class Code03_ReversePair { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = new int[]{1,3,4,2,5}; + int smallSum = mergeSort(arr); + SysOut.println(smallSum); + SysOut.printArray(arr); + } + + private int mergeSort(int[] arr) { + + + + return 0; + } + + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" new file mode 100644 index 00000000..de1bf410 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" @@ -0,0 +1,32 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class04; + +import common.CommonConstants; +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/21 + */ +public class Code04_BiggerThanRightTwice { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = new int[]{1,3,4,2,5}; + int smallSum = mergeSort(arr); + SysOut.println(smallSum); + SysOut.printArray(arr); + } + + private int mergeSort(int[] arr) { + return 0; + } + + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" new file mode 100644 index 00000000..93d28f99 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" @@ -0,0 +1,33 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class05; + +import common.CommonConstants; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/21 + */ +public class Code01_CountOfRangeSum { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + /** + * https://leetcode.cn/problems/count-of-range-sum/ + */ + @Test + public void testCase() { + + + + } + + private int countRangeSum(int[] nums, int lower, int upper) { + + return 0; + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" new file mode 100644 index 00000000..5a7cee60 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" @@ -0,0 +1,24 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class05; + +import common.CommonConstants; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/22 + */ +public class Code02_PartitionAndQuickSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + + } + + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" new file mode 100644 index 00000000..8d3279af --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" @@ -0,0 +1,24 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class05; + +import common.CommonConstants; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/22 + */ +public class Code03_QuickSortRecursiveAndUnrecursive { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + + } + + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" new file mode 100644 index 00000000..92c378c3 --- /dev/null +++ "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" @@ -0,0 +1,24 @@ +package algorithm_practice.algorithmzuo.b_体系学习班.class05; + +import common.CommonConstants; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/22 + */ +public class Code04_DoubleLinkedListQuickSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + + } + + +} diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index caf78e4b..463c7d42 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -52,7 +52,7 @@ public static int randomInt(int a, int b) { } /** - * 返回一个[0,100)范围的随机int型数组 + * 返回一个[-100,100)范围的随机int型数组 */ public static int[] randomArr() { return randomArr(random(50)); @@ -65,4 +65,19 @@ public static int[] randomArr(int arrLength) { } return a; } + + /** + * 返回一个[0,100)范围的随机int型数组 + */ + public static int[] randomNaturalNumArr() { + return randomNaturalNumArr(random(50)); + } + + public static int[] randomNaturalNumArr(int arrLength) { + int[] a = new int[arrLength]; + for (int i = 0; i < a.length; i++) { + a[i] = randomInt(0, 100); + } + return a; + } } diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java index 9d7e9128..4c2d2dab 100644 --- a/src/main/test/UnitTestDemo.java +++ b/src/main/test/UnitTestDemo.java @@ -1,3 +1,4 @@ +import common.CommonConstants; import org.junit.Test; /** @@ -5,6 +6,13 @@ */ public class UnitTestDemo { + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + @Test public void testCase() { From 344bcdcd511620d89304a44b3a79d2e1ca39258f Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 24 Oct 2022 11:40:08 +0800 Subject: [PATCH 17/36] =?UTF-8?q?=E4=BD=93=E7=B3=BB=E5=AD=A6=E4=B9=A0?= =?UTF-8?q?=E7=8F=AD=20=E7=AC=AC=E4=B8=80=E7=AB=A0=20=E6=8E=92=E5=BA=8F?= =?UTF-8?q?=E3=80=81=E9=93=BE=E8=A1=A8=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 3 +- ...\345\271\266\345\214\272\351\227\264.java" | 18 +- ...\347\232\204\344\270\252\346\225\260.java" | 6 +- .../README.md" | 2 - .../class01/Code01_PrintBinary.java" | 60 ---- .../class01/Code02_SumOfFactorial.java" | 37 --- .../class01/Code03_SelectionSort.java" | 50 --- .../class01/Code04_BubbleSort.java" | 50 --- .../class01/Code05_InsertionSort.java" | 50 --- .../class01/README.md" | 0 .../class01/README.md" | 1 - .../class04/Code01_MergeSort.java" | 115 ------- .../class04/Code02_SmallSum.java" | 77 ----- .../class04/Code03_ReversePair.java" | 35 -- .../class04/Code04_BiggerThanRightTwice.java" | 32 -- .../class05/Code01_CountOfRangeSum.java" | 33 -- .../Code02_PartitionAndQuickSort.java" | 24 -- ...e03_QuickSortRecursiveAndUnrecursive.java" | 24 -- .../Code04_DoubleLinkedListQuickSort.java" | 24 -- .../cc/tianbin/java/IO/FileReaderTest.java | 3 + .../IntegerTest.java" | 11 + src/main/java/common/CommonConstants.java | 4 +- src/main/java/common/model/Person.java | 6 + src/main/java/common/util/CompareUtils.java | 10 - src/main/java/common/util/SysRandom.java | 13 +- .../java/data_struct/\345\240\206/Heap.java" | 129 ++++++++ .../\345\240\206/HeapGreater.java" | 178 ++++++++++ .../data_struct/\345\240\206/MaxHeap.java" | 19 -- .../data_struct/\345\240\206/MinHeap.java" | 19 -- .../data_struct/\345\240\206/MyHeap.java" | 33 ++ src/main/test/UnitTestDemo.java | 13 +- .../test/algorithm_practice/TempTest.java | 58 ++-- .../algorithmzuo/README.md | 0 .../README.md" | 0 .../Code01_SelectionSort.java" | 56 ++++ .../Code02_BubbleSort.java" | 56 ++++ .../Code03_InsertionSort.java" | 57 ++++ .../Code04_1_MergeSort_Recursion.java" | 82 +++++ .../Code04_2_MergeSort_Non_Recursion.java" | 74 +++++ .../Code04_3_SmallSum.java" | 111 +++++++ .../Code04_4_ReversePair.java" | 104 ++++++ .../Code04_5_BiggerThanRightTwice.java" | 112 +++++++ .../Code04_6_CountOfRangeSum.java" | 122 +++++++ .../Code05_1_PartitionAndQuickSort.java" | 154 +++++++++ ...5_2_QuickSortRecursionAndUnrecursion.java" | 120 +++++++ .../Code06_1_HeapSort.java" | 84 +++++ .../Code06_2_SortArrayDistanceLessK.java" | 95 ++++++ .../Code06_3_CoverMax.java" | 112 +++++++ .../Code07_CountSort.java" | 64 ++++ .../Code08_RadixSort.java" | 97 ++++++ .../Code01_BSExist.java" | 6 +- .../Code02_BSNearLeft.java" | 6 +- .../Code03_BSNearRight.java" | 6 +- .../Code04_BSAwesome.java" | 86 +++++ .../Code01_Swap.java" | 26 +- .../Code02_EvenTimesOddTimes.java" | 14 +- .../Code03_KM.java" | 9 +- .../Code01_1_ReverseListNode.java" | 9 +- .../Code01_2_ReverseDoubleListNode.java" | 11 +- .../Code02_DeleteGivenValue.java" | 11 +- .../Code03_LinkedListMid.java" | 168 ++++++++++ .../Code04_IsPalindromeList.java" | 201 ++++++++++++ .../Code05_SmallerEqualBigger.java" | 136 ++++++++ .../Code06_CopyListWithRandom.java" | 91 ++++++ ...ode03_DoubleEndsQueueToStackAndQueue.java" | 2 +- .../Code04_RingArray.java" | 2 +- .../Code05_GetMinStack.java" | 2 +- .../Code06_TwoStacksImplementQueue.java" | 2 +- .../Code07_TwoQueueImplementStack.java" | 2 +- .../Code01_TrieTree.java" | 306 ++++++++++++++++++ .../c01xx_summary.md" | 14 + .../c0201_/package-info.java" | 1 + .../c02xx_summary.md" | 12 + .../README.md" | 0 .../cc/tianbin/java/mybatis/MybatisTest.java | 14 + .../cc/tianbin/java/spring/SpringTest.java | 16 + .../ListStreamTest.java" | 2 - src/main/test/javalang/test/IfTest.java | 85 +++++ 78 files changed, 3095 insertions(+), 782 deletions(-) delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/README.md" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" delete mode 100644 "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" create mode 100644 "src/main/java/data_struct/\345\240\206/Heap.java" create mode 100644 "src/main/java/data_struct/\345\240\206/HeapGreater.java" delete mode 100644 "src/main/java/data_struct/\345\240\206/MaxHeap.java" delete mode 100644 "src/main/java/data_struct/\345\240\206/MinHeap.java" create mode 100644 "src/main/java/data_struct/\345\240\206/MyHeap.java" rename src/main/{java/algorithm_practice => test}/algorithmzuo/README.md (100%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" (100%) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_6_CountOfRangeSum.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" rename "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" (89%) rename "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" (90%) rename "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" (90%) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code04_BSAwesome.java" rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code01_Swap.java" (86%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code02_EvenTimesOddTimes.java" (76%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" (88%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" (87%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" (84%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" (83%) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code03_DoubleEndsQueueToStackAndQueue.java" (98%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code04_RingArray.java" (94%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code05_GetMinStack.java" (86%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code06_TwoStacksImplementQueue.java" (96%) rename "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code07_TwoQueueImplementStack.java" (97%) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" rename "src/main/java/algorithm_practice/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" => "src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" (100%) create mode 100644 src/main/test/cc/tianbin/java/mybatis/MybatisTest.java create mode 100644 src/main/test/cc/tianbin/java/spring/SpringTest.java create mode 100644 src/main/test/javalang/test/IfTest.java diff --git a/.gitignore b/.gitignore index 7c306458..b058697d 100644 --- a/.gitignore +++ b/.gitignore @@ -6,4 +6,5 @@ .idea *.iml /target -*.DS_Store \ No newline at end of file +*.DS_Store +.fleet diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" index 8b8663c3..d9c455a4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" @@ -3,12 +3,8 @@ import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; -import sun.jvm.hotspot.utilities.BitMap; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.Comparator; -import java.util.List; +import java.util.*; /* 给出一个区间的集合,请合并所有重叠的区间。 @@ -104,25 +100,21 @@ public int compare(int[] o1, int[] o2) { * 使用BitMap */ public int[][] merge2(int[][] intervals) { - BitMap bitMap = new BitMap(100); + Map bitMap = new HashMap<>(100); for (int i = 0; i < intervals.length; i++) { int[] interval = intervals[i]; for (int j = interval[0]; j < interval[1]; j++) { - if (j > bitMap.size()) { - bitMap.set_size(j); - } - - bitMap.atPut(j, true); + bitMap.put(j, true); } } int[][] result = new int[1][2]; int count = 0; for (int i = 0; i < bitMap.size(); i++) { - if (bitMap.at(i)) { + if (bitMap.get(i)) { result[count][0] = i; - while (bitMap.at(i)) { + while (bitMap.get(i)) { i++; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" "b/src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" index 2a2a8139..eceb860b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" @@ -4,11 +4,11 @@ import org.junit.Test; /* -给定一个整数数组 nums,返回区间和在 [lower, upper] 之间的个数,包含 lower 和 upper。 -区间和 S(i, j) 表示在 nums 中,位置从 i 到 j 的元素之和,包含 i 和 j (i ≤ j)。 +给定一个整数数组 nums,返回区间和在 [lower, upper] 之间的个数,包含 lower 和 upper。 +区间和 S(i, j) 表示在 nums 中,位置从 i 到 j 的元素之和,包含 i 和 j (i ≤ j)。 说明: -最直观的算法复杂度是 O(n2) ,请在此基础上优化你的算法。 +最直观的算法复杂度是 O(n2) ,请在此基础上优化你的算法。 示例: diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" deleted file mode 100644 index e7d95698..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/README.md" +++ /dev/null @@ -1,2 +0,0 @@ -# 新手班 - \ No newline at end of file diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" deleted file mode 100644 index 95ade597..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code01_PrintBinary.java" +++ /dev/null @@ -1,60 +0,0 @@ -package algorithm_practice.algorithmzuo.a_新手班.class01; - -import common.util.SystemUtil; -import lombok.extern.slf4j.Slf4j; -import org.junit.Test; - -import java.math.BigDecimal; - -/** - * Created by nibnait on 2022/06/20 - */ -@Slf4j -public class Code01_PrintBinary { - - @Test - public void testCase() { - - int num = 4; - print(num); - print(0); - - print(Integer.MAX_VALUE); - print(Integer.MIN_VALUE); - print(Integer.MIN_VALUE + 1); - print(Integer.MIN_VALUE + 2); - print(Integer.MIN_VALUE + 3); - print(Integer.MIN_VALUE + 4); - print(Integer.MIN_VALUE + 5); - - print(-1); - - print(BigDecimal.valueOf(Math.pow(2, 32)).intValue()); - print(BigDecimal.valueOf(Math.pow(2, 31)).intValue()); - print(BigDecimal.valueOf(Math.pow(2, 30)).intValue()); - - SystemUtil.printCuttingLine(); - - // 带符号右移 和 不带符号右移 - num = 1024; - print(num >> 1); - print(num >>> 1); - SystemUtil.printCuttingLine(); - - // 为什么负数的二进制要取反加1? - // 为了加法 正+正 与 正+负。。走一套逻辑。 - num = 5; - print(num); - print(-num); - print(~num + 1); - } - - private void print(int num) { - System.out.print(num + "\t"); - for (int i = 31; i >= 0; i--) { - System.out.print( (num & (1 << i)) == 0 ? "0" : "1"); - } - System.out.println(); - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" deleted file mode 100644 index 17fe8ba3..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code02_SumOfFactorial.java" +++ /dev/null @@ -1,37 +0,0 @@ -package algorithm_practice.algorithmzuo.a_新手班.class01; - -public class Code02_SumOfFactorial { - - public static long f1(int N) { - long ans = 0; - for (int i = 1; i <= N; i++) { - ans += factorial(i); - } - return ans; - } - - public static long factorial(int N) { - long ans = 1; - for (int i = 1; i <= N; i++) { - ans *= i; - } - return ans; - } - - public static long f2(int N) { - long ans = 0; - long cur = 1; - for (int i = 1; i <= N; i++) { - cur = cur * i; - ans += cur; - } - return ans; - } - - public static void main(String[] args) { - int N = 10; - System.out.println(f1(N)); - System.out.println(f2(N)); - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" deleted file mode 100644 index db37993a..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code03_SelectionSort.java" +++ /dev/null @@ -1,50 +0,0 @@ -package algorithm_practice.algorithmzuo.a_新手班.class01; - -import common.CommonConstants; -import common.util.CompareUtils; -import common.util.SysOut; -import common.util.SysRandom; -import common.util.SystemUtil; -import org.junit.Assert; -import org.junit.Test; - -import static common.util.SwapUtil.swap; - -/** - * Created by nibnait on 2022/06/21 - */ -public class Code03_SelectionSort { - - @Test - public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { - int arr[] = SysRandom.randomArr(); - SysOut.printArray(arr); - selectSort(arr); - SysOut.printArray(arr); - if (!CompareUtils.isSortAsc(arr)) { - SysOut.println("。。。有问题❗️❗️❗️"); - Assert.assertTrue(false); - } - - SystemUtil.printLiteCuttingLine(); - } - } - - private void selectSort(int[] arr) { - if (arr == null || arr.length < 2) { - return; - } - - int length = arr.length; - for (int i = 0; i < length - 1; i++) { - int minValueIndex = i; - for (int j = i+1; j < length; j++) { - minValueIndex = arr[j] < arr[minValueIndex] ? j : minValueIndex; - } - swap(arr, i, minValueIndex); - } - - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" deleted file mode 100644 index e9b39956..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code04_BubbleSort.java" +++ /dev/null @@ -1,50 +0,0 @@ -package algorithm_practice.algorithmzuo.a_新手班.class01; - -import common.CommonConstants; -import common.util.CompareUtils; -import common.util.SysOut; -import common.util.SysRandom; -import common.util.SystemUtil; -import org.junit.Assert; -import org.junit.Test; - -import static common.util.SwapUtil.swap; - -/** - * Created by nibnait on 2022/06/21 - */ -public class Code04_BubbleSort { - - @Test - public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { - int arr[] = SysRandom.randomArr(); - SysOut.printArray(arr); - bubbleSort(arr); - SysOut.printArray(arr); - if (!CompareUtils.isSortAsc(arr)) { - SysOut.println("。。。有问题❗️❗️❗️"); - Assert.assertTrue(false); - } - - SystemUtil.printLiteCuttingLine(); - } - } - - private void bubbleSort(int[] arr) { - if (arr == null || arr.length < 2) { - return; - } - - int length = arr.length; - for (int end = length - 1; end > 0; end--) { - for (int i = 0; i < end; i++) { - if (arr[i] > arr[i + 1]) { - swap(arr, i, i + 1); - } - } - } - - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" deleted file mode 100644 index 8a8c817f..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/Code05_InsertionSort.java" +++ /dev/null @@ -1,50 +0,0 @@ -package algorithm_practice.algorithmzuo.a_新手班.class01; - -import common.CommonConstants; -import common.util.CompareUtils; -import common.util.SysOut; -import common.util.SysRandom; -import common.util.SystemUtil; -import org.junit.Assert; -import org.junit.Test; - -import static common.util.SwapUtil.swap; - -/** - * Created by nibnait on 2022/06/21 - */ -public class Code05_InsertionSort { - - @Test - public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { - int arr[] = SysRandom.randomArr(); - SysOut.printArray(arr); - - insertSort(arr); - SysOut.printArray(arr); - if (!CompareUtils.isSortAsc(arr)) { - SysOut.println("。。。有问题❗️❗️❗️"); - Assert.assertTrue(false); - } - - SystemUtil.printLiteCuttingLine(); - } - } - - private void insertSort(int[] arr) { - if (arr == null || arr.length < 2) { - return; - } - - int length = arr.length; - for (int end = 1; end < length; end++) { - int newNumIndex = end; - while (newNumIndex - 1 >= 0 && arr[newNumIndex - 1] > arr[newNumIndex]) { - swap(arr, newNumIndex - 1, newNumIndex); - newNumIndex--; - } - } - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/README.md" "b/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class01/README.md" deleted file mode 100644 index e69de29b..00000000 diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" deleted file mode 100644 index dfa9cbdb..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class01/README.md" +++ /dev/null @@ -1 +0,0 @@ -# [01 时间复杂度、空间复杂度、对数器和二分法](https://tianbin.cc) \ No newline at end of file diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" deleted file mode 100644 index b02e0c12..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code01_MergeSort.java" +++ /dev/null @@ -1,115 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class04; - -import common.CommonConstants; -import common.util.CompareUtils; -import common.util.SysOut; -import common.util.SysRandom; -import common.util.SystemUtil; -import org.junit.Assert; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/07 - */ -public class Code01_MergeSort { - - @Test - public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - int arr[] = SysRandom.randomNaturalNumArr(); -// int arr[] = SysRandom.randomArr(); - SysOut.printArray(arr); -// recursiveMergeSort(arr); - mergeSort(arr); - SysOut.printArray(arr); - if (!CompareUtils.isSortAsc(arr)) { - SysOut.println("。。。有问题❗️❗️❗️"); - Assert.assertTrue(false); - } - - SystemUtil.printLiteCuttingLine(); - } - } - - /** - * 归并排序 非递归 - */ - private void mergeSort(int[] arr) { - if (arr == null || arr.length < 2) { - return; - } - - int mergeSize = 1; - int length = arr.length; - while (mergeSize < length) { - - // 按照步长,开始 merge - int left = 0; - while (left < length) { - if (length - left < mergeSize) { - // 此时已经不存在右边了。不需要再merge了 - break; - } - - int mid = left + mergeSize - 1; - int right = mid + Math.min(mergeSize, length - mid - 1); - - merge(arr, left, mid, right); - left = right + 1; - } - - // 防止 mergeSize * 2 之后,导致 Integer 溢出 - if (mergeSize > length / 2) { - break; - } - mergeSize <<= 1; - } - - } - - /** - * 归并排序 递归版 - */ - private void recursiveMergeSort(int[] arr) { - if (arr == null || arr.length < 2) { - return; - } - - process(arr, 0, arr.length - 1); - } - - private void process(int[] arr, int left, int right) { - if (left == right) { - return; - } - - int mid = (left + right) / 2; - process(arr, left, mid); - process(arr, mid + 1, right); - merge(arr, left, mid, right); - } - - private void merge(int[] arr, int left, int mid, int right) { - int p1 = left; - int p2 = mid + 1; - - int[] help = new int[arr.length]; - for (int i = left; i <= right; i++) { - help[i] = arr[i]; - } - - int index = left; - while (p1 <= mid && p2 <= right) { - arr[index++] = help[p1] < help[p2] ? help[p1++] : help[p2++]; - } - - while (p1 <= mid) { - arr[index++] = help[p1++]; - } - - while (p2 <= right) { - arr[index++] = help[p2++]; - } - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" deleted file mode 100644 index 63ebebaf..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code02_SmallSum.java" +++ /dev/null @@ -1,77 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class04; - -import common.CommonConstants; -import common.util.SysOut; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/18 - */ -public class Code02_SmallSum { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - @Test - public void testCase() { - int arr[] = new int[]{1,3,4,2,5}; - int smallSum = mergeSort(arr); - SysOut.println(smallSum); - SysOut.printArray(arr); - } - - private int mergeSort(int[] arr) { - if (arr == null || arr.length < 2) { - return 0; - } - - return process(arr, 0, arr.length - 1); - } - - private int process(int[] arr, int left, int right) { - if (left == right) { - return 0; - } - - - int mid = (left + right) / 2; - return process(arr, left, mid) - + process(arr, mid + 1, right) - + merge(arr, left, mid, right); - } - - private int merge(int[] arr, int left, int mid, int right) { - int[] help = new int[arr.length]; - for (int i = left; i <= right; i++) { - help[i] = arr[i]; - } - - int p1 = left; - int p2 = mid + 1; - int index = left; - int smallSum = 0; - while (p1 <= mid && p2 <= right) { - if (help[p1] < help[p2]) { - smallSum += (right - p2 + 1) * arr[p1]; - arr[index++] = help[p1++]; - } else { - arr[index++] = help[p2++]; - } - } - - while (p1 <= mid) { - arr[index++] = help[p1++]; - } - - while (p2 <= right) { - arr[index++] = help[p2++]; - } - - return smallSum; - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" deleted file mode 100644 index 24ce666a..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code03_ReversePair.java" +++ /dev/null @@ -1,35 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class04; - -import common.CommonConstants; -import common.util.SysOut; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/21 - */ -public class Code03_ReversePair { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - @Test - public void testCase() { - int arr[] = new int[]{1,3,4,2,5}; - int smallSum = mergeSort(arr); - SysOut.println(smallSum); - SysOut.printArray(arr); - } - - private int mergeSort(int[] arr) { - - - - return 0; - } - - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" deleted file mode 100644 index de1bf410..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class04/Code04_BiggerThanRightTwice.java" +++ /dev/null @@ -1,32 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class04; - -import common.CommonConstants; -import common.util.SysOut; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/21 - */ -public class Code04_BiggerThanRightTwice { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - @Test - public void testCase() { - int arr[] = new int[]{1,3,4,2,5}; - int smallSum = mergeSort(arr); - SysOut.println(smallSum); - SysOut.printArray(arr); - } - - private int mergeSort(int[] arr) { - return 0; - } - - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" deleted file mode 100644 index 93d28f99..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code01_CountOfRangeSum.java" +++ /dev/null @@ -1,33 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class05; - -import common.CommonConstants; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/21 - */ -public class Code01_CountOfRangeSum { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - /** - * https://leetcode.cn/problems/count-of-range-sum/ - */ - @Test - public void testCase() { - - - - } - - private int countRangeSum(int[] nums, int lower, int upper) { - - return 0; - } - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" deleted file mode 100644 index 5a7cee60..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code02_PartitionAndQuickSort.java" +++ /dev/null @@ -1,24 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class05; - -import common.CommonConstants; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/22 - */ -public class Code02_PartitionAndQuickSort { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - @Test - public void testCase() { - - } - - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" deleted file mode 100644 index 8d3279af..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code03_QuickSortRecursiveAndUnrecursive.java" +++ /dev/null @@ -1,24 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class05; - -import common.CommonConstants; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/22 - */ -public class Code03_QuickSortRecursiveAndUnrecursive { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - @Test - public void testCase() { - - } - - -} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" "b/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" deleted file mode 100644 index 92c378c3..00000000 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class05/Code04_DoubleLinkedListQuickSort.java" +++ /dev/null @@ -1,24 +0,0 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class05; - -import common.CommonConstants; -import org.junit.Test; - -/** - * Created by nibnait on 2022/07/22 - */ -public class Code04_DoubleLinkedListQuickSort { - - @Test - public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - testCase(); - } - } - - @Test - public void testCase() { - - } - - -} diff --git a/src/main/java/cc/tianbin/java/IO/FileReaderTest.java b/src/main/java/cc/tianbin/java/IO/FileReaderTest.java index 8be81414..265f7edf 100644 --- a/src/main/java/cc/tianbin/java/IO/FileReaderTest.java +++ b/src/main/java/cc/tianbin/java/IO/FileReaderTest.java @@ -25,6 +25,9 @@ public void testNioFile() { Path normalize = path.normalize(); File file = path.toFile(); + File absoluteFile = file.getAbsoluteFile(); + System.out.println(absoluteFile); + try { System.out.println("一次性读取所有的字节流:"); diff --git "a/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" index cf3db175..477e5c22 100644 --- "a/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" +++ "b/src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" @@ -7,6 +7,17 @@ */ public class IntegerTest { + @Test + public void test04() { + System.out.println(-1/2); + } + + @Test + public void test03() { + String s = Integer.toHexString("".hashCode()); + System.out.println(s); + } + @Test public void max() { System.out.println(Integer.MAX_VALUE); diff --git a/src/main/java/common/CommonConstants.java b/src/main/java/common/CommonConstants.java index 9e62ee4e..e71bea57 100644 --- a/src/main/java/common/CommonConstants.java +++ b/src/main/java/common/CommonConstants.java @@ -5,9 +5,7 @@ */ public class CommonConstants { - public static final Integer TEST_CASE_COUNT_MIN = 10; + public static final Integer TEST_CASE_COUNT_10 = 10; public static final Integer TEST_CASE_COUNT_1000 = 1000; - public static final Integer TEST_CASE_COUNT = 500000; - } diff --git a/src/main/java/common/model/Person.java b/src/main/java/common/model/Person.java index 3dd336fb..12a88768 100644 --- a/src/main/java/common/model/Person.java +++ b/src/main/java/common/model/Person.java @@ -29,6 +29,12 @@ public Person(String name, Integer age) { this.age = age; } + public static Person buildByAge(int age) { + Person person = new Person(); + person.setAge(age); + return person; + } + @Override public boolean equals(Object o) { if (this == o) return true; diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java index 3770cdf9..cc90cf18 100644 --- a/src/main/java/common/util/CompareUtils.java +++ b/src/main/java/common/util/CompareUtils.java @@ -50,14 +50,4 @@ public static boolean isSortAsc(int[] arr) { return true; } - /** - * copy - */ - public static int[] copyArray(int[] arr) { - int[] ans = new int[arr.length]; - for (int i = 0; i < arr.length; i++) { - ans[i] = arr[i]; - } - return ans; - } } diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index 463c7d42..628d9065 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -22,8 +22,11 @@ private static double random() { * 随机返回 [0,n)之间的一个int值 */ public static int random(int n) { - if (n <= 0) { - throw new IllegalArgumentException("Parameter N must be positive"); + if (n < 0) { + throw new IllegalArgumentException(DataUtils.format("Parameter {} must be positive", n)); + } + if (n == 0) { + return 0; } return random.nextInt(n); } @@ -69,11 +72,11 @@ public static int[] randomArr(int arrLength) { /** * 返回一个[0,100)范围的随机int型数组 */ - public static int[] randomNaturalNumArr() { - return randomNaturalNumArr(random(50)); + public static int[] randomArrNaturalNum() { + return randomArrNaturalNum(random(50)); } - public static int[] randomNaturalNumArr(int arrLength) { + public static int[] randomArrNaturalNum(int arrLength) { int[] a = new int[arrLength]; for (int i = 0; i < a.length; i++) { a[i] = randomInt(0, 100); diff --git "a/src/main/java/data_struct/\345\240\206/Heap.java" "b/src/main/java/data_struct/\345\240\206/Heap.java" new file mode 100644 index 00000000..949769d0 --- /dev/null +++ "b/src/main/java/data_struct/\345\240\206/Heap.java" @@ -0,0 +1,129 @@ +package data_struct.堆; + +import common.util.SwapUtil; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * 大根堆:可以理解为在一个"完全二叉树"中,每一颗子树的最大值都是头节点 + * 大根堆:可以理解为在一个"完全二叉树"中,每一颗子树的最小值都是头节点 + *

+ * 因此堆可以用数组表示 + * heap[i] 的父节点: heap[(i - 1) / 2] + * heap[i] 的子节点: heap[i * 2 + 1], heap[i * 2 + 2] + *

+ * 可见,大小根堆的区别近在于建堆时的比较方法不同而已。 + *

+ * 当前的类 为手写的一个大根堆 + * Created by nibnait on 2020-01-07 + */ +public class Heap { + + @Test + public void testCase() { + int limit = 10; + int[] arr = SysRandom.randomArrNaturalNum(limit); + SysOut.printArray(arr); + + MapHeap maxHeap = new MapHeap(limit); + for (int i : arr) { + maxHeap.push(i); + } + for (int i = 0; i < limit; i++) { + System.out.println(maxHeap.pop()); + } + } + + public class MapHeap implements MyHeap { + + private int[] heap; + private final int limit; + private int heapSize; + + public MapHeap(int limit) { + this.heap = new int[limit]; + this.limit = limit; + heapSize = 0; + } + + @Override + public boolean isEmpty() { + return heapSize == 0; + } + + @Override + public boolean isFull() { + return heapSize == limit; + } + + @Override + public void push(Integer obj) { + if (isFull()) { + throw new UnsupportedOperationException("heap is full"); + } + heap[heapSize] = obj; + heapInsert(heapSize++); + } + + /** + * 先把 obj 加到数组末尾 + * 看他能不能在往上调一调 + */ + private void heapInsert(int curIndex) { + int fatherIndex = (curIndex - 1) / 2; + while (heap[curIndex] > heap[fatherIndex]) { + SwapUtil.swap(heap, curIndex, fatherIndex); + curIndex = fatherIndex; + fatherIndex = (curIndex - 1) / 2; + } + } + + @Override + public Integer peek() { + return heap[0]; + } + + @Override + public Integer pop() { + int heap0 = heap[0]; + SwapUtil.swap(heap, 0, --heapSize); + sinkDown(0); + return heap0; + } + + /** + * 当前 heap[0] 为原来的 heap[heapSize-1] + * 所以要把 heap[0] 往下调一调 + */ + private void sinkDown(int curIndex) { + int leftChildIndex = curIndex * 2 + 1; + while (leftChildIndex < heapSize) { + int largerChildIndex = leftChildIndex + 1 < heapSize && heap[leftChildIndex] < heap[leftChildIndex + 1] + ? leftChildIndex + 1 + : leftChildIndex; + + if (heap[largerChildIndex] < heap[curIndex]) { + // ok了,当前位置刚刚好,无需再往下沉 + break; + } + + SwapUtil.swap(heap, curIndex, largerChildIndex); + curIndex = largerChildIndex; + leftChildIndex = curIndex * 2 + 1; + } + } + + @Override + public List getAllElements() { + List allElements = new ArrayList<>(); + for (int e : heap) { + allElements.add(e); + } + return allElements; + } + } +} \ No newline at end of file diff --git "a/src/main/java/data_struct/\345\240\206/HeapGreater.java" "b/src/main/java/data_struct/\345\240\206/HeapGreater.java" new file mode 100644 index 00000000..ae8a2266 --- /dev/null +++ "b/src/main/java/data_struct/\345\240\206/HeapGreater.java" @@ -0,0 +1,178 @@ +package data_struct.堆; + +import common.model.Person; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Comparator; +import java.util.HashMap; +import java.util.List; + +/** + * 增强堆,新增了 反向索引功能 + */ +public class HeapGreater { + + @Test + public void testCase() { + int[] arr = SysRandom.randomArr(10); + SysOut.printArray(arr); + + int limit = 10; + MaxHeapGreater maxHeap = new MaxHeapGreater(new MyComparator()); + for (int i : arr) { + maxHeap.push(new Inner(Person.buildByAge(i))); + } + for (int i = 0; i < limit; i++) { + Person p = (Person) maxHeap.pop().value; + System.out.println(p.getAge()); + } + } + + private class MyComparator implements Comparator { + + @Override + public int compare(Inner o1, Inner o2) { + Person p1 = (Person) o1.value; + Person p2 = (Person) o2.value; + return p1.getAge() - p2.getAge(); + } + } + + public class Inner { + public T value; + + public Inner(T v) { + value = v; + } + } + + public class MaxHeapGreater implements MyHeap { + + private ArrayList heap; + private HashMap indexMap; + private int heapSize; + private Comparator comparator; + + public MaxHeapGreater(Comparator comparator) { + this.heap = new ArrayList<>(); + this.indexMap = new HashMap<>(); + this.heapSize = 0; + this.comparator = comparator; + } + + @Override + public boolean isEmpty() { + return heapSize == 0; + } + + @Override + public boolean isFull() { + return false; + } + + @Override + public boolean contains(Inner obj) { + return indexMap.containsKey(obj); + } + + @Override + public void push(Inner obj) { + heap.add(obj); + + heapInsert(heapSize++); + } + + /** + * 当前在在下面,看怎么网上调一调 + */ + private void heapInsert(int curIndex) { + int fatherIndex = (curIndex - 1) / 2; + while (comparator.compare(heap.get(curIndex), heap.get(fatherIndex)) > 0) { + swap(curIndex, fatherIndex); + curIndex = fatherIndex; + fatherIndex = (curIndex - 1) / 2; + } + } + + private void swap(int i, int j) { + Inner o1 = heap.get(i); + Inner o2 = heap.get(j); + heap.set(i, o2); + heap.set(j, o1); + indexMap.put(o2, i); + indexMap.put(o1, j); + } + + @Override + public Inner peek() { + return heap.get(0); + } + + @Override + public Inner pop() { + Inner heap0 = heap.get(0); + swap(0, heapSize - 1); + heap.remove(--heapSize); + indexMap.remove(heap0); + + sinkDown(0); + return heap0; + } + + private void sinkDown(int curIndex) { + int leftChildIndex = curIndex * 2 + 1; + while (leftChildIndex < heapSize) { + int largerChildIndex = leftChildIndex + 1 < heapSize && comparator.compare(heap.get(leftChildIndex + 1), heap.get(leftChildIndex)) > 0 + ? leftChildIndex + 1 + : leftChildIndex; + + if (comparator.compare(heap.get(largerChildIndex), heap.get(curIndex)) < 0) { + // ok了,当前位置刚刚好,无需再往下沉 + break; + } + + swap(curIndex, largerChildIndex); + curIndex = largerChildIndex; + leftChildIndex = curIndex * 2 + 1; + } + } + + @Override + public void remove(Inner obj) { + Integer index = indexMap.get(obj); + indexMap.remove(obj); + + Inner replace = heap.get(heapSize - 1); + heap.remove(--heapSize); + + if (comparator.compare(obj, replace) == 0) { + // 最后一个元素 就是要删除的 + return; + } + + heap.set(index, replace); + indexMap.put(replace, index); + resign(replace); + } + + @Override + public void resign(Inner obj) { + Integer index = indexMap.get(obj); + + heapInsert(index); + sinkDown(index); + } + + @Override + public List getAllElements() { + List allElements = new ArrayList<>(); + for (Inner e : heap) { + allElements.add(e); + } + return allElements; + } + } +} diff --git "a/src/main/java/data_struct/\345\240\206/MaxHeap.java" "b/src/main/java/data_struct/\345\240\206/MaxHeap.java" deleted file mode 100644 index 3c28fdc8..00000000 --- "a/src/main/java/data_struct/\345\240\206/MaxHeap.java" +++ /dev/null @@ -1,19 +0,0 @@ -package data_struct.堆; - -import junit.framework.TestCase; -import org.junit.Test; - -/* - 大顶堆 - -Created by nibnait on 2020-01-07 -*/ -public class MaxHeap extends TestCase { - - @Test - public void testCase() { - - } - - -} \ No newline at end of file diff --git "a/src/main/java/data_struct/\345\240\206/MinHeap.java" "b/src/main/java/data_struct/\345\240\206/MinHeap.java" deleted file mode 100644 index 69f80cef..00000000 --- "a/src/main/java/data_struct/\345\240\206/MinHeap.java" +++ /dev/null @@ -1,19 +0,0 @@ -package data_struct.堆; - -import junit.framework.TestCase; -import org.junit.Test; - -/* - - -Created by nibnait on 2020-01-07 -*/ -public class MinHeap extends TestCase { - - @Test - public void testCase() { - - } - - -} \ No newline at end of file diff --git "a/src/main/java/data_struct/\345\240\206/MyHeap.java" "b/src/main/java/data_struct/\345\240\206/MyHeap.java" new file mode 100644 index 00000000..64837352 --- /dev/null +++ "b/src/main/java/data_struct/\345\240\206/MyHeap.java" @@ -0,0 +1,33 @@ +package data_struct.堆; + +import java.util.List; + +/** + * Created by nibnait on 2022/10/24 + */ +public interface MyHeap { + + boolean isEmpty(); + + boolean isFull(); + + default boolean contains(T obj) { + throw new UnsupportedOperationException("不支持 contains 功能"); + } + + void push(T obj); + + T peek(); + + T pop(); + + default void remove(T obj) { + throw new UnsupportedOperationException("不支持 remove 功能"); + } + + default void resign(T obj) { + throw new UnsupportedOperationException("不支持 resign 功能"); + } + + List getAllElements(); +} diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java index 4c2d2dab..bf0f0e74 100644 --- a/src/main/test/UnitTestDemo.java +++ b/src/main/test/UnitTestDemo.java @@ -1,9 +1,15 @@ import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; import org.junit.Test; +import java.util.Arrays; + /** * Created by nibnait on 2022/07/06 */ +@Slf4j public class UnitTestDemo { @Test @@ -15,8 +21,13 @@ public void loopTestCase() { @Test public void testCase() { + int arr[] = SysRandom.randomArrNaturalNum(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + } } - } diff --git a/src/main/test/algorithm_practice/TempTest.java b/src/main/test/algorithm_practice/TempTest.java index 500f5181..3418000a 100644 --- a/src/main/test/algorithm_practice/TempTest.java +++ b/src/main/test/algorithm_practice/TempTest.java @@ -1,8 +1,8 @@ package algorithm_practice; -import common.datastruct.LinkedNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import common.CommonConstants; +import common.util.*; +import org.junit.Assert; import org.junit.Test; /** @@ -12,47 +12,33 @@ public class TempTest { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); - SysOut.printLinkedNode(head); + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + int arr[] = SysRandom.randomArr(); + SysOut.printArray(arr); + selectSort(arr); + SysOut.printArray(arr); + if (!CompareUtils.isSortAsc(arr)) { + SysOut.println("。。。有问题❗️❗️❗️"); + Assert.assertTrue(false); + } - head = reverseK(head, 2); - SysOut.printLinkedNode(head); + SystemUtil.printLiteCuttingLine(); + } } - private LinkedNode reverseK(LinkedNode head, int k) { - if (head == null) { - return null; + private void selectSort(int[] arr) { + if (arr == null || arr.length == 0) { + return; } - LinkedNode dummyHead = new LinkedNode(); - dummyHead.next = head; - - while (dummyHead.next != null) { - - dummyHead.next = reverseN(dummyHead.next, k); - - for (int i = 0; i < k; i++) { - if (dummyHead.next == null) { - break; - } - dummyHead = dummyHead.next; + for (int end = arr.length - 1; end > 0; end--) { + int maxValueIndex = 0; + for (int i = 1; i <= end; i++) { + maxValueIndex = arr[maxValueIndex] > arr[i] ? maxValueIndex : i; } - + SwapUtil.swap(arr, maxValueIndex, end); } - - return dummyHead.next; } - private LinkedNode reverseN(LinkedNode head, int n) { - if (n == 1) { - return head; - } - - LinkedNode last = reverseN(head.next, n-1); - head.next.next = head; - head.next = null; - - return last; - } } diff --git a/src/main/java/algorithm_practice/algorithmzuo/README.md b/src/main/test/algorithmzuo/README.md similarity index 100% rename from src/main/java/algorithm_practice/algorithmzuo/README.md rename to src/main/test/algorithmzuo/README.md diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" similarity index 100% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" new file mode 100644 index 00000000..15798d46 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" @@ -0,0 +1,56 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SwapUtil; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/23 + */ +@Slf4j +public class Code01_SelectionSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + selectSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 从小到大排: + * i=0,j=i+1,每一轮都比较出一个最大值,放到最前面 + */ + private void selectSort(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + + for (int i = 0; i < arr.length - 1; i++) { + int minValueIndex = i; + for (int j = i + 1; j < arr.length; j++) { + minValueIndex = arr[minValueIndex] < arr[j] ? minValueIndex : j; + } + SwapUtil.swap(arr, minValueIndex, i); + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" new file mode 100644 index 00000000..fff3719a --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" @@ -0,0 +1,56 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SwapUtil; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/23 + */ +@Slf4j +public class Code02_BubbleSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + bubbleSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 从小到大排 + * arr[i] arr[i+1] 两两比较,每一轮,都比较出一个最大值,放到最后 + */ + private void bubbleSort(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + + for (int end = arr.length - 1; end > 0; end--) { + for (int i = 0; i < end; i++) { + if (arr[i] > arr[i + 1]) { + SwapUtil.swap(arr, i, i + 1); + } + } + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" new file mode 100644 index 00000000..2817661d --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" @@ -0,0 +1,57 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SwapUtil; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/06/21 + */ +@Slf4j +public class Code03_InsertionSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + insertSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 从小到大排(打扑克 抓牌、码牌) + * i=1, j=i,每一轮比较,都把arr[i] 安排到一个正确的位置 + * if(arr[j] < arr[j-1]) swap; + */ + private void insertSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + for (int i = 1; i < arr.length; i++) { + for (int j = i; j - 1 >= 0; j--) { + if (arr[j] < arr[j - 1]) { + SwapUtil.swap(arr, j, j - 1); + } + } + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" new file mode 100644 index 00000000..d933f818 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" @@ -0,0 +1,82 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/23 + */ +@Slf4j +public class Code04_1_MergeSort_Recursion { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + mergeSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 归并排序,递归版 + */ + private void mergeSort(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + + process(arr, 0, arr.length - 1); + } + + private void process(int[] arr, int left, int right) { + if (left == right) { + return; + } + + int mid = left + ((right - left) >> 1); + process(arr, left, mid); + process(arr, mid + 1, right); + merge(arr, left, mid, right); + } + + protected static void merge(int[] arr, int left, int mid, int right) { + int[] help = new int[right - left + 1]; + int p1 = left; + int p2 = mid + 1; + int index = 0; + while (p1 <= mid && p2 <= right) { + help[index++] = arr[p1] <= arr[p2] ? arr[p1++] : arr[p2++]; + } + + while (p1 <= mid) { + help[index++] = arr[p1++]; + } + + while (p2 <= right) { + help[index++] = arr[p2++]; + } + + for (int i = 0; i < help.length; i++) { + arr[left + i] = help[i]; + } + } + + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" new file mode 100644 index 00000000..c7713c84 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" @@ -0,0 +1,74 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/23 + */ +@Slf4j +public class Code04_2_MergeSort_Non_Recursion { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArrNaturalNum(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + mergeSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 归并排序,非递归版 + */ + private void mergeSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + + int mergeSize = 1; + int length = arr.length; + while (mergeSize < length) { + + // 按照步长,开始 merge + int left = 0; + while (left < length) { + if (length - left < mergeSize) { + // 此时已经不存在右边了。不需要再merge了 + break; + } + + int mid = left + mergeSize - 1; + int right = mid + Math.min(mergeSize, length - mid - 1); + + Code04_1_MergeSort_Recursion.merge(arr, left, mid, right); + left = right + 1; + } + + // 防止 mergeSize * 2 之后,导致 Integer 溢出 + if (mergeSize > length / 2) { + break; + } + mergeSize <<= 1; + } + + } + + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" new file mode 100644 index 00000000..d80936b2 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" @@ -0,0 +1,111 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.SysRandom; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/07/18 + */ +@Slf4j +public class Code04_3_SmallSum { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + int expectResult = comparator(arr); + + int smallSum = mergeSort(arr); + if (!CompareUtils.matchObject(smallSum, expectResult)) { + log.error("arr: {}", copyArr); + log.error("actual: {}, expect: {}", smallSum, expectResult); + throw new RuntimeException(); + } + } + + /** + * 小和问题 + * 在一个数组中,一个数左边比它小的数的总和,叫该数的小和。所有数的小和累加起来,叫数组小和 + * 例子: [1,3,4,2,5] + * 1左边比1小的数:没有 + * 3左边比3小的数:1 + * 4左边比4小的数:1、3 + * 2左边比2小的数:1 + * 5左边比5小的数:1、3、4、2 + * 所以数组的小和为1+1+3+1+1+3+4+2=16 + * 给定一个数组arr,求数组小和 + */ + private int mergeSort(int[] arr) { + if (arr == null || arr.length < 2) { + return 0; + } + + return process(arr, 0, arr.length - 1); + } + + private int process(int[] arr, int left, int right) { + if (left == right) { + return 0; + } + + + int mid = left + ((right - left) >> 1); + return process(arr, left, mid) + + process(arr, mid + 1, right) + + merge(arr, left, mid, right); + } + + private int merge(int[] arr, int left, int mid, int right) { + int[] help = new int[right - left + 1]; + int p1 = left; + int p2 = mid + 1; + int index = 0; + int smallSum = 0; + while (p1 <= mid && p2 <= right) { + if (arr[p1] < arr[p2]) { + smallSum += (right - p2 + 1) * arr[p1]; + help[index++] = arr[p1++]; + } else { + help[index++] = arr[p2++]; + } + } + + while (p1 <= mid) { + help[index++] = arr[p1++]; + } + while (p2 <= right) { + help[index++] = arr[p2++]; + } + for (int i = 0; i < help.length; i++) { + arr[left + i] = help[i]; + } + + return smallSum; + } + + //-------------------------- 对数器 --------------------------// + private int comparator(int[] arr) { + if (arr == null || arr.length < 2) { + return 0; + } + int res = 0; + for (int i = 1; i < arr.length; i++) { + for (int j = 0; j < i; j++) { + res += arr[j] < arr[i] ? arr[j] : 0; + } + } + return res; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" new file mode 100644 index 00000000..8928c27a --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" @@ -0,0 +1,104 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.SysRandom; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/07/21 + */ +@Slf4j +public class Code04_4_ReversePair { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + int expectResult = comparator(arr); + int reversePairCount = mergeSort(arr); + if (!CompareUtils.matchObject(reversePairCount, expectResult)) { + log.error("arr: {}", copyArr); + log.error("actual: {}, expect: {}", reversePairCount, expectResult); + throw new RuntimeException(); + } + } + + /** + * 逆序对问题 + * 在一个数组中,任何一个前面的数a,和任何一个后面的数b,如果(a,b)是降序的,就称为降序对 + * 给定一个数组arr,求数组的降序对总数量 + */ + private int mergeSort(int[] arr) { + if (arr == null || arr.length == 1) { + return 0; + } + + return process(arr, 0, arr.length - 1); + } + + private int process(int[] arr, int left, int right) { + if (left == right) { + return 0; + } + + int mid = left + ((right - left) >> 1); + return process(arr, left, mid) + + process(arr, mid + 1, right) + + merge(arr, left, mid, right); + } + + private int merge(int[] arr, int left, int mid, int right) { + int[] help = new int[right - left + 1]; + int p1 = mid; + int p2 = right; + int index = help.length - 1; + int reversePairCount = 0; + while (p1 >= left && p2 > mid) { + if (arr[p1] > arr[p2]) { + reversePairCount += p2 - mid; + help[index--] = arr[p1--]; + } else { + help[index--] = arr[p2--]; + } + } + + while (p1 >= left) { + help[index--] = arr[p1--]; + } + + while (p2 > mid) { + help[index--] = arr[p2--]; + } + + for (int i = 0; i < help.length; i++) { + arr[left + i] = help[i]; + } + + return reversePairCount; + } + + //-------------------------- 对数器 --------------------------// + private int comparator(int[] arr) { + int ans = 0; + for (int i = 0; i < arr.length; i++) { + for (int j = i + 1; j < arr.length; j++) { + if (arr[i] > arr[j]) { + ans++; + } + } + } + return ans; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" new file mode 100644 index 00000000..86c6c692 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" @@ -0,0 +1,112 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.SysRandom; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/07/21 + */ +@Slf4j +public class Code04_5_BiggerThanRightTwice { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArrNaturalNum(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + int expectResult = comparator(arr); + + int reversePairCount = mergeSort(arr); + if (!CompareUtils.matchObject(reversePairCount, expectResult)) { + log.error("arr: {}", copyArr); + log.error("actual: {}, expect: {}", reversePairCount, expectResult); + throw new RuntimeException(); + } + } + + /** + * 大于两倍问题 + * 在一个数组中,对于任何一个数num,求有多少个(后面的数*2)依然> 1); + return process(arr, left, mid) + + process(arr, mid + 1, right) + + merge(arr, left, mid, right); + } + + private int merge(int[] arr, int left, int mid, int right) { + int res = 0; + int p1 = left; + int p2 = mid + 1; + while (p1 <= mid) { + while (p2 <= right && (long) arr[p2] * 2 < arr[p1]) { + p2++; + } + res += p2 - (mid + 1); + p1++; + } + + int[] help = new int[right - left + 1]; + p1 = left; + p2 = mid + 1; + int index = 0; + while (p1 <= mid && p2 <= right) { + help[index++] = arr[p1] <= arr[p2] ? arr[p1++] : arr[p2++]; + } + + while (p1 <= mid) { + help[index++] = arr[p1++]; + } + while (p2 <= right) { + help[index++] = arr[p2++]; + } + for (int i = 0; i < help.length; i++) { + arr[left + i] = help[i]; + } + + return res; + } + + //-------------------------- 对数器 --------------------------// + private int comparator(int[] arr) { + int ans = 0; + for (int i = 0; i < arr.length; i++) { + for (int j = i + 1; j < arr.length; j++) { + if (arr[i] > (arr[j] << 1)) { + ans++; + } + } + } + return ans; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_6_CountOfRangeSum.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_6_CountOfRangeSum.java" new file mode 100644 index 00000000..6d3ba350 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_6_CountOfRangeSum.java" @@ -0,0 +1,122 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +/** + * Created by nibnait on 2022/07/21 + */ +@Slf4j +public class Code04_6_CountOfRangeSum { + + /** + * https://leetcode.cn/problems/count-of-range-sum/ + */ + @Test + public void testCase() { + int[] arr = new int[]{-2, 5, -1}; + int lower = -2; + int upper = 2; + int result = countRangeSum(arr, lower, upper); + int expect = 3; + if (!CompareUtils.matchObject(result, expect)) { + log.error("arr: {}\n actual: {}, expect: {}", arr, result, expect); + throw new RuntimeException(); + } + + arr = new int[]{0}; + lower = 0; + upper = 0; + result = countRangeSum(arr, lower, upper); + expect = 1; + if (!CompareUtils.matchObject(result, expect)) { + log.error("arr: {}\n actual: {}, expect: {}", arr, result, expect); + throw new RuntimeException(); + } + + arr = new int[]{0, 0}; + lower = 0; + upper = 0; + result = countRangeSum(arr, lower, upper); + expect = 3; + if (!CompareUtils.matchObject(result, expect)) { + log.error("arr: {}\n actual: {}, expect: {}", arr, result, expect); + throw new RuntimeException(); + } + } + + /** + * 这道题 有点绕 + * 要想求 nums[] 有多少个区间的和,在 [lower, upper]上。 + * 1. 先搞一个前缀和数组 sum[] + * sum[i] 代表: nums[0] ~ nums[i] 这个区间的和 + * sum[i] - sum[j] 代表: nums[j] ~ nums[i] 这个区间的和 + * 2. 借用归并排序,sum[left, mid], sum[mid+1, right] 的各自范围上都是有序的 + * 题目想求 以i位置结尾的子数组和在 [lower, upper] 范围上, + * 即在每次 merge 时,求有多少个前缀和在 [sum[i] - upper, sum[i] - lower) 上 + * + */ + private int countRangeSum(int[] nums, int lower, int upper) { + if (nums == null || nums.length == 0) { + return 0; + } + + long[] sum = new long[nums.length]; + sum[0] = nums[0]; + for (int i = 1; i < nums.length; i++) { + sum[i] = sum[i - 1] + nums[i]; + } + + return process(sum, 0, sum.length - 1, lower, upper); + } + + private int process(long[] sum, int left, int right, int lower, int upper) { + if (left == right) { + return sum[left] >= lower && sum[left] <= upper ? 1 : 0; + } + int mid = left + ((right - left) >> 1); + return process(sum, left, mid, lower, upper) + + process(sum, mid + 1, right, lower, upper) + + merge(sum, left, mid, right, lower, upper); + } + + private int merge(long[] sum, int left, int mid, int right, int lower, int upper) { + int p1 = left; + int p2 = left; + int res = 0; + // [p1, p2) + for (int i = mid + 1; i <= right; i++) { + long minValue = sum[i] - upper; + long maxValue = sum[i] - lower; + while (p1 <= mid && sum[p1] < minValue) { + p1++; + } + while (p2 <= mid && sum[p2] <= maxValue) { + p2++; + } + res += p2 - p1; + } + + long[] help = new long[right - left + 1]; + int index = 0; + p1 = left; + p2 = mid + 1; + while (p1 <= mid && p2 <= right) { + help[index++] = sum[p1] <= sum[p2] ? sum[p1++] : sum[p2++]; + } + + while (p1 <= mid) { + help[index++] = sum[p1++]; + } + while (p2 <= right) { + help[index++] = sum[p2++]; + } + for (int i = 0; i < help.length; i++) { + sum[left + i] = help[i]; + } + + return res; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" new file mode 100644 index 00000000..87f96397 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" @@ -0,0 +1,154 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SwapUtil; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/07/22 + */ +@Slf4j +public class Code05_1_PartitionAndQuickSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArr(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + quickSort3(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 快排1.0 + * 即:荷兰国旗1.0 + * arr[L...R], 以 arr[R] 为标准将数组划分成 + * <= arr[R] || > arr[R] 两部分 + */ + protected void quickSort1(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + + process1(arr, 0, arr.length - 1); + } + + private void process1(int[] arr, int left, int right) { + if (left >= right) { + return; + } + + int mid = netherlandsFlag1(arr, left, right); + process1(arr, left, mid - 1); + process1(arr, mid + 1, right); + } + + // 返回 <= 区,的右边界 + private int netherlandsFlag1(int[] arr, int left, int right) { + if (left > right) { + return -1; + } + if (left == right) { + return left; + } + int lessEqual = left - 1; + int index = left; + while (index < right) { + if (arr[index] <= arr[right]) { + SwapUtil.swap(arr, index++, ++lessEqual); + } else { + index++; + } + } + SwapUtil.swap(arr, ++lessEqual, right); + return lessEqual; + } + + + /** + * 快排2.0 + * 即:荷兰国旗问题2.0 + * arr[L...R], 以 arr[R] 为标准将数组划分为 + * < arr[R] || = arr[R] || > arr[R] 三部分 + */ + protected void quickSort2(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + process2(arr, 0, arr.length - 1); + } + + private void process2(int[] arr, int left, int right) { + if (left >= right) { + return; + } + int[] equalArea = netherlandsFlag2(arr, left, right); + process2(arr, left, equalArea[0] - 1); + process2(arr, equalArea[1] + 1, right); + } + + // 返回 =区 的左边界+右边界 + private int[] netherlandsFlag2(int[] arr, int left, int right) { + if (left > right) { + return new int[]{-1, -1}; + } + if (left == right) { + return new int[]{left, right}; + } + + // < 区的右边界 + int less = left - 1; + // > 区的左边界 + int more = right; + int index = left; + while (index < more) { + if (arr[index] < arr[right]) { + SwapUtil.swap(arr, index++, ++less); + } else if (arr[index] == arr[right]) { + index++; + } else { + SwapUtil.swap(arr, index, --more); + } + } + + SwapUtil.swap(arr, more, right); + return new int[]{less + 1, more}; + } + + /** + * 快排3.0 + * 在快排2.0的基础上,随机选一个数组中的数,作为标准值。(不再指定 arr[R]) + */ + protected void quickSort3(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + process3(arr, 0, arr.length - 1); + } + + private void process3(int[] arr, int left, int right) { + if (left >= right) { + return; + } + SwapUtil.swap(arr, left + (int) (Math.random() * (right - left + 1)), right); + int[] equalArea = netherlandsFlag2(arr, left, right); + process3(arr, left, equalArea[0] - 1); + process3(arr, equalArea[1] + 1, right); + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" new file mode 100644 index 00000000..a0ea0b10 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" @@ -0,0 +1,120 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SwapUtil; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; +import java.util.Stack; + +/** + * Created by nibnait on 2022/07/22 + */ +@Slf4j +public class Code05_2_QuickSortRecursionAndUnrecursion { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArrNaturalNum(10); + int[] copyArr = Arrays.copyOf(arr, arr.length); + quickSortWithStack(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 手写快排3.0 + */ + protected void quickSortRecursion(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + process(arr, 0, arr.length - 1); + } + + private void process(int[] arr, int left, int right) { + if (left >= right) { + return; + } + + SwapUtil.swap(arr, right, SysRandom.random(right - left + 1)); + int[] equalArea = partition(arr, left, right); + process(arr, left, equalArea[0] - 1); + process(arr, equalArea[1] + 1, right); + } + + private int[] partition(int[] arr, int left, int right) { + if (left > right) { + return new int[]{-1, -1}; + } + if (left == right) { + return new int[]{left, right}; + } + int less = left - 1; + int more = right; + int index = left; + while (index < more) { + if (arr[index] < arr[right]) { + SwapUtil.swap(arr, index++, ++less); + } else if (arr[index] == arr[right]) { + index++; + } else { + SwapUtil.swap(arr, index, --more); + } + } + SwapUtil.swap(arr, more, right); + return new int[]{less + 1, more}; + } + + /** + * 快排3.0 非递归 + * 用栈实现 + */ + protected void quickSortWithStack(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + int length = arr.length; + Stack stack = new Stack<>(); + + SwapUtil.swap(arr, length - 1, SysRandom.random(length)); + int[] partition = partition(arr, 0, length - 1); + stack.push(new SortArea(0, partition[0] - 1)); + stack.push(new SortArea(partition[1] + 1, length - 1)); + while (!stack.isEmpty()) { + SortArea sortArea = stack.pop(); + if (sortArea.left < sortArea.right) { + SwapUtil.swap(arr, sortArea.right, sortArea.left + SysRandom.random(sortArea.right - sortArea.left + 1)); + partition = partition(arr, sortArea.left, sortArea.right); + stack.push(new SortArea(sortArea.left, partition[0] - 1)); + stack.push(new SortArea(partition[1] + 1, sortArea.right)); + } + } + + } + + private static class SortArea { + public int left; + public int right; + + public SortArea(int left, int right) { + this.left = left; + this.right = right; + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" new file mode 100644 index 00000000..3599c011 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" @@ -0,0 +1,84 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SwapUtil; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/22 + */ +@Slf4j +public class Code06_1_HeapSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArrNaturalNum(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + heapSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + private void heapSort(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + + // heapInsert 构建一个堆。时间复杂度 O(N*logN) +// for (int i = 0; i < arr.length; i++) { +// heapInsert(arr, i); +// } + + // sinkDown 构建一个堆。时间复杂度 O(N) + for (int i = arr.length / 2; i >= 0; i--) { + sinkDown(arr, i, arr.length); + } + + int heapSize = arr.length; + SwapUtil.swap(arr, 0, --heapSize); + while (heapSize > 0) { + sinkDown(arr, 0, heapSize); + SwapUtil.swap(arr, 0, --heapSize); + } + } + + private void sinkDown(int[] arr, int curIndex, int heapSize) { + int leftChildIndex = curIndex * 2 + 1; + while (leftChildIndex < heapSize) { + int largerChildIndex = leftChildIndex + 1 < heapSize && arr[leftChildIndex + 1] > arr[leftChildIndex] ? leftChildIndex + 1 : leftChildIndex; + if (arr[largerChildIndex] < arr[curIndex]) { + break; + } + + SwapUtil.swap(arr, curIndex, largerChildIndex); + curIndex = largerChildIndex; + leftChildIndex = curIndex * 2 + 1; + } + } + + private void heapInsert(int[] arr, int curIndex) { + int fatherIndex = (curIndex - 1) / 2; + while (arr[fatherIndex] < arr[curIndex]) { + SwapUtil.swap(arr, curIndex, fatherIndex); + curIndex = fatherIndex; + fatherIndex = (curIndex - 1) / 2; + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" new file mode 100644 index 00000000..c5b98d0a --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" @@ -0,0 +1,95 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; +import java.util.PriorityQueue; + +/** + * Created by nibnait on 2022/10/22 + */ +@Slf4j +public class Code06_2_SortArrayDistanceLessK { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxSize = 100; + int maxValue = 100; + int k = SysRandom.random(maxSize); + int[] arr = randomArrayNoMoveMoreK(maxSize, maxValue, k); + int[] copyArr = Arrays.copyOf(arr, arr.length); + sortArrayDistanceLessK(arr, k); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + throw new RuntimeException(); + } + } + + /** + * 已知一个几乎有序的数组。请选择一个合适的排序策略,对这个数组进行排序。 + * 几乎有序是指,如果把数组排好顺序的话,每个元素移动的距离一定不超过k + * k相对于数组长度来说是比较小的。 + */ + private void sortArrayDistanceLessK(int[] arr, int k) { + if (k == 0) { + return; + } + + // 默认小根堆 + PriorityQueue heap = new PriorityQueue<>(); + + int index = 0; + int heapSize = Math.min(k, arr.length - 1); + while (index <= heapSize) { + heap.add(arr[index++]); + } + + int i = 0; + while (index < arr.length) { + heap.add(arr[index++]); + arr[i++] = heap.poll(); + } + + while (!heap.isEmpty()) { + arr[i++] = heap.poll(); + } + } + + //-------------------------- 对数器 --------------------------// + private static int[] randomArrayNoMoveMoreK(int maxSize, int maxValue, int K) { + int[] arr = new int[(int) ((maxSize + 1) * Math.random())]; + for (int i = 0; i < arr.length; i++) { + arr[i] = (int) ((maxValue + 1) * Math.random()) - (int) (maxValue * Math.random()); + } + // 先排个序 + Arrays.sort(arr); + // 然后开始随意交换,但是保证每个数距离不超过K + // swap[i] == true, 表示i位置已经参与过交换 + // swap[i] == false, 表示i位置没有参与过交换 + boolean[] isSwap = new boolean[arr.length]; + for (int i = 0; i < arr.length; i++) { + int j = Math.min(i + (int) (Math.random() * (K + 1)), arr.length - 1); + if (!isSwap[i] && !isSwap[j]) { + isSwap[i] = true; + isSwap[j] = true; + int tmp = arr[i]; + arr[i] = arr[j]; + arr[j] = tmp; + } + } + return arr; + } +} \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" new file mode 100644 index 00000000..b76ce8c5 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" @@ -0,0 +1,112 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import io.github.nibnait.common.utils.DataUtils; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; +import java.util.PriorityQueue; + +/** + * Created by nibnait on 2022/10/22 + */ +@Slf4j +public class Code06_3_CoverMax { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int N = 10; + int L = 0; + int R = 200; + int[][] lines = generateLines(N, L, R); + int expectResult = comparator(lines); + + int maxCover = maxCover(lines); + if (!CompareUtils.matchObject(maxCover, expectResult)) { + log.error("lines: {}", DataUtils.toJsonStringArray(lines)); + log.error("actual: {}, expect: {}", maxCover, expectResult); + throw new RuntimeException(); + } + } + + /** + * 给定很多线段,每个线段都有两个数[start, end], + * 表示线段开始位置和结束位置,左右都是闭区间 + * 规定: + * 1)线段的开始和结束位置一定都是整数值 + * 2)线段重合区域的长度必须>=1 + * 返回线段最多重合区域中,包含了几条线段 + */ + /** + * 先按照 每条线段的起点(line[0]) 从小到大排序 + * 准备一个小根堆 + * 遍历 lines 数组, + * 先把堆中<当前线段起点(line[0])的所有元素 pop出去 + * 把当前线段的终点(line[1]) push 进堆中 + * 计算和当前线段重合线段数 = heap.size + */ + private int maxCover(int[][] lines) { + if (lines == null || lines.length == 0) { + return 0; + } + // 按 lines[0][i] 线段头 排序 + Arrays.sort(lines, (a, b) -> (a[0] - b[0])); + // 小根堆 + PriorityQueue heap = new PriorityQueue<>(); + int ans = 0; + for (int[] line : lines) { + while (!heap.isEmpty() && heap.peek() <= line[0]) { + heap.poll(); + } + heap.add(line[1]); + ans = Math.max(ans, heap.size()); + } + + return ans; + } + + //-------------------------- 对数器 --------------------------// + private int comparator(int[][] lines) { + int min = Integer.MAX_VALUE; + int max = Integer.MIN_VALUE; + for (int i = 0; i < lines.length; i++) { + min = Math.min(min, lines[i][0]); + max = Math.max(max, lines[i][1]); + } + int cover = 0; + for (double p = min + 0.5; p < max; p += 1) { + int cur = 0; + for (int i = 0; i < lines.length; i++) { + if (lines[i][0] < p && lines[i][1] > p) { + cur++; + } + } + cover = Math.max(cover, cur); + } + return cover; + } + + private int[][] generateLines(int N, int L, int R) { + int size = (int) (Math.random() * N) + 1; + int[][] ans = new int[size][2]; + for (int i = 0; i < size; i++) { + int a = L + (int) (Math.random() * (R - L + 1)); + int b = L + (int) (Math.random() * (R - L + 1)); + if (a == b) { + b = a + 1; + } + ans[i][0] = Math.min(a, b); + ans[i][1] = Math.max(a, b); + } + return ans; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" new file mode 100644 index 00000000..eeb30f30 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" @@ -0,0 +1,64 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/23 + */ +@Slf4j +public class Code07_CountSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + // 全是自然数,范围 [0-100) + int arr[] = SysRandom.randomArrNaturalNum(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + countSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + } + } + + /** + * 比较适用于 年龄排序 + * (待排序的数组的范围是有限的) + * 准备若干个桶就好了。遍历到的数字是几,就放到几号桶里 + */ + private void countSort(int[] arr) { + if (arr == null || arr.length == 1) { + return; + } + + int max = Integer.MIN_VALUE; + for (int i = 0; i < arr.length; i++) { + max = Math.max(max, arr[i]); + } + int[] bucket = new int[max + 1]; + for (int i = 0; i < arr.length; i++) { + bucket[arr[i]]++; + } + + int i = 0; + for (int j = 0; j < bucket.length; j++) { + while (bucket[j]-- > 0) { + arr[i++] = j; + } + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" new file mode 100644 index 00000000..a2832b23 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" @@ -0,0 +1,97 @@ +package algorithmzuo.b_体系学习班.c0101_排序; + +import common.CommonConstants; +import common.util.CompareUtils; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/10/23 + */ +@Slf4j +public class Code08_RadixSort { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arr[] = SysRandom.randomArrNaturalNum(); + int[] copyArr = Arrays.copyOf(arr, arr.length); + radixSort(arr); + + if (!CompareUtils.isSortAsc(arr)) { + log.error("原数组: {}", copyArr); + log.error("排序后: {}", arr); + } + } + + /** + * 仅适用于 十进制的正数 + */ + private void radixSort(int[] arr) { + if (arr == null || arr.length < 2) { + return; + } + radixSort(arr, 0, arr.length - 1, maxbits(arr)); + } + + private int maxbits(int[] arr) { + int max = Integer.MIN_VALUE; + for (int i = 0; i < arr.length; i++) { + max = Math.max(max, arr[i]); + } + int res = 0; + while (max != 0) { + res++; + max /= 10; + } + return res; + } + + // arr[L..R]排序 , 最大值的十进制位数digit + private void radixSort(int[] arr, int L, int R, int digit) { + final int radix = 10; + int i = 0, j = 0; + // 有多少个数准备多少个辅助空间 + int[] help = new int[R - L + 1]; + for (int d = 1; d <= digit; d++) { // 有多少位就进出几次 + // 10个空间 + // count[0] 当前位(d位)是0的数字有多少个 + // count[1] 当前位(d位)是(0和1)的数字有多少个 + // count[2] 当前位(d位)是(0、1和2)的数字有多少个 + // count[i] 当前位(d位)是(0~i)的数字有多少个 + int[] count = new int[radix]; // count[0..9] + for (i = L; i <= R; i++) { + // 103 1 3 + // 209 1 9 + j = getDigit(arr[i], d); + count[j]++; + } + for (i = 1; i < radix; i++) { + count[i] = count[i] + count[i - 1]; + } + for (i = R; i >= L; i--) { + j = getDigit(arr[i], d); + help[count[j] - 1] = arr[i]; + count[j]--; + } + for (i = L, j = 0; i <= R; i++, j++) { + arr[i] = help[j]; + } + } + } + + private int getDigit(int x, int d) { + return ((x / ((int) Math.pow(10, d - 1))) % 10); + } + + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" similarity index 89% rename from "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" index f51d7438..632a98ca 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code01_BSExist.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_新手班.class03; +package algorithmzuo.b_体系学习班.c0102_二分查找; import common.CommonConstants; import common.util.SysOut; @@ -16,7 +16,7 @@ public class Code01_BSExist { @Test public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { int[] arr = SysRandom.randomArr(); Arrays.sort(arr); int num = 11; @@ -41,7 +41,7 @@ private int find(int[]arr, int num) { int left = 0; int right = arr.length - 1; while (left <= right) { - int mid = (left + right) / 2; + int mid = left + ((right - left) >> 1); if (arr[mid] == num) { return mid; } else if (arr[mid] > num) { diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" similarity index 90% rename from "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" index 76933ad9..d6f5ed38 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code02_BSNearLeft.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_新手班.class03; +package algorithmzuo.b_体系学习班.c0102_二分查找; import common.CommonConstants; import common.util.SysOut; @@ -15,7 +15,7 @@ public class Code02_BSNearLeft { @Test public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { int[] arr = SysRandom.randomArr(); Arrays.sort(arr); int num = 11; @@ -44,7 +44,7 @@ private int mostLeftNoLessNumIndex(int[]arr, int num) { int right = arr.length - 1; int ans = -1; while (left <= right) { - int mid = (left + right) / 2; + int mid = left + ((right - left) >> 1); if (arr[mid] >= num) { if (arr[mid] == num) { ans = mid; diff --git "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" similarity index 90% rename from "src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" index 3b60c9f8..eea3c3a8 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/a_\346\226\260\346\211\213\347\217\255/class03/Code03_BSNearRight.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.a_新手班.class03; +package algorithmzuo.b_体系学习班.c0102_二分查找; import common.CommonConstants; import common.util.SysOut; @@ -15,7 +15,7 @@ public class Code03_BSNearRight { @Test public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { int[] arr = SysRandom.randomArr(); Arrays.sort(arr); int num = 11; @@ -44,7 +44,7 @@ private int nearestIndex(int[] arr, int num) { int right = arr.length - 1; int ans = -1; while (left <= right) { - int mid = (left + right) / 2; + int mid = left + ((right - left) >> 1); if (arr[mid] <= num) { ans = mid; left = mid + 1; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code04_BSAwesome.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code04_BSAwesome.java" new file mode 100644 index 00000000..8e0d1bad --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code04_BSAwesome.java" @@ -0,0 +1,86 @@ +package algorithmzuo.b_体系学习班.c0102_二分查找; + +/** + * 局部最小值问题 + */ +public class Code04_BSAwesome { + + /** + * 定义何为局部最小值: + * arr[0] < arr[1],0位置是局部最小; + * arr[N-1] < arr[N-2],N-1位置是局部最小; + * arr[i-1] > arr[i] < arr[i+1],i位置是局部最小; + * 给定一个数组arr,已知任何两个相邻的数都不相等,找到随便一个局部最小位置返回 + */ + // 课上的代码 + public static int getLessIndex(int[] arr) { + if (arr == null || arr.length == 0) { + return -1; + } + if (arr.length == 1 || arr[0] < arr[1]) { + return 0; + } + if (arr[arr.length - 1] < arr[arr.length - 2]) { + return arr.length - 1; + } + int left = 1; + int right = arr.length - 2; + int mid = 0; + while (left < right) { + mid = (left + right) / 2; + if (arr[mid] > arr[mid - 1]) { + right = mid - 1; + } else if (arr[mid] > arr[mid + 1]) { + left = mid + 1; + } else { + return mid; + } + } + return left; + } + + // 验证得到的结果,是不是局部最小 + public static boolean isRight(int[] arr, int index) { + if (arr.length <= 1) { + return true; + } + if (index == 0) { + return arr[index] < arr[index + 1]; + } + if (index == arr.length - 1) { + return arr[index] < arr[index - 1]; + } + return arr[index] < arr[index - 1] && arr[index] < arr[index + 1]; + } + + // 为了测试 + // 生成相邻不相等的数组 + public static int[] generateRandomArray(int maxSize, int maxValue) { + int[] arr = new int[(int) (Math.random() * maxSize) + 1]; + arr[0] = (int) (Math.random() * maxValue) - (int) (Math.random() * maxValue); + for (int i = 1; i < arr.length; i++) { + do { + arr[i] = (int) (Math.random() * maxValue) - (int) (Math.random() * maxValue); + } while (arr[i] == arr[i - 1]); + } + return arr; + } + + // 为了测试 + public static void main(String[] args) { + int testTime = 500000; + int maxSize = 30; + int maxValue = 100; + System.out.println("测试开始"); + for (int i = 0; i < testTime; i++) { + int[] arr = generateRandomArray(maxSize, maxValue); + int ans = getLessIndex(arr); + if (!isRight(arr, ans)) { + System.out.println("出错了!"); + break; + } + } + System.out.println("测试结束"); + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code01_Swap.java" similarity index 86% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code01_Swap.java" index f9cd64b2..dc722f40 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code01_Swap.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code01_Swap.java" @@ -1,14 +1,12 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class02; +package algorithmzuo.b_体系学习班.c0103_异或运算; public class Code01_Swap { - + + /** + * 不用额外变量交换两个数的值 + */ public static void main(String[] args) { - - - - - int a = 16; int b = 603; @@ -25,8 +23,7 @@ public static void main(String[] args) { System.out.println(b); - - + int[] arr = {3,1,100}; int i = 0; @@ -38,13 +35,7 @@ public static void main(String[] args) { System.out.println(arr[i] + " , " + arr[j]); - - - - - - - + System.out.println(arr[0]); System.out.println(arr[2]); @@ -53,9 +44,6 @@ public static void main(String[] args) { System.out.println(arr[0]); System.out.println(arr[2]); - - - } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code02_EvenTimesOddTimes.java" similarity index 76% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code02_EvenTimesOddTimes.java" index 55940e57..e9666376 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code02_EvenTimesOddTimes.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code02_EvenTimesOddTimes.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class02; +package algorithmzuo.b_体系学习班.c0103_异或运算; import common.util.SysOut; import org.junit.Test; @@ -8,7 +8,9 @@ */ public class Code02_EvenTimesOddTimes { - // arr中,只有一种数,出现奇数次 + /** + * 一个数组中有一种数出现了奇数次,其他数都出现了偶数次,怎么找到并打印这种数 + */ @Test public void printOddTimesNum1() { int[] arr = {3, 3, 2, 3, 1, 1, 1, 3, 1, 1, 1}; @@ -26,7 +28,9 @@ public void printOddTimesNum1() { SysOut.println(eor); } - // 一个int类型的数,提取出它二进制中最右侧的1来 + /** + * 怎么把一个int类型的数,提取出二进制中最右侧的1来 + */ @Test public void bit1counts() { int num = 1744; @@ -40,7 +44,9 @@ public void bit1counts() { } - // arr中,有两种数,出现奇数次 + /** + * 一个数组中有两种数出现了奇数次,其他数都出现了偶数次,怎么找到并打印这两种数 + */ @Test public void printOddTimesNum2() { int[] arr = {4, 3, 4, 2, 2, 2, 4, 1, 1, 1, 3, 3, 1, 1, 1, 4, 2, 2}; diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" similarity index 88% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" index 44833745..1dbbd288 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class02/Code03_KM.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class02; +package algorithmzuo.b_体系学习班.c0103_异或运算; import common.CommonConstants; import common.util.SysOut; @@ -13,9 +13,14 @@ */ public class Code03_KM { + /** + * 一个数组中有一种数出现K次,其他数都出现了M次, + * 已知M > 1,K < M,找到出现了K次的数 + * 要求额外空间复杂度O(1),时间复杂度O(N) + */ @Test public void testCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_MIN; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_10; i++) { int a = SysRandom.random(9) + 1; int b = SysRandom.random(9) + 1; int k = Math.min(a, b); diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" similarity index 87% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" index 7af7405e..c59f5097 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_1_ReverseListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" @@ -1,10 +1,9 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0104_链表; import common.CommonConstants; import common.datastruct.LinkedNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; -import common.util.SysOut; import common.util.SysRandom; import org.junit.Assert; import org.junit.Test; @@ -29,12 +28,12 @@ public void loopTestCase() { public void testCase() { LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr()); LinkedNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); - SysOut.printLinkedNode("origin: ", head); +// SysOut.printLinkedNode("origin: ", head); LinkedNode actual = reverseList(head); - SysOut.printLinkedNode("reverse: ", actual); +// SysOut.printLinkedNode("reverse: ", actual); LinkedNode excepted = expectReverseListNode(copyHead); - SysOut.printLinkedNode("excepted: ", excepted); +// SysOut.printLinkedNode("excepted: ", excepted); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" similarity index 84% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" index ac7dec91..e41be41b 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code01_2_ReverseDoubleListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" @@ -1,10 +1,9 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0104_链表; import common.CommonConstants; import common.datastruct.LinkedNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; -import common.util.SysOut; import common.util.SysRandom; import org.junit.Assert; import org.junit.Test; @@ -20,7 +19,7 @@ public class Code01_2_ReverseDoubleListNode { @Test public void loopTestCase() { - for (int i = 0; i < CommonConstants.TEST_CASE_COUNT; i++) { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { testCase(); } } @@ -28,13 +27,13 @@ public void loopTestCase() { @Test public void testCase() { LinkedNode head = ConstructLinkedNode.constructDoubleLinkedNode(SysRandom.randomArr()); - SysOut.printDoubleLinkedNode("origin: ", head); +// SysOut.printDoubleLinkedNode("origin: ", head); LinkedNode copyHead = ConstructLinkedNode.copyDoubleLinkedNode(head); LinkedNode actual = reverseList(head); - SysOut.printDoubleLinkedNode("reverse: ", actual); +// SysOut.printDoubleLinkedNode("reverse: ", actual); LinkedNode excepted = expectReverseListNode(copyHead); - SysOut.printDoubleLinkedNode("excepted: ", excepted); +// SysOut.printDoubleLinkedNode("excepted: ", excepted); Assert.assertTrue(CompareUtils.compareDoubleListNode(excepted, actual)); } diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" similarity index 83% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" index a7100f4f..e6a2bde5 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code02_DeleteGivenValue.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" @@ -1,9 +1,8 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0104_链表; import common.CommonConstants; import common.datastruct.LinkedNode; import common.util.ConstructLinkedNode; -import common.util.SysOut; import common.util.SysRandom; import org.junit.Test; @@ -23,20 +22,20 @@ public void loopTestCase() { public void testCase() { LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr(20)); LinkedNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); - SysOut.printLinkedNode("before: ", head); +// SysOut.printLinkedNode("before: ", head); LinkedNode ans = deleteGivenValue(head, 11); - SysOut.printLinkedNode("after: ", ans); +// SysOut.printLinkedNode("after: ", ans); } @Test public void test() { LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{11,11,12,3,4,5}); // head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{3,4,5,11}); - SysOut.printLinkedNode("before: ", head); +// SysOut.printLinkedNode("before: ", head); LinkedNode ans = deleteGivenValue(head, 11); - SysOut.printLinkedNode("after: ", ans); +// SysOut.printLinkedNode("after: ", ans); } /** diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" new file mode 100644 index 00000000..c1c823b0 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" @@ -0,0 +1,168 @@ +package algorithmzuo.b_体系学习班.c0104_链表; + +import common.datastruct.LinkedNode; +import org.junit.Test; + +import java.util.ArrayList; + +public class Code03_LinkedListMid { + + @Test + public void test() { + LinkedNode test = null; + test = new LinkedNode(0); + test.next = new LinkedNode(1); + test.next.next = new LinkedNode(2); + test.next.next.next = new LinkedNode(3); + test.next.next.next.next = new LinkedNode(4); + test.next.next.next.next.next = new LinkedNode(5); + test.next.next.next.next.next.next = new LinkedNode(6); + test.next.next.next.next.next.next.next = new LinkedNode(7); + test.next.next.next.next.next.next.next.next = new LinkedNode(8); + + LinkedNode ans1 = null; + LinkedNode ans2 = null; + + ans1 = midOrUpMidLinkedNode(test); + ans2 = right1(test); + System.out.println(ans1 != null ? ans1.val : "无"); + System.out.println(ans2 != null ? ans2.val : "无"); + + ans1 = midOrDownMidLinkedNode(test); + ans2 = right2(test); + System.out.println(ans1 != null ? ans1.val : "无"); + System.out.println(ans2 != null ? ans2.val : "无"); + + ans1 = midOrUpMidPreLinkedNode(test); + ans2 = right3(test); + System.out.println(ans1 != null ? ans1.val : "无"); + System.out.println(ans2 != null ? ans2.val : "无"); + + ans1 = midOrDownMidPreLinkedNode(test); + ans2 = right4(test); + System.out.println(ans1 != null ? ans1.val : "无"); + System.out.println(ans2 != null ? ans2.val : "无"); + } + + /** + * 输入链表头节点,奇数长度返回中点,偶数长度返回上中点 + */ + public static LinkedNode midOrUpMidLinkedNode(LinkedNode head) { + if (head == null || head.next == null || head.next.next == null) { + return head; + } + // 链表有3个点或以上 + LinkedNode slow = head.next; + LinkedNode fast = head.next.next; + while (fast.next != null && fast.next.next != null) { + slow = slow.next; + fast = fast.next.next; + } + return slow; + } + + /** + * 输入链表头节点,奇数长度返回中点,偶数长度返回下中点 + */ + public static LinkedNode midOrDownMidLinkedNode(LinkedNode head) { + if (head == null || head.next == null) { + return head; + } + LinkedNode slow = head.next; + LinkedNode fast = head.next; + while (fast.next != null && fast.next.next != null) { + slow = slow.next; + fast = fast.next.next; + } + return slow; + } + + /** + * 输入链表头节点,奇数长度返回中点前一个,偶数长度返回上中点前一个 + */ + public static LinkedNode midOrUpMidPreLinkedNode(LinkedNode head) { + if (head == null || head.next == null || head.next.next == null) { + return null; + } + LinkedNode slow = head; + LinkedNode fast = head.next.next; + while (fast.next != null && fast.next.next != null) { + slow = slow.next; + fast = fast.next.next; + } + return slow; + } + + /** + * 输入链表头节点,奇数长度返回中点前一个,偶数长度返回下中点前一个 + */ + public static LinkedNode midOrDownMidPreLinkedNode(LinkedNode head) { + if (head == null || head.next == null) { + return null; + } + if (head.next.next == null) { + return head; + } + LinkedNode slow = head; + LinkedNode fast = head.next; + while (fast.next != null && fast.next.next != null) { + slow = slow.next; + fast = fast.next.next; + } + return slow; + } + + //-------------------------- 对数器 --------------------------// + public static LinkedNode right1(LinkedNode head) { + if (head == null) { + return null; + } + LinkedNode cur = head; + ArrayList arr = new ArrayList<>(); + while (cur != null) { + arr.add(cur); + cur = cur.next; + } + return arr.get((arr.size() - 1) / 2); + } + + public static LinkedNode right2(LinkedNode head) { + if (head == null) { + return null; + } + LinkedNode cur = head; + ArrayList arr = new ArrayList<>(); + while (cur != null) { + arr.add(cur); + cur = cur.next; + } + return arr.get(arr.size() / 2); + } + + public static LinkedNode right3(LinkedNode head) { + if (head == null || head.next == null || head.next.next == null) { + return null; + } + LinkedNode cur = head; + ArrayList arr = new ArrayList<>(); + while (cur != null) { + arr.add(cur); + cur = cur.next; + } + return arr.get((arr.size() - 3) / 2); + } + + public static LinkedNode right4(LinkedNode head) { + if (head == null || head.next == null) { + return null; + } + LinkedNode cur = head; + ArrayList arr = new ArrayList<>(); + while (cur != null) { + arr.add(cur); + cur = cur.next; + } + return arr.get((arr.size() - 2) / 2); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" new file mode 100644 index 00000000..427d3e70 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" @@ -0,0 +1,201 @@ +package algorithmzuo.b_体系学习班.c0104_链表; + +import common.datastruct.LinkedNode; +import org.junit.Test; + +import java.util.Stack; + +public class Code04_IsPalindromeList { + + /** + * 给定一个单链表的头节点head,请判断该链表是否为回文结构 + */ + @Test + public void test() { + LinkedNode head = null; + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(2); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(1); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(1); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(1); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(2); + head.next.next.next = new LinkedNode(1); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + head = new LinkedNode(1); + head.next = new LinkedNode(2); + head.next.next = new LinkedNode(3); + head.next.next.next = new LinkedNode(2); + head.next.next.next.next = new LinkedNode(1); + printLinkedList(head); + System.out.print(isPalindrome1(head) + " | "); + System.out.print(isPalindrome2(head) + " | "); + System.out.println(isPalindrome3(head) + " | "); + printLinkedList(head); + System.out.println("========================="); + + } + + // need n extra space + public static boolean isPalindrome1(LinkedNode head) { + Stack stack = new Stack(); + LinkedNode cur = head; + while (cur != null) { + stack.push(cur); + cur = cur.next; + } + while (head != null) { + if (head.val != stack.pop().val) { + return false; + } + head = head.next; + } + return true; + } + + // need n/2 extra space + public static boolean isPalindrome2(LinkedNode head) { + if (head == null || head.next == null) { + return true; + } + LinkedNode right = head.next; + LinkedNode cur = head; + while (cur.next != null && cur.next.next != null) { + right = right.next; + cur = cur.next.next; + } + Stack stack = new Stack(); + while (right != null) { + stack.push(right); + right = right.next; + } + while (!stack.isEmpty()) { + if (head.val != stack.pop().val) { + return false; + } + head = head.next; + } + return true; + } + + // need O(1) extra space + public static boolean isPalindrome3(LinkedNode head) { + if (head == null || head.next == null) { + return true; + } + LinkedNode n1 = head; + LinkedNode n2 = head; + while (n2.next != null && n2.next.next != null) { // find mid LinkedNode + n1 = n1.next; // n1 -> mid + n2 = n2.next.next; // n2 -> end + } + // n1 中点 + + + n2 = n1.next; // n2 -> right part first LinkedNode + n1.next = null; // mid.next -> null + LinkedNode n3 = null; + while (n2 != null) { // right part convert + n3 = n2.next; // n3 -> save next LinkedNode + n2.next = n1; // next of right LinkedNode convert + n1 = n2; // n1 move + n2 = n3; // n2 move + } + n3 = n1; // n3 -> save last LinkedNode + n2 = head;// n2 -> left first LinkedNode + boolean res = true; + while (n1 != null && n2 != null) { // check palindrome + if (n1.val != n2.val) { + res = false; + break; + } + n1 = n1.next; // left to mid + n2 = n2.next; // right to mid + } + n1 = n3.next; + n3.next = null; + while (n1 != null) { // recover list + n2 = n1.next; + n1.next = n3; + n3 = n1; + n1 = n2; + } + return res; + } + + public static void printLinkedList(LinkedNode LinkedNode) { + System.out.print("Linked List: "); + while (LinkedNode != null) { + System.out.print(LinkedNode.val + " "); + LinkedNode = LinkedNode.next; + } + System.out.println(); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" new file mode 100644 index 00000000..9fb015b7 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" @@ -0,0 +1,136 @@ +package algorithmzuo.b_体系学习班.c0104_链表; + +import common.datastruct.LinkedNode; +import org.junit.Test; + +public class Code05_SmallerEqualBigger { + + /** + * 给定一个单链表的头节点head,给定一个整数n,将链表按n划分成左边n + */ + @Test + public void test() { + LinkedNode head1 = new LinkedNode(7); + head1.next = new LinkedNode(9); + head1.next.next = new LinkedNode(1); + head1.next.next.next = new LinkedNode(8); + head1.next.next.next.next = new LinkedNode(5); + head1.next.next.next.next.next = new LinkedNode(2); + head1.next.next.next.next.next.next = new LinkedNode(5); + printLinkedList(head1); + // head1 = listPartition1(head1, 4); + head1 = listPartition2(head1, 5); + printLinkedList(head1); + } + + + public static LinkedNode listPartition1(LinkedNode head, int pivot) { + if (head == null) { + return head; + } + LinkedNode cur = head; + int i = 0; + while (cur != null) { + i++; + cur = cur.next; + } + LinkedNode[] LinkedNodeArr = new LinkedNode[i]; + i = 0; + cur = head; + for (i = 0; i != LinkedNodeArr.length; i++) { + LinkedNodeArr[i] = cur; + cur = cur.next; + } + arrPartition(LinkedNodeArr, pivot); + for (i = 1; i != LinkedNodeArr.length; i++) { + LinkedNodeArr[i - 1].next = LinkedNodeArr[i]; + } + LinkedNodeArr[i - 1].next = null; + return LinkedNodeArr[0]; + } + + public static void arrPartition(LinkedNode[] LinkedNodeArr, int pivot) { + int small = -1; + int big = LinkedNodeArr.length; + int index = 0; + while (index != big) { + if (LinkedNodeArr[index].val < pivot) { + swap(LinkedNodeArr, ++small, index++); + } else if (LinkedNodeArr[index].val == pivot) { + index++; + } else { + swap(LinkedNodeArr, --big, index); + } + } + } + + public static void swap(LinkedNode[] LinkedNodeArr, int a, int b) { + LinkedNode tmp = LinkedNodeArr[a]; + LinkedNodeArr[a] = LinkedNodeArr[b]; + LinkedNodeArr[b] = tmp; + } + + public static LinkedNode listPartition2(LinkedNode head, int pivot) { + LinkedNode sH = null; // small head + LinkedNode sT = null; // small tail + LinkedNode eH = null; // equal head + LinkedNode eT = null; // equal tail + LinkedNode mH = null; // big head + LinkedNode mT = null; // big tail + LinkedNode next = null; // save next LinkedNode + // every LinkedNode distributed to three lists + while (head != null) { + next = head.next; + head.next = null; + if (head.val < pivot) { + if (sH == null) { + sH = head; + sT = head; + } else { + sT.next = head; + sT = head; + } + } else if (head.val == pivot) { + if (eH == null) { + eH = head; + eT = head; + } else { + eT.next = head; + eT = head; + } + } else { + if (mH == null) { + mH = head; + mT = head; + } else { + mT.next = head; + mT = head; + } + } + head = next; + } + // 小于区域的尾巴,连等于区域的头,等于区域的尾巴连大于区域的头 + if (sT != null) { // 如果有小于区域 + sT.next = eH; + eT = eT == null ? sT : eT; // 下一步,谁去连大于区域的头,谁就变成eT + } + // 下一步,一定是需要用eT 去接 大于区域的头 + // 有等于区域,eT -> 等于区域的尾结点 + // 无等于区域,eT -> 小于区域的尾结点 + // eT 尽量不为空的尾巴节点 + if (eT != null) { // 如果小于区域和等于区域,不是都没有 + eT.next = mH; + } + return sH != null ? sH : (eH != null ? eH : mH); + } + + public static void printLinkedList(LinkedNode LinkedNode) { + System.out.print("Linked List: "); + while (LinkedNode != null) { + System.out.print(LinkedNode.val + " "); + LinkedNode = LinkedNode.next; + } + System.out.println(); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" new file mode 100644 index 00000000..83c238a2 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" @@ -0,0 +1,91 @@ +package algorithmzuo.b_体系学习班.c0104_链表; + +import java.util.HashMap; + +public class Code06_CopyListWithRandom { + + public static class Node { + int val; + Node next; + Node random; + + public Node(int val) { + this.val = val; + this.next = null; + this.random = null; + } + } + + /** + * https://leetcode.cn/problems/copy-list-with-random-pointer/ + * 一种特殊的单链表节点类描述如下 + * class Node { + * int value; + * Node next; + * Node rand; + * Node(int val) { value = val; } + * } + * rand指针是单链表节点结构中新增的指针,rand可能指向链表中的任意一个节点,也可能指向null + * 给定一个由Node节点类型组成的无环单链表的头节点head,请实现一个函数完成这个链表的复制 + * 返回复制的新链表的头节点,要求时间复杂度O(N),额外空间复杂度O(1) + */ + public static Node copyRandomList1(Node head) { + // key 老节点 + // value 新节点 + HashMap map = new HashMap(); + Node cur = head; + while (cur != null) { + map.put(cur, new Node(cur.val)); + cur = cur.next; + } + cur = head; + while (cur != null) { + // cur 老 + // map.get(cur) 新 + // 新.next -> cur.next克隆节点找到 + map.get(cur).next = map.get(cur.next); + map.get(cur).random = map.get(cur.random); + cur = cur.next; + } + return map.get(head); + } + + public static Node copyRandomList2(Node head) { + if (head == null) { + return null; + } + Node cur = head; + Node next = null; + // 1 -> 2 -> 3 -> null + // 1 -> 1' -> 2 -> 2' -> 3 -> 3' + while (cur != null) { + next = cur.next; + cur.next = new Node(cur.val); + cur.next.next = next; + cur = next; + } + cur = head; + Node copy = null; + // 1 1' 2 2' 3 3' + // 依次设置 1' 2' 3' random指针 + while (cur != null) { + next = cur.next.next; + copy = cur.next; + copy.random = cur.random != null ? cur.random.next : null; + cur = next; + } + Node res = head.next; + cur = head; + // 老 新 混在一起,next方向上,random正确 + // next方向上,把新老链表分离 + while (cur != null) { + next = cur.next.next; + copy = cur.next; + cur.next = next; + copy.next = next != null ? next.next : null; + cur = next; + } + return res; + } + +} diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code03_DoubleEndsQueueToStackAndQueue.java" similarity index 98% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code03_DoubleEndsQueueToStackAndQueue.java" index fdf12194..3b131079 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code03_DoubleEndsQueueToStackAndQueue.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code03_DoubleEndsQueueToStackAndQueue.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0105_栈和队列; import common.datastruct.Node; import io.github.nibnait.common.utils.compare.CompareUtils; diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code04_RingArray.java" similarity index 94% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code04_RingArray.java" index c30aab3b..bae943f2 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code04_RingArray.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code04_RingArray.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0105_栈和队列; /** * 用环形数组实现队列 diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code05_GetMinStack.java" similarity index 86% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code05_GetMinStack.java" index bed78dfc..79298c1c 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code05_GetMinStack.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code05_GetMinStack.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0105_栈和队列; /** * 实现有getMin功能的栈 diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code06_TwoStacksImplementQueue.java" similarity index 96% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code06_TwoStacksImplementQueue.java" index 8e15716d..9d49fa74 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code06_TwoStacksImplementQueue.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code06_TwoStacksImplementQueue.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0105_栈和队列; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code07_TwoQueueImplementStack.java" similarity index 97% rename from "src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code07_TwoQueueImplementStack.java" index 66091047..cd01deb3 100644 --- "a/src/main/java/algorithm_practice/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/class03/Code07_TwoQueueImplementStack.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code07_TwoQueueImplementStack.java" @@ -1,4 +1,4 @@ -package algorithm_practice.algorithmzuo.b_体系学习班.class03; +package algorithmzuo.b_体系学习班.c0105_栈和队列; import org.junit.Test; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" new file mode 100644 index 00000000..d3536dc4 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" @@ -0,0 +1,306 @@ +package algorithmzuo.b_体系学习班.c0106_前缀树; + +import java.util.HashMap; + +// 该程序完全正确 +public class Code01_TrieTree { + + public static class Node1 { + public int pass; + public int end; + public Node1[] nexts; + + // char tmp = 'b' (tmp - 'a') + public Node1() { + pass = 0; + end = 0; + // 0 a + // 1 b + // 2 c + // .. .. + // 25 z + // nexts[i] == null i方向的路不存在 + // nexts[i] != null i方向的路存在 + nexts = new Node1[26]; + } + } + + public static class Trie1 { + private Node1 root; + + public Trie1() { + root = new Node1(); + } + + public void insert(String word) { + if (word == null) { + return; + } + char[] str = word.toCharArray(); + Node1 node = root; + node.pass++; + int path = 0; + for (int i = 0; i < str.length; i++) { // 从左往右遍历字符 + path = str[i] - 'a'; // 由字符,对应成走向哪条路 + if (node.nexts[path] == null) { + node.nexts[path] = new Node1(); + } + node = node.nexts[path]; + node.pass++; + } + node.end++; + } + + public void delete(String word) { + if (search(word) != 0) { + char[] chs = word.toCharArray(); + Node1 node = root; + node.pass--; + int path = 0; + for (int i = 0; i < chs.length; i++) { + path = chs[i] - 'a'; + if (--node.nexts[path].pass == 0) { + node.nexts[path] = null; + return; + } + node = node.nexts[path]; + } + node.end--; + } + } + + // word这个单词之前加入过几次 + public int search(String word) { + if (word == null) { + return 0; + } + char[] chs = word.toCharArray(); + Node1 node = root; + int index = 0; + for (int i = 0; i < chs.length; i++) { + index = chs[i] - 'a'; + if (node.nexts[index] == null) { + return 0; + } + node = node.nexts[index]; + } + return node.end; + } + + // 所有加入的字符串中,有几个是以pre这个字符串作为前缀的 + public int prefixNumber(String pre) { + if (pre == null) { + return 0; + } + char[] chs = pre.toCharArray(); + Node1 node = root; + int index = 0; + for (int i = 0; i < chs.length; i++) { + index = chs[i] - 'a'; + if (node.nexts[index] == null) { + return 0; + } + node = node.nexts[index]; + } + return node.pass; + } + } + + public static class Node2 { + public int pass; + public int end; + public HashMap nexts; + + public Node2() { + pass = 0; + end = 0; + nexts = new HashMap<>(); + } + } + + public static class Trie2 { + private Node2 root; + + public Trie2() { + root = new Node2(); + } + + public void insert(String word) { + if (word == null) { + return; + } + char[] chs = word.toCharArray(); + Node2 node = root; + node.pass++; + int index = 0; + for (int i = 0; i < chs.length; i++) { + index = (int) chs[i]; + if (!node.nexts.containsKey(index)) { + node.nexts.put(index, new Node2()); + } + node = node.nexts.get(index); + node.pass++; + } + node.end++; + } + + public void delete(String word) { + if (search(word) != 0) { + char[] chs = word.toCharArray(); + Node2 node = root; + node.pass--; + int index = 0; + for (int i = 0; i < chs.length; i++) { + index = (int) chs[i]; + if (--node.nexts.get(index).pass == 0) { + node.nexts.remove(index); + return; + } + node = node.nexts.get(index); + } + node.end--; + } + } + + // word这个单词之前加入过几次 + public int search(String word) { + if (word == null) { + return 0; + } + char[] chs = word.toCharArray(); + Node2 node = root; + int index = 0; + for (int i = 0; i < chs.length; i++) { + index = (int) chs[i]; + if (!node.nexts.containsKey(index)) { + return 0; + } + node = node.nexts.get(index); + } + return node.end; + } + + // 所有加入的字符串中,有几个是以pre这个字符串作为前缀的 + public int prefixNumber(String pre) { + if (pre == null) { + return 0; + } + char[] chs = pre.toCharArray(); + Node2 node = root; + int index = 0; + for (int i = 0; i < chs.length; i++) { + index = (int) chs[i]; + if (!node.nexts.containsKey(index)) { + return 0; + } + node = node.nexts.get(index); + } + return node.pass; + } + } + + public static class Right { + + private HashMap box; + + public Right() { + box = new HashMap<>(); + } + + public void insert(String word) { + if (!box.containsKey(word)) { + box.put(word, 1); + } else { + box.put(word, box.get(word) + 1); + } + } + + public void delete(String word) { + if (box.containsKey(word)) { + if (box.get(word) == 1) { + box.remove(word); + } else { + box.put(word, box.get(word) - 1); + } + } + } + + public int search(String word) { + if (!box.containsKey(word)) { + return 0; + } else { + return box.get(word); + } + } + + public int prefixNumber(String pre) { + int count = 0; + for (String cur : box.keySet()) { + if (cur.startsWith(pre)) { + count += box.get(cur); + } + } + return count; + } + } + + // for test + public static String generateRandomString(int strLen) { + char[] ans = new char[(int) (Math.random() * strLen) + 1]; + for (int i = 0; i < ans.length; i++) { + int value = (int) (Math.random() * 6); + ans[i] = (char) (97 + value); + } + return String.valueOf(ans); + } + + // for test + public static String[] generateRandomStringArray(int arrLen, int strLen) { + String[] ans = new String[(int) (Math.random() * arrLen) + 1]; + for (int i = 0; i < ans.length; i++) { + ans[i] = generateRandomString(strLen); + } + return ans; + } + + public static void main(String[] args) { + int arrLen = 100; + int strLen = 20; + int testTimes = 100000; + for (int i = 0; i < testTimes; i++) { + String[] arr = generateRandomStringArray(arrLen, strLen); + Trie1 trie1 = new Trie1(); + Trie2 trie2 = new Trie2(); + Right right = new Right(); + for (int j = 0; j < arr.length; j++) { + double decide = Math.random(); + if (decide < 0.25) { + trie1.insert(arr[j]); + trie2.insert(arr[j]); + right.insert(arr[j]); + } else if (decide < 0.5) { + trie1.delete(arr[j]); + trie2.delete(arr[j]); + right.delete(arr[j]); + } else if (decide < 0.75) { + int ans1 = trie1.search(arr[j]); + int ans2 = trie2.search(arr[j]); + int ans3 = right.search(arr[j]); + if (ans1 != ans2 || ans2 != ans3) { + System.out.println("Oops!"); + } + } else { + int ans1 = trie1.prefixNumber(arr[j]); + int ans2 = trie2.prefixNumber(arr[j]); + int ans3 = right.prefixNumber(arr[j]); + if (ans1 != ans2 || ans2 != ans3) { + System.out.println("Oops!"); + } + } + } + } + System.out.println("finish!"); + + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" new file mode 100644 index 00000000..3ff94bec --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" @@ -0,0 +1,14 @@ +## 体系学习班 +class01 - class10 + +### 用master公式来估计时间复杂度 +Master 公式: +形如 T(N) = a * T(N/b) + O(N^d) (a、b、d都是常数)的递归函数,可以直接通过 Master 公式来确定时间复杂度 +- 如果 log(b,a) < d, 复杂度为 O(N^d) +- 如果 log(b,a) > d, 复杂度为 O(N^log(b,a)) +- 如果 log(b,a) == d, 复杂度为 O(N^d * logN) + +### 堆 和 加强堆 +[堆相关](../../../data_struct/堆) + +### \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" new file mode 100644 index 00000000..307102a1 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" @@ -0,0 +1 @@ +package algorithmzuo.b_体系学习班.c0201_; \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" new file mode 100644 index 00000000..934e1e71 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" @@ -0,0 +1,12 @@ +## 体系学习班 +class01 - class10 + +### 用master公式来估计时间复杂度 +Master 公式: +形如 T(N) = a * T(N/b) + O(N^d) (a、b、d都是常数)的递归函数,可以直接通过 Master 公式来确定时间复杂度 +- 如果 log(b,a) < d, 复杂度为 O(N^d) +- 如果 log(b,a) > d, 复杂度为 O(N^log(b,a)) +- 如果 log(b,a) == d, 复杂度为 O(N^d * logN) + +### 堆 和 加强堆 +[堆相关](../../../data_struct/堆) \ No newline at end of file diff --git "a/src/main/java/algorithm_practice/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" "b/src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" similarity index 100% rename from "src/main/java/algorithm_practice/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" rename to "src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" diff --git a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java new file mode 100644 index 00000000..9a135fb4 --- /dev/null +++ b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java @@ -0,0 +1,14 @@ +package cc.tianbin.java.mybatis; + +import org.apache.ibatis.binding.MapperMethod; +import org.junit.Test; + +/** + * Created by nibnait on 2022/10/18 + */ +public class MybatisTest { + + @Test + public void test() { + } +} diff --git a/src/main/test/cc/tianbin/java/spring/SpringTest.java b/src/main/test/cc/tianbin/java/spring/SpringTest.java new file mode 100644 index 00000000..1e70d584 --- /dev/null +++ b/src/main/test/cc/tianbin/java/spring/SpringTest.java @@ -0,0 +1,16 @@ +package cc.tianbin.java.spring; + +import org.junit.Test; + +/** + * Created by nibnait on 2022/09/30 + */ +public class SpringTest { + + @Test + public void test01() { + + + + } +} diff --git "a/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" index c6704b00..1ac64952 100644 --- "a/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" @@ -31,10 +31,8 @@ public void groupBy() { .collect(Collectors.groupingBy(Person::getName, Collectors.mapping(Person::getAge, Collectors.toList()))); log.info(DataUtils.toJsonStringObject(owner2ItemsIdMap)); - } - @Test public void comparing() { List personList = new ArrayList<>(); diff --git a/src/main/test/javalang/test/IfTest.java b/src/main/test/javalang/test/IfTest.java new file mode 100644 index 00000000..607592b5 --- /dev/null +++ b/src/main/test/javalang/test/IfTest.java @@ -0,0 +1,85 @@ +package javalang.test; + +import com.alibaba.fastjson.JSON; +import io.github.nibnait.common.constants.CommonConstants; +import io.github.nibnait.common.utils.DataUtils; +import lombok.Data; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +/** + * Created by nibnait on 2022/09/08 + */ +@Slf4j +public class IfTest { + + + + + + + + + + + + + + @Test + public void test01() { + String extraData = "{\"itemsId\":1}"; + ItemsExtDataVO itemsExtDataVO = ItemsExtDataVO.getExtVOByExtStr(extraData); + + long operateTime = itemsExtDataVO != null ? itemsExtDataVO.getOperateTime() : 0L; + System.out.println(operateTime); + } + + + + + + + + + + + + + + + + + @Data + public static class ItemsExtDataVO { + + /** + * 商品id + */ + private Long itemsId; + + /** + * 商品最近操作时间(单位 毫秒): + * - 商详点击【发布】商品后面审核流每一步的变动 + * - 单独修改库存和价格 + * - 上下架 + * - 撤回提审操作 + * 【目前只有商家平台列表页会用到专用】 + */ + private Long operateTime; + + public static ItemsExtDataVO getExtVOByExtStr(String ext) { + if (ext == null || "".equals(ext) || CommonConstants.NULL_STRING.equalsIgnoreCase(ext)) { + return null; + } + ItemsExtDataVO result = null; + try { + result = JSON.parseObject(ext, ItemsExtDataVO.class); + } catch (Exception e) { + log.error(DataUtils.format("ItemsExtDataVO.getExtVOByStr error, extraDataStr: {} ", ext), e); + } + return result; + } + } + + +} From 451784d8e1855772a2aec50c40d2d14abfb7724a Mon Sep 17 00:00:00 2001 From: tianbin Date: Tue, 25 Oct 2022 08:44:36 +0800 Subject: [PATCH 18/36] LinkedNode -> ListNode --- .obsidian/app.json | 1 + .obsidian/appearance.json | 3 + .obsidian/core-plugins.json | 19 +++ .obsidian/hotkeys.json | 1 + .obsidian/workspace.json | 144 ++++++++++++++++++ ...\345\244\215\345\205\203\347\264\240.java" | 10 +- ...\346\225\260\347\233\270\345\212\240.java" | 50 +++--- ...\344\270\252\350\212\202\347\202\271.java" | 20 +-- ...\347\232\204\350\212\202\347\202\271.java" | 24 +-- ...\350\275\254\351\223\276\350\241\250.java" | 20 +-- ...350\275\254\351\223\276\350\241\2502.java" | 26 ++-- ...\345\205\245\346\216\222\345\272\217.java" | 18 +-- ...\345\272\217\351\223\276\350\241\250.java" | 18 +-- ...\350\275\254\351\223\276\350\241\250.java" | 26 ++-- ...\347\232\204\347\273\223\347\202\271.java" | 14 +- ...\345\201\266\351\223\276\350\241\250.java" | 28 ++-- ...\351\227\264\347\273\223\347\202\271.java" | 6 +- ...\345\215\260\351\223\276\350\241\250.java" | 26 ++-- ...\350\241\250\347\273\223\347\202\271.java" | 20 +-- ...\344\270\252\347\273\223\347\202\271.java" | 20 +-- ...\350\275\254\351\223\276\350\241\250.java" | 32 ++-- ...\347\232\204\351\223\276\350\241\250.java" | 54 +++---- ...\345\205\261\347\273\223\347\202\271.java" | 72 ++++----- ...\345\217\243\347\273\223\347\202\271.java" | 44 +++--- ...\347\232\204\347\273\223\347\202\271.java" | 142 ++++++++--------- .../{LinkedNode.java => ListNode.java} | 15 +- src/main/java/common/util/CompareUtils.java | 6 +- .../java/common/util/ConstructLinkedNode.java | 38 ++--- src/main/java/common/util/SysOut.java | 10 +- src/main/test/UnitTestDemo.java | 1 + .../Code01_1_ReverseListNode.java" | 20 +-- .../Code01_2_ReverseDoubleListNode.java" | 20 +-- .../Code02_DeleteGivenValue.java" | 16 +- .../Code03_LinkedListMid.java" | 76 ++++----- .../Code04_IsPalindromeList.java" | 82 +++++----- .../Code05_SmallerEqualBigger.java" | 80 +++++----- .../Code07_FindFirstIntersectListNode.java" | 42 +++++ .../c01xx_summary.md" | 22 ++- 38 files changed, 751 insertions(+), 515 deletions(-) create mode 100644 .obsidian/app.json create mode 100644 .obsidian/appearance.json create mode 100644 .obsidian/core-plugins.json create mode 100644 .obsidian/hotkeys.json create mode 100644 .obsidian/workspace.json rename src/main/java/common/datastruct/{LinkedNode.java => ListNode.java} (59%) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" diff --git a/.obsidian/app.json b/.obsidian/app.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/.obsidian/app.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/.obsidian/appearance.json b/.obsidian/appearance.json new file mode 100644 index 00000000..c8c365d8 --- /dev/null +++ b/.obsidian/appearance.json @@ -0,0 +1,3 @@ +{ + "accentColor": "" +} \ No newline at end of file diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json new file mode 100644 index 00000000..96869dfd --- /dev/null +++ b/.obsidian/core-plugins.json @@ -0,0 +1,19 @@ +[ + "file-explorer", + "global-search", + "switcher", + "graph", + "backlink", + "outgoing-link", + "tag-pane", + "page-preview", + "daily-notes", + "templates", + "note-composer", + "command-palette", + "editor-status", + "starred", + "outline", + "word-count", + "file-recovery" +] \ No newline at end of file diff --git a/.obsidian/hotkeys.json b/.obsidian/hotkeys.json new file mode 100644 index 00000000..9e26dfee --- /dev/null +++ b/.obsidian/hotkeys.json @@ -0,0 +1 @@ +{} \ No newline at end of file diff --git a/.obsidian/workspace.json b/.obsidian/workspace.json new file mode 100644 index 00000000..4fb98dc3 --- /dev/null +++ b/.obsidian/workspace.json @@ -0,0 +1,144 @@ +{ + "main": { + "id": "f8f8bf0084662b96", + "type": "split", + "children": [ + { + "id": "562a022d8d3f23de", + "type": "tabs", + "children": [ + { + "id": "de478e1350dcc63b", + "type": "leaf", + "state": { + "type": "markdown", + "state": { + "file": "src/main/test/algorithmzuo/b_体系学习班/c01xx_summary.md", + "mode": "source", + "source": false + } + } + } + ] + } + ], + "direction": "vertical" + }, + "left": { + "id": "39d6ad5f24ea0a47", + "type": "split", + "children": [ + { + "id": "b6ba68a27e126ae7", + "type": "tabs", + "children": [ + { + "id": "3b088549f8ef430b", + "type": "leaf", + "state": { + "type": "file-explorer", + "state": { + "sortOrder": "alphabetical" + } + } + }, + { + "id": "8bd04676dcbd4227", + "type": "leaf", + "state": { + "type": "search", + "state": { + "query": "", + "matchingCase": false, + "explainSearch": false, + "collapseAll": false, + "extraContext": false, + "sortOrder": "alphabetical" + } + } + }, + { + "id": "0652bac4a6ad5994", + "type": "leaf", + "state": { + "type": "starred", + "state": {} + } + } + ] + } + ], + "direction": "horizontal", + "width": 300 + }, + "right": { + "id": "231a88f74a7f3619", + "type": "split", + "children": [ + { + "id": "005aafd8648043fa", + "type": "tabs", + "children": [ + { + "id": "f76efae53043d7b8", + "type": "leaf", + "state": { + "type": "backlink", + "state": { + "file": "src/main/test/algorithmzuo/b_体系学习班/c01xx_summary.md", + "collapseAll": false, + "extraContext": false, + "sortOrder": "alphabetical", + "showSearch": false, + "searchQuery": "", + "backlinkCollapsed": false, + "unlinkedCollapsed": true + } + } + }, + { + "id": "3f29cc4d01c84d4b", + "type": "leaf", + "state": { + "type": "outgoing-link", + "state": { + "file": "src/main/test/algorithmzuo/b_体系学习班/c01xx_summary.md", + "linksCollapsed": false, + "unlinkedCollapsed": true + } + } + }, + { + "id": "1eda0b327a762bc3", + "type": "leaf", + "state": { + "type": "tag", + "state": { + "sortOrder": "frequency", + "useHierarchy": true + } + } + }, + { + "id": "7d949761d7385226", + "type": "leaf", + "state": { + "type": "outline", + "state": { + "file": "src/main/test/algorithmzuo/b_体系学习班/c01xx_summary.md" + } + } + } + ] + } + ], + "direction": "horizontal", + "width": 300, + "collapsed": true + }, + "ribbon": { + "mostRecentAction": "" + }, + "active": "f76efae53043d7b8", + "lastOpenFiles": [] +} \ No newline at end of file diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" "b/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" index 9fd9178b..ed2571cd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; @@ -39,9 +39,9 @@ public void testCase() { } private void soutTest(int[] list) { - LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list); + ListNode before = ConstructLinkedNode.constructSingleLinkedNode(list); SysOut.printLinkedNode(before); - LinkedNode after = deleteDuplicates(before); + ListNode after = deleteDuplicates(before); SysOut.printLinkedNode(after); System.out.println(); } @@ -51,8 +51,8 @@ private void soutTest(int[] list) { * @param head * @return */ - public LinkedNode deleteDuplicates(LinkedNode head) { - LinkedNode currentNode = head; + public ListNode deleteDuplicates(ListNode head) { + ListNode currentNode = head; while (currentNode != null && currentNode.next != null) { if (currentNode.val == currentNode.next.val) { currentNode.next = currentNode.next.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" index 871a188c..ef8264b9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; /* 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个结点只能存储 一位 数字。 @@ -23,18 +23,18 @@ public class M002_两数相加 { public static void main(String[] args) { //1,8 0 //1, 9,9 - LinkedNode firstLinkedNode = new LinkedNode(2); - firstLinkedNode.next = new LinkedNode(7); - firstLinkedNode.next.next = new LinkedNode(1); + ListNode firstListNode = new ListNode(2); + firstListNode.next = new ListNode(7); + firstListNode.next.next = new ListNode(1); - LinkedNode secondLinkedNode = new LinkedNode(3); - secondLinkedNode.next = new LinkedNode(2); - secondLinkedNode.next.next = new LinkedNode(9); - secondLinkedNode.next.next.next = new LinkedNode(9); + ListNode secondListNode = new ListNode(3); + secondListNode.next = new ListNode(2); + secondListNode.next.next = new ListNode(9); + secondListNode.next.next.next = new ListNode(9); - addTwoNumbers(firstLinkedNode, secondLinkedNode).printListNode(); + addTwoNumbers(firstListNode, secondListNode).printListNode(); System.out.println(); - addTwoNumbers_v2(firstLinkedNode, secondLinkedNode).printListNode(); + addTwoNumbers_v2(firstListNode, secondListNode).printListNode(); } @@ -44,24 +44,24 @@ public static void main(String[] args) { * @param l2 * @return */ - private static LinkedNode addTwoNumbers_v2(LinkedNode l1, LinkedNode l2) { + private static ListNode addTwoNumbers_v2(ListNode l1, ListNode l2) { int carry = 0; - LinkedNode result = new LinkedNode(0); + ListNode result = new ListNode(0); result.next = sumListNode(l1, l2, carry); return result.next; } static int TEN = 10; - private static LinkedNode sumListNode(LinkedNode l1, LinkedNode l2, int carry) { + private static ListNode sumListNode(ListNode l1, ListNode l2, int carry) { if (l1 == null && l2 == null) { - return carry > 0 ? new LinkedNode(carry) : null; + return carry > 0 ? new ListNode(carry) : null; } int x = l1 == null ? 0 : l1.val; int y = l2 == null ? 0 : l2.val; int sum = x + y + carry; carry = sum / TEN; - LinkedNode sumNode = new LinkedNode(sum % TEN); + ListNode sumNode = new ListNode(sum % TEN); sumNode.next = sumListNode(l1 != null ? l1.next : null, l2 != null ? l2.next : null, carry); return sumNode; } @@ -76,17 +76,17 @@ private static LinkedNode sumListNode(LinkedNode l1, LinkedNode l2, int carry) { * @param l2 * @return */ - private static LinkedNode addTwoNumbers(LinkedNode l1, LinkedNode l2) { + private static ListNode addTwoNumbers(ListNode l1, ListNode l2) { int TEN = 10; - LinkedNode result = null; + ListNode result = null; int carry = 0; - LinkedNode valNode = new LinkedNode(0); + ListNode valNode = new ListNode(0); while (l1 != null || l2 != null) { int x = l1 == null ? 0 : l1.val; int y = l2 == null ? 0 : l2.val; int sum = x + y + carry; carry = sum / TEN; - valNode.next = new LinkedNode(sum % TEN); + valNode.next = new ListNode(sum % TEN); if (result == null) { result = valNode.next; } @@ -95,7 +95,7 @@ private static LinkedNode addTwoNumbers(LinkedNode l1, LinkedNode l2) { l2 = l2 != null ? l2.next : null; } if (carry > 0) { - valNode.next = new LinkedNode(carry); + valNode.next = new ListNode(carry); } return result; } @@ -109,23 +109,23 @@ private static LinkedNode addTwoNumbers(LinkedNode l1, LinkedNode l2) { * @param l2 * @return */ - private static LinkedNode daan(LinkedNode l1, LinkedNode l2) { + private static ListNode daan(ListNode l1, ListNode l2) { int TEN = 10; int carry = 0; - LinkedNode currentNode = new LinkedNode(0); - LinkedNode dummyHead = currentNode; + ListNode currentNode = new ListNode(0); + ListNode dummyHead = currentNode; while (l1 != null || l2 != null) { int x = l1 == null ? 0 : l1.val; int y = l2 == null ? 0 : l2.val; int sum = x + y + carry; carry = sum / TEN; - currentNode.next = new LinkedNode(sum % TEN); + currentNode.next = new ListNode(sum % TEN); currentNode = currentNode.next; l1 = l1 != null ? l1.next : null; l2 = l2 != null ? l2.next : null; } if (carry > 0) { - currentNode.next = new LinkedNode(carry); + currentNode.next = new ListNode(carry); } return dummyHead.next; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" index 9918f864..3d5ec103 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; @@ -32,19 +32,19 @@ public class M019_删除链表的倒数第N个节点 extends TestCase { public void testCase() { int[] list1 = {1,2,3,4,5}; int n = 2; - LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list1); + ListNode before = ConstructLinkedNode.constructSingleLinkedNode(list1); before.printListNode(); System.out.println(); - LinkedNode after = removeNthFromEnd(before, n); + ListNode after = removeNthFromEnd(before, n); after.printListNode(); System.out.println(); int[] list2 = {1}; int n2 = 1; - LinkedNode linkedNode2 = ConstructLinkedNode.constructSingleLinkedNode(list2); - SysOut.printLinkedNode(linkedNode2); - SysOut.printLinkedNode(removeNthFromEnd(linkedNode2, n2)); + ListNode listNode2 = ConstructLinkedNode.constructSingleLinkedNode(list2); + SysOut.printLinkedNode(listNode2); + SysOut.printLinkedNode(removeNthFromEnd(listNode2, n2)); } /** @@ -53,14 +53,14 @@ public void testCase() { * @param n * @return */ - public LinkedNode removeNthFromEnd(LinkedNode head, int n) { + public ListNode removeNthFromEnd(ListNode head, int n) { //指向最后一个结点 - LinkedNode lastNode = head; + ListNode lastNode = head; for (int i = 0; i < n-1; i++) { lastNode = lastNode.next; } - LinkedNode preNode = head; - LinkedNode curNode = head.next; + ListNode preNode = head; + ListNode curNode = head.next; if (lastNode == null || lastNode.next == null) { return curNode; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" index a07f1a93..f5d218b8 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; @@ -28,11 +28,11 @@ public void testCase() { } private void soutTest(int[] list) { - LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list); + ListNode before = ConstructLinkedNode.constructSingleLinkedNode(list); SysOut.printLinkedNode(before); - LinkedNode after_recursion = swapPairs_recursion(before); + ListNode after_recursion = swapPairs_recursion(before); SysOut.printLinkedNode(after_recursion); - LinkedNode after = swapPairs(ConstructLinkedNode.constructSingleLinkedNode(list)); + ListNode after = swapPairs(ConstructLinkedNode.constructSingleLinkedNode(list)); SysOut.printLinkedNode(after); System.out.println(); @@ -43,18 +43,18 @@ private void soutTest(int[] list) { * @param head * @return */ - public LinkedNode swapPairs(LinkedNode head) { + public ListNode swapPairs(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode next = head.next; - LinkedNode nextNext = next.next; + ListNode next = head.next; + ListNode nextNext = next.next; next.next = head; head.next = nextNext; - LinkedNode pre = head; + ListNode pre = head; while (nextNext != null && nextNext.next != null) { - LinkedNode next1 = nextNext.next; - LinkedNode nextNext1 = next1.next; + ListNode next1 = nextNext.next; + ListNode nextNext1 = next1.next; next1.next = nextNext; nextNext.next = nextNext1; @@ -66,11 +66,11 @@ public LinkedNode swapPairs(LinkedNode head) { return next; } - public LinkedNode swapPairs_recursion(LinkedNode head) { + public ListNode swapPairs_recursion(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode next = head.next; + ListNode next = head.next; head.next = swapPairs_recursion(next.next); next.next = head; return next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" index 49c62609..1f6b85f0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; @@ -50,28 +50,28 @@ public void testCase() { } private void soutTest(int[] list, int k) { - LinkedNode before = ConstructLinkedNode.constructSingleLinkedNode(list); + ListNode before = ConstructLinkedNode.constructSingleLinkedNode(list); SysOut.printLinkedNode(before); - LinkedNode after = rotateRight(before, k); + ListNode after = rotateRight(before, k); SysOut.printLinkedNode(after); System.out.println(); } - public LinkedNode rotateRight(LinkedNode head, int k) { + public ListNode rotateRight(ListNode head, int k) { if (head == null) { return null; } if (k == 0) { return head; } - LinkedNode newHeadPreNode = findKthToTail(head, k); - LinkedNode newHead = newHeadPreNode.next; + ListNode newHeadPreNode = findKthToTail(head, k); + ListNode newHead = newHeadPreNode.next; if (newHead == null) { return head; } newHeadPreNode.next = null; - LinkedNode lastNode = newHead; + ListNode lastNode = newHead; while (lastNode.next != null) { lastNode = lastNode.next; } @@ -86,9 +86,9 @@ public LinkedNode rotateRight(LinkedNode head, int k) { * @param k * @return */ - private LinkedNode findKthToTail(LinkedNode head, int k) { - LinkedNode p1 = head; - LinkedNode p2 = head; + private ListNode findKthToTail(ListNode head, int k) { + ListNode p1 = head; + ListNode p2 = head; int newK = 0; for (int i = 0; i < k; i++) { if (p2.next != null) { diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index 614b9907..8c6c5db0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code000; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysOut; @@ -28,10 +28,10 @@ public class M092_反转链表2 { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); int m = 2, n = 4; - LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 4, 3, 2, 5}); - LinkedNode actual = reverseBetween(head, m, n); + ListNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 4, 3, 2, 5}); + ListNode actual = reverseBetween(head, m, n); SysOut.printLinkedNode(actual); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); @@ -47,7 +47,7 @@ public void testCase() { /** * 递归 */ - public LinkedNode reverseBetween(LinkedNode head, int m, int n) { + public ListNode reverseBetween(ListNode head, int m, int n) { if (m == 1) { return reverseN(head, n); } @@ -57,17 +57,17 @@ public LinkedNode reverseBetween(LinkedNode head, int m, int n) { return head; } - LinkedNode lastNext = null; + ListNode lastNext = null; /** * reverse 前n个节点 */ - private LinkedNode reverseN(LinkedNode head, int n) { + private ListNode reverseN(ListNode head, int n) { if (n == 1) { lastNext = head.next; return head; } - LinkedNode last = reverseN(head.next, n-1); + ListNode last = reverseN(head.next, n-1); head.next.next = head; head.next = lastNext; @@ -78,13 +78,13 @@ private LinkedNode reverseN(LinkedNode head, int n) { /** * 非递归 */ - public LinkedNode reverseBetween2(LinkedNode head, int m, int n) { + public ListNode reverseBetween2(ListNode head, int m, int n) { if (head == null) { return null; } - LinkedNode dummyHead = new LinkedNode(); + ListNode dummyHead = new ListNode(); dummyHead.next = head; int index = 1; @@ -98,11 +98,11 @@ public LinkedNode reverseBetween2(LinkedNode head, int m, int n) { } // indexNode的前驱节点 - LinkedNode prev = dummyHead.next; - LinkedNode indexNode = prev.next; + ListNode prev = dummyHead.next; + ListNode indexNode = prev.next; while (indexNode != null && index+1 <= n) { // 把 indexNode 插在dummyHead 的后面。 - LinkedNode cur = new LinkedNode(indexNode.val); + ListNode cur = new ListNode(indexNode.val); prev.next = indexNode.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index 0c04411c..765e8a56 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code100; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysOut; @@ -42,9 +42,9 @@ public class M147_对链表进行插入排序 { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); - LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); - LinkedNode actual = insertionSortList(head); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); + ListNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + ListNode actual = insertionSortList(head); SysOut.printLinkedNode(actual); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); @@ -58,23 +58,23 @@ public void testCase() { /** * 双指针 */ - public LinkedNode insertionSortList(LinkedNode head) { + public ListNode insertionSortList(ListNode head) { if (head == null) { return null; } - LinkedNode dummyHead = new LinkedNode(); + ListNode dummyHead = new ListNode(); dummyHead.next = head; // 已排好序的最后一个节点 - LinkedNode p1 = head; + ListNode p1 = head; /** * p1的下一个节点 * 1. p1.val <= p2.val: 正常,已排好序,依次往后移动 * 2. p1.val > p2.val: p2应该从头开始找 第一个比p2大的值,把p2插在它前面 */ - LinkedNode p2 = p1.next; + ListNode p2 = p1.next; while (p2 != null) { @@ -82,7 +82,7 @@ public LinkedNode insertionSortList(LinkedNode head) { p1 = p1.next; } else { // 从头开始找 第一个比p2大的值,把p2插在它前面 - LinkedNode prev = dummyHead; + ListNode prev = dummyHead; while (prev.next.val < p2.val) { prev = prev.next; } diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 166dccf7..49e1b107 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code100; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysOut; @@ -36,9 +36,9 @@ public class M148_排序链表 { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{4,2,1,3}); - LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4}); - LinkedNode actual = sortList(head); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{4,2,1,3}); + ListNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4}); + ListNode actual = sortList(head); SysOut.printLinkedNode(actual); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); @@ -53,17 +53,17 @@ public void testCase() { /** * 双指针 */ - public LinkedNode sortList(LinkedNode head) { + public ListNode sortList(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode dummyHead = new LinkedNode(); + ListNode dummyHead = new ListNode(); dummyHead.next = head; // 指向当前 val最小的节点 - LinkedNode p1 = head; + ListNode p1 = head; // 指向当前 val最大的节点 - LinkedNode p2 = head.next; + ListNode p2 = head.next; if (p1.val > p2.val) { // 把 p2 挪到 p1 前面 p1.next = p2.next; @@ -74,7 +74,7 @@ public LinkedNode sortList(LinkedNode head) { p2 = dummyHead.next.next; } - LinkedNode cur = p2.next; + ListNode cur = p2.next; while (cur != null) { if (cur.val <= p1.val) { // 把 cur 挪到 p1 前面 diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index 4f23b02a..d89ba5ab 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code200; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysOut; @@ -28,9 +28,9 @@ public class E206_反转链表 { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); - LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{5, 4, 3, 2, 1}); - LinkedNode actual = reverseList(head); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + ListNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{5, 4, 3, 2, 1}); + ListNode actual = reverseList(head); SysOut.printLinkedNode(actual); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); @@ -39,12 +39,12 @@ public void testCase() { /** * labuladong 递归 */ - public LinkedNode reverseList(LinkedNode head) { + public ListNode reverseList(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode last = reverseList(head.next); + ListNode last = reverseList(head.next); head.next.next = head; head.next = null; @@ -54,13 +54,13 @@ public LinkedNode reverseList(LinkedNode head) { /** * 递归 */ - public LinkedNode reverseList3(LinkedNode head) { + public ListNode reverseList3(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode prev = reverseList(head.next); - LinkedNode p = prev; + ListNode prev = reverseList(head.next); + ListNode p = prev; while (p.next != null) { p = p.next; } @@ -73,19 +73,19 @@ public LinkedNode reverseList3(LinkedNode head) { /** * 非递归 */ - public LinkedNode reverseList2(LinkedNode head) { + public ListNode reverseList2(ListNode head) { if (head == null) { return null; } - LinkedNode dummyHead = new LinkedNode(); + ListNode dummyHead = new ListNode(); dummyHead.next = head; - LinkedNode cur = head.next; + ListNode cur = head.next; head.next = null; while (cur != null) { - LinkedNode next = cur.next; + ListNode next = cur.next; // 把 cur 插在 dummyHead.next cur.next = dummyHead.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" index 4a87c878..800b24de 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code200; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; @@ -37,15 +37,15 @@ public class E237_删除链表中的结点 extends TestCase { @Test public void testCase() { int[] list1 = {4,5,1,9}; - LinkedNode linkedNode1 = ConstructLinkedNode.constructSingleLinkedNode(list1); - SysOut.printLinkedNode(linkedNode1); - deleteNode(linkedNode1.next); - SysOut.printLinkedNode(linkedNode1); + ListNode listNode1 = ConstructLinkedNode.constructSingleLinkedNode(list1); + SysOut.printLinkedNode(listNode1); + deleteNode(listNode1.next); + SysOut.printLinkedNode(listNode1); } - public void deleteNode(LinkedNode node) { - LinkedNode nextNode = node.next; + public void deleteNode(ListNode node) { + ListNode nextNode = node.next; while (nextNode != null) { node.val = nextNode.val; nextNode = nextNode.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index 92dad2ff..33039fbc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code300; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysOut; @@ -35,9 +35,9 @@ public class M328_奇偶链表 { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); - LinkedNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); - LinkedNode actual = oddEvenList(head); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 2, 3, 4, 5}); + ListNode excepted = ConstructLinkedNode.constructSingleLinkedNode(new int[]{1, 3, 5, 2, 4}); + ListNode actual = oddEvenList(head); // SysOut.printList(actual); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); @@ -73,21 +73,21 @@ public void testCase() { * * 双指针 屡试不爽 */ - public LinkedNode oddEvenValList(LinkedNode head) { + public ListNode oddEvenValList(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode dummyHead = new LinkedNode(); + ListNode dummyHead = new ListNode(); dummyHead.next = head; // p1 指向奇数val 的节点 - LinkedNode p1 = dummyHead; + ListNode p1 = dummyHead; while (p1.next != null && p1.next.val % 2 == 0) { p1 = p1.next; } // p1.next 是 第一个奇数节点,把他挪到 dummyHead.next - LinkedNode cur = p1.next; + ListNode cur = p1.next; p1.next = cur.next; cur.next = dummyHead.next; @@ -96,7 +96,7 @@ public LinkedNode oddEvenValList(LinkedNode head) { p1 = cur; // p2 指向偶数val 的节点 - LinkedNode p2 = dummyHead.next; + ListNode p2 = dummyHead.next; while (p2.next != null && p2.next.val % 2 == 1) { p2 = p2.next; } @@ -112,7 +112,7 @@ public LinkedNode oddEvenValList(LinkedNode head) { cur = cur.next; while (cur != null) { if (cur.val % 2 == 1) { - LinkedNode next = cur.next; + ListNode next = cur.next; p2.next = cur.next; @@ -139,18 +139,18 @@ public LinkedNode oddEvenValList(LinkedNode head) { * 把第2、4、6...个节点放到后面 * 跟节点值的奇偶性无关。。。 */ - public LinkedNode oddEvenList(LinkedNode head) { + public ListNode oddEvenList(ListNode head) { if (head == null) { return null; } // 奇数编号 Node - LinkedNode p1 = head; + ListNode p1 = head; // 偶数编号 Node - LinkedNode evenHead = head.next; - LinkedNode p2 = head.next; + ListNode evenHead = head.next; + ListNode p2 = head.next; while (p2 != null && p2.next != null) { p1.next = p2.next; diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" index fcabed3d..50ad96f5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.LeetCode.code800; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysOut; import junit.framework.TestCase; @@ -59,13 +59,13 @@ public void testCase() { * @return */ - public LinkedNode middleNode(LinkedNode head) { + public ListNode middleNode(ListNode head) { if (head == null) { return null; } - List nodeList = new ArrayList<>(); + List nodeList = new ArrayList<>(); while (head != null) { nodeList.add(head); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" index 9e092341..fe96daec 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import java.util.Stack; @@ -16,7 +16,7 @@ public class b05_从尾到头打印链表 { * 递归 * @param head */ - private static void printListInverselyUsingRecursion(LinkedNode head) { + private static void printListInverselyUsingRecursion(ListNode head) { if (head == null){ return; } @@ -28,7 +28,7 @@ private static void printListInverselyUsingRecursion(LinkedNode head) { * 栈 * @param head */ - private static void printListInverselyUsingStack(LinkedNode head) { + private static void printListInverselyUsingStack(ListNode head) { if (head == null){ return; } @@ -46,17 +46,17 @@ private static void printListInverselyUsingStack(LinkedNode head) { * 利用头插法插入链表 * @param head */ - public static void reverseNode(LinkedNode head) { + public static void reverseNode(ListNode head) { if (head == null) { return ; } //最终翻转之后的 Node - LinkedNode node ; + ListNode node ; - LinkedNode pre = head; - LinkedNode cur = head.next; - LinkedNode next ; + ListNode pre = head; + ListNode cur = head.next; + ListNode next ; while(cur != null){ next = cur.next; @@ -80,11 +80,11 @@ public static void reverseNode(LinkedNode head) { public static void main(String[] args) { - LinkedNode head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(4); - head.next.next.next.next = new LinkedNode(5); + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + head.next.next.next.next = new ListNode(5); printListInverselyUsingStack(head); System.out.println(); printListInverselyUsingRecursion(head); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" index b1b7698b..241ac7ef 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.SysOut; import static common.util.SysOut.printLinkedNode; @@ -23,12 +23,12 @@ public class c13_删除链表结点 { public static void main(String[] args) { - LinkedNode head = new LinkedNode(1); - head.next = new LinkedNode(2); - LinkedNode middle = head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(4); - head.next.next.next.next = new LinkedNode(5); - LinkedNode last = head.next.next.next.next.next = new LinkedNode(6); + ListNode head = new ListNode(1); + head.next = new ListNode(2); + ListNode middle = head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + head.next.next.next.next = new ListNode(5); + ListNode last = head.next.next.next.next.next = new ListNode(6); head = deleteNodeInList(head, head); // 删除头结点 SysOut.printLinkedNode(head); @@ -38,20 +38,20 @@ public static void main(String[] args) { SysOut.printLinkedNode(head); } - private static LinkedNode deleteNodeInList(LinkedNode head, LinkedNode nodeToBeDeleted) { + private static ListNode deleteNodeInList(ListNode head, ListNode nodeToBeDeleted) { if (head==null || nodeToBeDeleted==null){ return head; } if (nodeToBeDeleted.next != null){ //只要删除的不是尾结点 - LinkedNode tmp = nodeToBeDeleted.next; + ListNode tmp = nodeToBeDeleted.next; nodeToBeDeleted.val = tmp.val; nodeToBeDeleted.next = tmp.next; tmp = null; } else if (head == nodeToBeDeleted){ //链表中就这么一个结点 nodeToBeDeleted = null; } else { //多个结点的情况下,删除尾结点 - LinkedNode tmp = head; + ListNode tmp = head; while (tmp.next != nodeToBeDeleted){ tmp = tmp.next; } diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" index 2e88847e..7333d09b 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; /** * 题目:输入一个链表,输出该链表中倒数第k 个结点. @@ -31,12 +31,12 @@ public class c15_链表中倒数第k个结点 { - public static LinkedNode findKthToTail(LinkedNode head, int k) { + public static ListNode findKthToTail(ListNode head, int k) { if (head==null || k<=0){ return null; } - LinkedNode p1 = head; - LinkedNode p2 = head; + ListNode p1 = head; + ListNode p2 = head; for (int i = 1; i < k; i++) { if (p2.next != null){ p2 = p2.next; @@ -53,12 +53,12 @@ public static LinkedNode findKthToTail(LinkedNode head, int k) { } public static void main(String[] args) { - LinkedNode head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(4); - head.next.next.next.next = new LinkedNode(5); - head.next.next.next.next.next = new LinkedNode(6); + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + head.next.next.next.next = new ListNode(5); + head.next.next.next.next.next = new ListNode(6); System.out.println(findKthToTail(head, 1).val); //倒数第1个 System.out.println(findKthToTail(head, 3).val); //中间的一个 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" index 072d4e37..c28754d0 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.SysOut; /** @@ -14,13 +14,13 @@ public class c16_反转链表 { - private static LinkedNode reverseList(LinkedNode head) { + private static ListNode reverseList(ListNode head) { if (head == null) { return null; } - LinkedNode root = new LinkedNode(); //逻辑头结点 + ListNode root = new ListNode(); //逻辑头结点 root.next = null; - LinkedNode next; + ListNode next; while (head != null){ next = head.next; head.next = root.next; @@ -35,15 +35,15 @@ private static LinkedNode reverseList(LinkedNode head) { * @param head * @return */ - private static LinkedNode reverseList2(LinkedNode head) { + private static ListNode reverseList2(ListNode head) { if (head == null) { return null; } - LinkedNode reverseHead = null; - LinkedNode cur = head; //当前结点 - LinkedNode pre = null; //当前结点的前一个结点 + ListNode reverseHead = null; + ListNode cur = head; //当前结点 + ListNode pre = null; //当前结点的前一个结点 // pre = null, 因为反转后,head.next = null; - LinkedNode next = null; + ListNode next = null; while (cur != null) { next = cur.next; if (next == null) { @@ -57,12 +57,12 @@ private static LinkedNode reverseList2(LinkedNode head) { } public static void main(String[] args) { - LinkedNode head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(4); - head.next.next.next.next = new LinkedNode(5); - head.next.next.next.next.next = new LinkedNode(6); + ListNode head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + head.next.next.next.next = new ListNode(5); + head.next.next.next.next.next = new ListNode(6); SysOut.printLinkedNode(head); head = reverseList(head); @@ -71,7 +71,7 @@ public static void main(String[] args) { SysOut.printLinkedNode(head); //当只有一个结点时 - LinkedNode head2 = new LinkedNode(1); + ListNode head2 = new ListNode(1); SysOut.printLinkedNode(head2); head = reverseList(head2); SysOut.printLinkedNode(head2); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" index ae35054a..eb4fd9f8 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.SysOut; /** @@ -20,16 +20,16 @@ public class c17_合并两个排序的链表 { * @param head2 * @return */ - public static LinkedNode mergeSortedLists(LinkedNode head1, LinkedNode head2) { + public static ListNode mergeSortedLists(ListNode head1, ListNode head2) { if (head1 == null) { return head2; } else if (head2 == null) { return head1; } - LinkedNode head = new LinkedNode(); - LinkedNode head1tmp = new LinkedNode(); //永远指向head1.next - LinkedNode head1ttmp = new LinkedNode(); //永远指向head1.next.next - LinkedNode head2tmp = new LinkedNode(); //永远指向head2.next + ListNode head = new ListNode(); + ListNode head1tmp = new ListNode(); //永远指向head1.next + ListNode head1ttmp = new ListNode(); //永远指向head1.next.next + ListNode head2tmp = new ListNode(); //永远指向head2.next //不管怎样,都让head2往head1上合并! if (head2.val < head1.val) { head = head1; @@ -76,14 +76,14 @@ public static LinkedNode mergeSortedLists(LinkedNode head1, LinkedNode head2) { * @param head2 * @return */ - private static LinkedNode mergeSortedLists2(LinkedNode head1, LinkedNode head2){ + private static ListNode mergeSortedLists2(ListNode head1, ListNode head2){ if (head1 == null) { return head2; } else if (head2 == null) { return head1; } - LinkedNode head = new LinkedNode(); - LinkedNode tail = head; //永远指向root链的末尾 + ListNode head = new ListNode(); + ListNode tail = head; //永远指向root链的末尾 while (head1!=null && head2!=null){ if (head1.val <= head2.val){ tail.next = head1; @@ -111,14 +111,14 @@ private static LinkedNode mergeSortedLists2(LinkedNode head1, LinkedNode head2){ * @param head2 * @return */ - private static LinkedNode mergeSortedLists3(LinkedNode head1, LinkedNode head2) { + private static ListNode mergeSortedLists3(ListNode head1, ListNode head2) { if (head1 == null) { return head2; } else if (head2 == null) { return head1; } - LinkedNode tmp = new LinkedNode(); + ListNode tmp = new ListNode(); if (head1.val <= head2.val){ tmp = head1; //head1.next = head2; tmp.next = mergeSortedLists3(head1.next, head2); @@ -132,32 +132,32 @@ private static LinkedNode mergeSortedLists3(LinkedNode head1, LinkedNode head2) public static void main(String[] args) { - LinkedNode head = new LinkedNode(2); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(4); - head.next.next.next.next = new LinkedNode(5); + ListNode head = new ListNode(2); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(4); + head.next.next.next.next = new ListNode(5); SysOut.printLinkedNode(head); - LinkedNode head2 = new LinkedNode(1); - head2.next = new LinkedNode(3); - head2.next.next = new LinkedNode(5); - head2.next.next.next = new LinkedNode(6); - head2.next.next.next.next = new LinkedNode(7); + ListNode head2 = new ListNode(1); + head2.next = new ListNode(3); + head2.next.next = new ListNode(5); + head2.next.next.next = new ListNode(6); + head2.next.next.next.next = new ListNode(7); SysOut.printLinkedNode(head2); head = mergeSortedLists2(head, head2); SysOut.printLinkedNode(head); System.out.println(); //1. head2插在head1和head1tmp中间 - LinkedNode head3 = new LinkedNode(1); - head3.next = new LinkedNode(6); - head3.next.next = new LinkedNode(7); + ListNode head3 = new ListNode(1); + head3.next = new ListNode(6); + head3.next.next = new ListNode(7); SysOut.printLinkedNode(head3); - LinkedNode head4 = new LinkedNode(2); - head4.next = new LinkedNode(3); - head4.next.next = new LinkedNode(4); + ListNode head4 = new ListNode(2); + head4.next = new ListNode(3); + head4.next.next = new ListNode(4); SysOut.printLinkedNode(head4); head3 = mergeSortedLists(head3, head4); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" index 48bf64a9..a75f963e 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode;; +import common.datastruct.ListNode;; /** * 题目:输入两个链表,找出它们的第一个公共结点。 @@ -34,12 +34,12 @@ */ public class e37_两个单向链表的第一个公共结点 { - public static LinkedNode getIntersectListNode(LinkedNode head1, LinkedNode head2) { + public static ListNode getIntersectListNode(ListNode head1, ListNode head2) { if (head1 == null || head2 == null) { return null; } - LinkedNode loop1 = getLoopListNode(head1); - LinkedNode loop2 = getLoopListNode(head2); + ListNode loop1 = getLoopListNode(head1); + ListNode loop2 = getLoopListNode(head2); if (loop1 == null && loop2 == null) { return noLoop(head1, head2); } @@ -55,12 +55,12 @@ public static LinkedNode getIntersectListNode(LinkedNode head1, LinkedNode head2 * @param head * @return */ - public static LinkedNode getLoopListNode(LinkedNode head) { + public static ListNode getLoopListNode(ListNode head) { if (head == null || head.next == null || head.next.next == null) { return null; } - LinkedNode n1 = head.next; // n1 -> slow - LinkedNode n2 = head.next.next; // n2 -> fast 一次走两步 + ListNode n1 = head.next; // n1 -> slow + ListNode n2 = head.next.next; // n2 -> fast 一次走两步 while (n1 != n2) { if (n2.next == null || n2.next.next == null) { return null; @@ -83,12 +83,12 @@ public static LinkedNode getLoopListNode(LinkedNode head) { * @param head2 * @return */ - public static LinkedNode noLoop(LinkedNode head1, LinkedNode head2) { + public static ListNode noLoop(ListNode head1, ListNode head2) { if (head1 == null || head2 == null) { return null; } - LinkedNode cur1 = head1; - LinkedNode cur2 = head2; + ListNode cur1 = head1; + ListNode cur2 = head2; int n = 0; while (cur1.next != null) { n++; @@ -124,9 +124,9 @@ public static LinkedNode noLoop(LinkedNode head1, LinkedNode head2) { * @param loop2 链表2的 第一个入环结点 * @return */ - public static LinkedNode bothLoop(LinkedNode head1, LinkedNode loop1, LinkedNode head2, LinkedNode loop2) { - LinkedNode cur1 = null; - LinkedNode cur2 = null; + public static ListNode bothLoop(ListNode head1, ListNode loop1, ListNode head2, ListNode loop2) { + ListNode cur1 = null; + ListNode cur2 = null; if (loop1 == loop2) { cur1 = head1; cur2 = head2; @@ -165,42 +165,42 @@ public static LinkedNode bothLoop(LinkedNode head1, LinkedNode loop1, LinkedNode public static void main(String[] args) { // 1->2->3->4->5->6->7->null - LinkedNode head1 = new LinkedNode(1); - head1.next = new LinkedNode(2); - head1.next.next = new LinkedNode(3); - head1.next.next.next = new LinkedNode(4); - head1.next.next.next.next = new LinkedNode(5); - head1.next.next.next.next.next = new LinkedNode(6); - head1.next.next.next.next.next.next = new LinkedNode(7); + ListNode head1 = new ListNode(1); + head1.next = new ListNode(2); + head1.next.next = new ListNode(3); + head1.next.next.next = new ListNode(4); + head1.next.next.next.next = new ListNode(5); + head1.next.next.next.next.next = new ListNode(6); + head1.next.next.next.next.next.next = new ListNode(7); // 0->9->8->6->7->null - LinkedNode head2 = new LinkedNode(0); - head2.next = new LinkedNode(9); - head2.next.next = new LinkedNode(8); + ListNode head2 = new ListNode(0); + head2.next = new ListNode(9); + head2.next.next = new ListNode(8); head2.next.next.next = head1.next.next.next.next.next; // 8->6 System.out.println(getIntersectListNode(head1, head2).val); // 1->2->3->4->5->6->7->4... - head1 = new LinkedNode(1); - head1.next = new LinkedNode(2); - head1.next.next = new LinkedNode(3); - head1.next.next.next = new LinkedNode(4); - head1.next.next.next.next = new LinkedNode(5); - head1.next.next.next.next.next = new LinkedNode(6); - head1.next.next.next.next.next.next = new LinkedNode(7); + head1 = new ListNode(1); + head1.next = new ListNode(2); + head1.next.next = new ListNode(3); + head1.next.next.next = new ListNode(4); + head1.next.next.next.next = new ListNode(5); + head1.next.next.next.next.next = new ListNode(6); + head1.next.next.next.next.next.next = new ListNode(7); head1.next.next.next.next.next.next = head1.next.next.next; // 7->4 // 0->9->8->2... - head2 = new LinkedNode(0); - head2.next = new LinkedNode(9); - head2.next.next = new LinkedNode(8); + head2 = new ListNode(0); + head2.next = new ListNode(9); + head2.next.next = new ListNode(8); head2.next.next.next = head1.next; // 8->2 System.out.println(getIntersectListNode(head1, head2).val); // 0->9->8->6->4->5->6.. - head2 = new LinkedNode(0); - head2.next = new LinkedNode(9); - head2.next.next = new LinkedNode(8); + head2 = new ListNode(0); + head2.next = new ListNode(9); + head2.next.next = new ListNode(8); head2.next.next.next = head1.next.next.next.next.next; // 8->6 System.out.println(getIntersectListNode(head1, head2).val); diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" index 226719f7..51de3dc2 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; /** * 题目:一个链表中包含环,如何找出环的入口结点? @@ -17,9 +17,9 @@ * Created by nibnait on 2016/10/3. */ public class h56_链表中环的入口结点 { - private static LinkedNode meetingNode(LinkedNode head) { - LinkedNode fast = head; - LinkedNode slow = head; + private static ListNode meetingNode(ListNode head) { + ListNode fast = head; + ListNode slow = head; while (fast != null && fast.next != null) { fast = fast.next.next; slow = slow.next; @@ -46,12 +46,12 @@ public static void main(String[] args) { } // 1->2->3->4->5->6 private static void test01() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(2); - LinkedNode n3 = new LinkedNode(3); - LinkedNode n4 = new LinkedNode(4); - LinkedNode n5 = new LinkedNode(5); - LinkedNode n6 = new LinkedNode(6); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); + ListNode n3 = new ListNode(3); + ListNode n4 = new ListNode(4); + ListNode n5 = new ListNode(5); + ListNode n6 = new ListNode(6); n1.next = n2; n2.next = n3; n3.next = n4; @@ -64,12 +64,12 @@ private static void test01() { // | | // +--------+ private static void test02() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(2); - LinkedNode n3 = new LinkedNode(3); - LinkedNode n4 = new LinkedNode(4); - LinkedNode n5 = new LinkedNode(5); - LinkedNode n6 = new LinkedNode(6); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); + ListNode n3 = new ListNode(3); + ListNode n4 = new ListNode(4); + ListNode n5 = new ListNode(5); + ListNode n6 = new ListNode(6); n1.next = n2; n2.next = n3; n3.next = n4; @@ -82,12 +82,12 @@ private static void test02() { // | | // +---+ private static void test03() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(2); - LinkedNode n3 = new LinkedNode(3); - LinkedNode n4 = new LinkedNode(4); - LinkedNode n5 = new LinkedNode(5); - LinkedNode n6 = new LinkedNode(6); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); + ListNode n3 = new ListNode(3); + ListNode n4 = new ListNode(4); + ListNode n5 = new ListNode(5); + ListNode n6 = new ListNode(6); n1.next = n2; n2.next = n3; n3.next = n4; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" index 98932205..a976518a 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ package algorithm_practice.SwordOffer.old; -import common.datastruct.LinkedNode;; +import common.datastruct.ListNode;; import common.util.SysOut; /** @@ -16,16 +16,16 @@ */ public class h57_删除链表中重复的结点 { - private static LinkedNode deleteDuplication(LinkedNode head) { + private static ListNode deleteDuplication(ListNode head) { if (head == null) { return null; } - LinkedNode root = new LinkedNode(); + ListNode root = new ListNode(); root.next = head; // 临时的头结点 - LinkedNode prev = root; // 当前结点的前驱结点 - LinkedNode node = head; // 当前处理的结点 + ListNode prev = root; // 当前结点的前驱结点 + ListNode node = head; // 当前处理的结点 while (node != null && node.next != null) { if (node.val == node.next.val) { while (node.next != null && node.next.val == node.val) { @@ -55,86 +55,86 @@ public static void main(String[] args) { } // 1->2->3->3->4->4->5 private static void test01() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(2); - LinkedNode n3 = new LinkedNode(3); - LinkedNode n4 = new LinkedNode(3); - LinkedNode n5 = new LinkedNode(4); - LinkedNode n6 = new LinkedNode(4); - LinkedNode n7 = new LinkedNode(5); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); + ListNode n3 = new ListNode(3); + ListNode n4 = new ListNode(3); + ListNode n5 = new ListNode(4); + ListNode n6 = new ListNode(4); + ListNode n7 = new ListNode(5); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->2->3->4->5->6->7 private static void test02() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(2); - LinkedNode n3 = new LinkedNode(3); - LinkedNode n4 = new LinkedNode(4); - LinkedNode n5 = new LinkedNode(5); - LinkedNode n6 = new LinkedNode(6); - LinkedNode n7 = new LinkedNode(7); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); + ListNode n3 = new ListNode(3); + ListNode n4 = new ListNode(4); + ListNode n5 = new ListNode(5); + ListNode n6 = new ListNode(6); + ListNode n7 = new ListNode(7); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->1->1->1->1->1->2 private static void test03() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(1); - LinkedNode n3 = new LinkedNode(1); - LinkedNode n4 = new LinkedNode(1); - LinkedNode n5 = new LinkedNode(1); - LinkedNode n6 = new LinkedNode(1); - LinkedNode n7 = new LinkedNode(2); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(1); + ListNode n3 = new ListNode(1); + ListNode n4 = new ListNode(1); + ListNode n5 = new ListNode(1); + ListNode n6 = new ListNode(1); + ListNode n7 = new ListNode(2); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->1->1->1->1->1->1 private static void test04() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(1); - LinkedNode n3 = new LinkedNode(1); - LinkedNode n4 = new LinkedNode(1); - LinkedNode n5 = new LinkedNode(1); - LinkedNode n6 = new LinkedNode(1); - LinkedNode n7 = new LinkedNode(1); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(1); + ListNode n3 = new ListNode(1); + ListNode n4 = new ListNode(1); + ListNode n5 = new ListNode(1); + ListNode n6 = new ListNode(1); + ListNode n7 = new ListNode(1); n1.next = n2; n2.next = n3; n3.next = n4; n4.next = n5; n5.next = n6; n6.next = n7; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->1->2->2->3->3->4->4 private static void test05() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(1); - LinkedNode n3 = new LinkedNode(2); - LinkedNode n4 = new LinkedNode(2); - LinkedNode n5 = new LinkedNode(3); - LinkedNode n6 = new LinkedNode(3); - LinkedNode n7 = new LinkedNode(4); - LinkedNode n8 = new LinkedNode(4); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(1); + ListNode n3 = new ListNode(2); + ListNode n4 = new ListNode(2); + ListNode n5 = new ListNode(3); + ListNode n6 = new ListNode(3); + ListNode n7 = new ListNode(4); + ListNode n8 = new ListNode(4); n1.next = n2; n2.next = n3; n3.next = n4; @@ -142,19 +142,19 @@ private static void test05() { n5.next = n6; n6.next = n7; n7.next = n8; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->1->2->3->3->4->5->5 private static void test06() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(1); - LinkedNode n3 = new LinkedNode(2); - LinkedNode n4 = new LinkedNode(3); - LinkedNode n5 = new LinkedNode(3); - LinkedNode n6 = new LinkedNode(4); - LinkedNode n7 = new LinkedNode(5); - LinkedNode n8 = new LinkedNode(5); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(1); + ListNode n3 = new ListNode(2); + ListNode n4 = new ListNode(3); + ListNode n5 = new ListNode(3); + ListNode n6 = new ListNode(4); + ListNode n7 = new ListNode(5); + ListNode n8 = new ListNode(5); n1.next = n2; n2.next = n3; n3.next = n4; @@ -162,20 +162,20 @@ private static void test06() { n5.next = n6; n6.next = n7; n7.next = n8; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->1->2->2->3->3->4->5->5 private static void test07() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(1); - LinkedNode n3 = new LinkedNode(2); - LinkedNode n4 = new LinkedNode(2); - LinkedNode n5 = new LinkedNode(3); - LinkedNode n6 = new LinkedNode(3); - LinkedNode n7 = new LinkedNode(4); - LinkedNode n8 = new LinkedNode(5); - LinkedNode n9 = new LinkedNode(5); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(1); + ListNode n3 = new ListNode(2); + ListNode n4 = new ListNode(2); + ListNode n5 = new ListNode(3); + ListNode n6 = new ListNode(3); + ListNode n7 = new ListNode(4); + ListNode n8 = new ListNode(5); + ListNode n9 = new ListNode(5); n1.next = n2; n2.next = n3; n3.next = n4; @@ -184,26 +184,26 @@ private static void test07() { n6.next = n7; n7.next = n8; n8.next = n9; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1->2 private static void test08() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode n2 = new LinkedNode(2); + ListNode n1 = new ListNode(1); + ListNode n2 = new ListNode(2); n1.next = n2; - LinkedNode result = deleteDuplication(n1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // 1 private static void test09() { - LinkedNode n1 = new LinkedNode(1); - LinkedNode result = deleteDuplication(n1); + ListNode n1 = new ListNode(1); + ListNode result = deleteDuplication(n1); SysOut.printLinkedNode(result); } // null private static void test10() { - LinkedNode result = deleteDuplication(null); + ListNode result = deleteDuplication(null); SysOut.printLinkedNode(result); } } diff --git a/src/main/java/common/datastruct/LinkedNode.java b/src/main/java/common/datastruct/ListNode.java similarity index 59% rename from src/main/java/common/datastruct/LinkedNode.java rename to src/main/java/common/datastruct/ListNode.java index 394810ff..8b33e79c 100644 --- a/src/main/java/common/datastruct/LinkedNode.java +++ b/src/main/java/common/datastruct/ListNode.java @@ -4,18 +4,23 @@ * LeetCode 链表结点 * Created by nibnait on 2016/9/20. */ -public class LinkedNode { +public class ListNode { public int val; - public LinkedNode prev = null; - public LinkedNode next = null; + public ListNode prev = null; + public ListNode next = null; - public LinkedNode() { + public ListNode() { } - public LinkedNode(int data){ + public ListNode(int data){ this.val = data; } + public ListNode(int val, ListNode next) { + this.val = val; + this.next = next; + } + public void printListNode() { String arrow = next != null ? "->" : ""; System.out.print(val + arrow); diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java index cc90cf18..2d8f1270 100644 --- a/src/main/java/common/util/CompareUtils.java +++ b/src/main/java/common/util/CompareUtils.java @@ -1,6 +1,6 @@ package common.util; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; /** * Created by nibnait on 2022/04/11 @@ -10,7 +10,7 @@ public class CompareUtils { /** * 对比两个链表 */ - public static boolean compareSingleListNode(LinkedNode left, LinkedNode right) { + public static boolean compareSingleListNode(ListNode left, ListNode right) { while (left != null && right != null && left.val == right.val) { left = left.next; right = right.next; @@ -18,7 +18,7 @@ public static boolean compareSingleListNode(LinkedNode left, LinkedNode right) { return left == right; } - public static boolean compareDoubleListNode(LinkedNode left, LinkedNode right) { + public static boolean compareDoubleListNode(ListNode left, ListNode right) { while (left != null && right != null && left.val == right.val) { left = left.next; right = right.next; diff --git a/src/main/java/common/util/ConstructLinkedNode.java b/src/main/java/common/util/ConstructLinkedNode.java index 60f8761b..b74d2192 100644 --- a/src/main/java/common/util/ConstructLinkedNode.java +++ b/src/main/java/common/util/ConstructLinkedNode.java @@ -1,6 +1,6 @@ package common.util; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; /** * 构造链表 @@ -8,27 +8,27 @@ */ public class ConstructLinkedNode { - public static LinkedNode constructSingleLinkedNode(int[] nums) { - LinkedNode head = new LinkedNode(); - LinkedNode curNode = head; + public static ListNode constructSingleLinkedNode(int[] nums) { + ListNode head = new ListNode(); + ListNode curNode = head; for (int i = 0; i < nums.length; i++) { curNode.val = nums[i]; if (i != nums.length - 1) { - curNode.next = new LinkedNode(); + curNode.next = new ListNode(); curNode = curNode.next; } } return head; } - public static LinkedNode copySingleLinkedNode(LinkedNode head) { - LinkedNode newHead = new LinkedNode(); - LinkedNode next = new LinkedNode(); + public static ListNode copySingleLinkedNode(ListNode head) { + ListNode newHead = new ListNode(); + ListNode next = new ListNode(); newHead.next = next; while (head != null) { next.val = head.val; if (head.next != null) { - next.next = new LinkedNode(); + next.next = new ListNode(); } next = next.next; head = head.next; @@ -36,17 +36,17 @@ public static LinkedNode copySingleLinkedNode(LinkedNode head) { return newHead.next; } - public static LinkedNode constructDoubleLinkedNode(int[] nums) { - LinkedNode head = new LinkedNode(); - LinkedNode prevNode = null; + public static ListNode constructDoubleLinkedNode(int[] nums) { + ListNode head = new ListNode(); + ListNode prevNode = null; - LinkedNode next = new LinkedNode(); + ListNode next = new ListNode(); head.next = next; for (int i = 0; i < nums.length; i++) { next.val = nums[i]; next.prev = prevNode; if (i != nums.length - 1) { - next.next = new LinkedNode(); + next.next = new ListNode(); } prevNode = next; @@ -55,15 +55,15 @@ public static LinkedNode constructDoubleLinkedNode(int[] nums) { return head.next; } - public static LinkedNode copyDoubleLinkedNode(LinkedNode head) { - LinkedNode newHead = new LinkedNode(); - LinkedNode next = new LinkedNode(); + public static ListNode copyDoubleLinkedNode(ListNode head) { + ListNode newHead = new ListNode(); + ListNode next = new ListNode(); newHead.next = next; - LinkedNode prevNode = null; + ListNode prevNode = null; while (head != null) { next.val = head.val; if (head.next != null) { - next.next = new LinkedNode(); + next.next = new ListNode(); } next.prev = prevNode; diff --git a/src/main/java/common/util/SysOut.java b/src/main/java/common/util/SysOut.java index 24334b50..e67581a9 100644 --- a/src/main/java/common/util/SysOut.java +++ b/src/main/java/common/util/SysOut.java @@ -1,7 +1,7 @@ package common.util; import common.datastruct.BinaryTreeNode; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import io.github.nibnait.common.exception.ClientViewException; import java.util.Stack; @@ -73,12 +73,12 @@ public static void printArray(int[] a) { } //*********** 打印链表 ************************************/ - public static void printLinkedNode(String format, LinkedNode head) { + public static void printLinkedNode(String format, ListNode head) { print(format); printLinkedNode(head); } - public static void printLinkedNode(LinkedNode head) { + public static void printLinkedNode(ListNode head) { while (head != null) { String arrow = head != null ? " -> " : ""; print(head.val + arrow); @@ -87,12 +87,12 @@ public static void printLinkedNode(LinkedNode head) { println("null"); } - public static void printDoubleLinkedNode(String format, LinkedNode head) { + public static void printDoubleLinkedNode(String format, ListNode head) { print(format); printDoubleLinkedNode(head); } - public static void printDoubleLinkedNode(LinkedNode head) { + public static void printDoubleLinkedNode(ListNode head) { print("NULL <- "); Integer prevVal = null; while (head != null) { diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java index bf0f0e74..f2170a29 100644 --- a/src/main/test/UnitTestDemo.java +++ b/src/main/test/UnitTestDemo.java @@ -27,6 +27,7 @@ public void testCase() { if (!CompareUtils.isSortAsc(arr)) { log.error("原数组: {}", copyArr); log.error("排序后: {}", arr); + throw new RuntimeException(); } } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" index c59f5097..5adb1822 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" @@ -1,7 +1,7 @@ package algorithmzuo.b_体系学习班.c0104_链表; import common.CommonConstants; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysRandom; @@ -26,13 +26,13 @@ public void loopTestCase() { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr()); - LinkedNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr()); + ListNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); // SysOut.printLinkedNode("origin: ", head); - LinkedNode actual = reverseList(head); + ListNode actual = reverseList(head); // SysOut.printLinkedNode("reverse: ", actual); - LinkedNode excepted = expectReverseListNode(copyHead); + ListNode excepted = expectReverseListNode(copyHead); // SysOut.printLinkedNode("excepted: ", excepted); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); } @@ -40,9 +40,9 @@ public void testCase() { /** * 反转链表 */ - private LinkedNode reverseList(LinkedNode head) { - LinkedNode pre = null; - LinkedNode next = null; + private ListNode reverseList(ListNode head) { + ListNode pre = null; + ListNode next = null; while (head != null) { next = head.next; head.next = pre; @@ -57,8 +57,8 @@ private LinkedNode reverseList(LinkedNode head) { /** * 用数组对数器,验证反转链表 */ - private LinkedNode expectReverseListNode(LinkedNode head) { - List list = new ArrayList<>(); + private ListNode expectReverseListNode(ListNode head) { + List list = new ArrayList<>(); while (head != null) { list.add(head); head = head.next; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" index e41be41b..cb95f959 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" @@ -1,7 +1,7 @@ package algorithmzuo.b_体系学习班.c0104_链表; import common.CommonConstants; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.CompareUtils; import common.util.ConstructLinkedNode; import common.util.SysRandom; @@ -26,13 +26,13 @@ public void loopTestCase() { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructDoubleLinkedNode(SysRandom.randomArr()); + ListNode head = ConstructLinkedNode.constructDoubleLinkedNode(SysRandom.randomArr()); // SysOut.printDoubleLinkedNode("origin: ", head); - LinkedNode copyHead = ConstructLinkedNode.copyDoubleLinkedNode(head); + ListNode copyHead = ConstructLinkedNode.copyDoubleLinkedNode(head); - LinkedNode actual = reverseList(head); + ListNode actual = reverseList(head); // SysOut.printDoubleLinkedNode("reverse: ", actual); - LinkedNode excepted = expectReverseListNode(copyHead); + ListNode excepted = expectReverseListNode(copyHead); // SysOut.printDoubleLinkedNode("excepted: ", excepted); Assert.assertTrue(CompareUtils.compareDoubleListNode(excepted, actual)); } @@ -40,9 +40,9 @@ public void testCase() { /** * 反转双向链表 */ - private LinkedNode reverseList(LinkedNode head) { - LinkedNode pre = null; - LinkedNode next = null; + private ListNode reverseList(ListNode head) { + ListNode pre = null; + ListNode next = null; while (head != null) { next = head.next; head.next = pre; @@ -57,8 +57,8 @@ private LinkedNode reverseList(LinkedNode head) { /** * 用数组对数器,验证反转链表 */ - private LinkedNode expectReverseListNode(LinkedNode head) { - List list = new ArrayList<>(); + private ListNode expectReverseListNode(ListNode head) { + List list = new ArrayList<>(); while (head != null) { list.add(head); head = head.next; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" index e6a2bde5..5daf38fe 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" @@ -1,7 +1,7 @@ package algorithmzuo.b_体系学习班.c0104_链表; import common.CommonConstants; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import common.util.ConstructLinkedNode; import common.util.SysRandom; import org.junit.Test; @@ -20,28 +20,28 @@ public void loopTestCase() { @Test public void testCase() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr(20)); - LinkedNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr(20)); + ListNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); // SysOut.printLinkedNode("before: ", head); - LinkedNode ans = deleteGivenValue(head, 11); + ListNode ans = deleteGivenValue(head, 11); // SysOut.printLinkedNode("after: ", ans); } @Test public void test() { - LinkedNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{11,11,12,3,4,5}); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{11,11,12,3,4,5}); // head = ConstructLinkedNode.constructSingleLinkedNode(new int[]{3,4,5,11}); // SysOut.printLinkedNode("before: ", head); - LinkedNode ans = deleteGivenValue(head, 11); + ListNode ans = deleteGivenValue(head, 11); // SysOut.printLinkedNode("after: ", ans); } /** * 在链表中删除指定值的所有节点 */ - private LinkedNode deleteGivenValue(LinkedNode head, int num) { + private ListNode deleteGivenValue(ListNode head, int num) { if (head == null) { return head; } @@ -50,7 +50,7 @@ private LinkedNode deleteGivenValue(LinkedNode head, int num) { head = head.next; } - LinkedNode cursor = head; + ListNode cursor = head; while (cursor != null && cursor.next != null) { if (cursor.next.val == num) { cursor.next = cursor.next.next; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" index c1c823b0..524852a2 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" @@ -1,6 +1,6 @@ package algorithmzuo.b_体系学习班.c0104_链表; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import org.junit.Test; import java.util.ArrayList; @@ -9,19 +9,19 @@ public class Code03_LinkedListMid { @Test public void test() { - LinkedNode test = null; - test = new LinkedNode(0); - test.next = new LinkedNode(1); - test.next.next = new LinkedNode(2); - test.next.next.next = new LinkedNode(3); - test.next.next.next.next = new LinkedNode(4); - test.next.next.next.next.next = new LinkedNode(5); - test.next.next.next.next.next.next = new LinkedNode(6); - test.next.next.next.next.next.next.next = new LinkedNode(7); - test.next.next.next.next.next.next.next.next = new LinkedNode(8); - - LinkedNode ans1 = null; - LinkedNode ans2 = null; + ListNode test = null; + test = new ListNode(0); + test.next = new ListNode(1); + test.next.next = new ListNode(2); + test.next.next.next = new ListNode(3); + test.next.next.next.next = new ListNode(4); + test.next.next.next.next.next = new ListNode(5); + test.next.next.next.next.next.next = new ListNode(6); + test.next.next.next.next.next.next.next = new ListNode(7); + test.next.next.next.next.next.next.next.next = new ListNode(8); + + ListNode ans1 = null; + ListNode ans2 = null; ans1 = midOrUpMidLinkedNode(test); ans2 = right1(test); @@ -47,13 +47,13 @@ public void test() { /** * 输入链表头节点,奇数长度返回中点,偶数长度返回上中点 */ - public static LinkedNode midOrUpMidLinkedNode(LinkedNode head) { + public static ListNode midOrUpMidLinkedNode(ListNode head) { if (head == null || head.next == null || head.next.next == null) { return head; } // 链表有3个点或以上 - LinkedNode slow = head.next; - LinkedNode fast = head.next.next; + ListNode slow = head.next; + ListNode fast = head.next.next; while (fast.next != null && fast.next.next != null) { slow = slow.next; fast = fast.next.next; @@ -64,12 +64,12 @@ public static LinkedNode midOrUpMidLinkedNode(LinkedNode head) { /** * 输入链表头节点,奇数长度返回中点,偶数长度返回下中点 */ - public static LinkedNode midOrDownMidLinkedNode(LinkedNode head) { + public static ListNode midOrDownMidLinkedNode(ListNode head) { if (head == null || head.next == null) { return head; } - LinkedNode slow = head.next; - LinkedNode fast = head.next; + ListNode slow = head.next; + ListNode fast = head.next; while (fast.next != null && fast.next.next != null) { slow = slow.next; fast = fast.next.next; @@ -80,12 +80,12 @@ public static LinkedNode midOrDownMidLinkedNode(LinkedNode head) { /** * 输入链表头节点,奇数长度返回中点前一个,偶数长度返回上中点前一个 */ - public static LinkedNode midOrUpMidPreLinkedNode(LinkedNode head) { + public static ListNode midOrUpMidPreLinkedNode(ListNode head) { if (head == null || head.next == null || head.next.next == null) { return null; } - LinkedNode slow = head; - LinkedNode fast = head.next.next; + ListNode slow = head; + ListNode fast = head.next.next; while (fast.next != null && fast.next.next != null) { slow = slow.next; fast = fast.next.next; @@ -96,15 +96,15 @@ public static LinkedNode midOrUpMidPreLinkedNode(LinkedNode head) { /** * 输入链表头节点,奇数长度返回中点前一个,偶数长度返回下中点前一个 */ - public static LinkedNode midOrDownMidPreLinkedNode(LinkedNode head) { + public static ListNode midOrDownMidPreLinkedNode(ListNode head) { if (head == null || head.next == null) { return null; } if (head.next.next == null) { return head; } - LinkedNode slow = head; - LinkedNode fast = head.next; + ListNode slow = head; + ListNode fast = head.next; while (fast.next != null && fast.next.next != null) { slow = slow.next; fast = fast.next.next; @@ -113,12 +113,12 @@ public static LinkedNode midOrDownMidPreLinkedNode(LinkedNode head) { } //-------------------------- 对数器 --------------------------// - public static LinkedNode right1(LinkedNode head) { + public static ListNode right1(ListNode head) { if (head == null) { return null; } - LinkedNode cur = head; - ArrayList arr = new ArrayList<>(); + ListNode cur = head; + ArrayList arr = new ArrayList<>(); while (cur != null) { arr.add(cur); cur = cur.next; @@ -126,12 +126,12 @@ public static LinkedNode right1(LinkedNode head) { return arr.get((arr.size() - 1) / 2); } - public static LinkedNode right2(LinkedNode head) { + public static ListNode right2(ListNode head) { if (head == null) { return null; } - LinkedNode cur = head; - ArrayList arr = new ArrayList<>(); + ListNode cur = head; + ArrayList arr = new ArrayList<>(); while (cur != null) { arr.add(cur); cur = cur.next; @@ -139,12 +139,12 @@ public static LinkedNode right2(LinkedNode head) { return arr.get(arr.size() / 2); } - public static LinkedNode right3(LinkedNode head) { + public static ListNode right3(ListNode head) { if (head == null || head.next == null || head.next.next == null) { return null; } - LinkedNode cur = head; - ArrayList arr = new ArrayList<>(); + ListNode cur = head; + ArrayList arr = new ArrayList<>(); while (cur != null) { arr.add(cur); cur = cur.next; @@ -152,12 +152,12 @@ public static LinkedNode right3(LinkedNode head) { return arr.get((arr.size() - 3) / 2); } - public static LinkedNode right4(LinkedNode head) { + public static ListNode right4(ListNode head) { if (head == null || head.next == null) { return null; } - LinkedNode cur = head; - ArrayList arr = new ArrayList<>(); + ListNode cur = head; + ArrayList arr = new ArrayList<>(); while (cur != null) { arr.add(cur); cur = cur.next; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" index 427d3e70..787bbe76 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" @@ -1,6 +1,6 @@ package algorithmzuo.b_体系学习班.c0104_链表; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import org.junit.Test; import java.util.Stack; @@ -12,7 +12,7 @@ public class Code04_IsPalindromeList { */ @Test public void test() { - LinkedNode head = null; + ListNode head = null; printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -20,7 +20,7 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); + head = new ListNode(1); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -28,8 +28,8 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(2); + head = new ListNode(1); + head.next = new ListNode(2); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -37,8 +37,8 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(1); + head = new ListNode(1); + head.next = new ListNode(1); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -46,9 +46,9 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); + head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -56,9 +56,9 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(1); + head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(1); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -66,10 +66,10 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(1); + head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(1); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -77,10 +77,10 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(2); - head.next.next.next = new LinkedNode(1); + head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(2); + head.next.next.next = new ListNode(1); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -88,11 +88,11 @@ public void test() { printLinkedList(head); System.out.println("========================="); - head = new LinkedNode(1); - head.next = new LinkedNode(2); - head.next.next = new LinkedNode(3); - head.next.next.next = new LinkedNode(2); - head.next.next.next.next = new LinkedNode(1); + head = new ListNode(1); + head.next = new ListNode(2); + head.next.next = new ListNode(3); + head.next.next.next = new ListNode(2); + head.next.next.next.next = new ListNode(1); printLinkedList(head); System.out.print(isPalindrome1(head) + " | "); System.out.print(isPalindrome2(head) + " | "); @@ -103,9 +103,9 @@ public void test() { } // need n extra space - public static boolean isPalindrome1(LinkedNode head) { - Stack stack = new Stack(); - LinkedNode cur = head; + public static boolean isPalindrome1(ListNode head) { + Stack stack = new Stack(); + ListNode cur = head; while (cur != null) { stack.push(cur); cur = cur.next; @@ -120,17 +120,17 @@ public static boolean isPalindrome1(LinkedNode head) { } // need n/2 extra space - public static boolean isPalindrome2(LinkedNode head) { + public static boolean isPalindrome2(ListNode head) { if (head == null || head.next == null) { return true; } - LinkedNode right = head.next; - LinkedNode cur = head; + ListNode right = head.next; + ListNode cur = head; while (cur.next != null && cur.next.next != null) { right = right.next; cur = cur.next.next; } - Stack stack = new Stack(); + Stack stack = new Stack(); while (right != null) { stack.push(right); right = right.next; @@ -145,12 +145,12 @@ public static boolean isPalindrome2(LinkedNode head) { } // need O(1) extra space - public static boolean isPalindrome3(LinkedNode head) { + public static boolean isPalindrome3(ListNode head) { if (head == null || head.next == null) { return true; } - LinkedNode n1 = head; - LinkedNode n2 = head; + ListNode n1 = head; + ListNode n2 = head; while (n2.next != null && n2.next.next != null) { // find mid LinkedNode n1 = n1.next; // n1 -> mid n2 = n2.next.next; // n2 -> end @@ -160,7 +160,7 @@ public static boolean isPalindrome3(LinkedNode head) { n2 = n1.next; // n2 -> right part first LinkedNode n1.next = null; // mid.next -> null - LinkedNode n3 = null; + ListNode n3 = null; while (n2 != null) { // right part convert n3 = n2.next; // n3 -> save next LinkedNode n2.next = n1; // next of right LinkedNode convert @@ -189,11 +189,11 @@ public static boolean isPalindrome3(LinkedNode head) { return res; } - public static void printLinkedList(LinkedNode LinkedNode) { + public static void printLinkedList(ListNode ListNode) { System.out.print("Linked List: "); - while (LinkedNode != null) { - System.out.print(LinkedNode.val + " "); - LinkedNode = LinkedNode.next; + while (ListNode != null) { + System.out.print(ListNode.val + " "); + ListNode = ListNode.next; } System.out.println(); } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" index 9fb015b7..50d8c139 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" @@ -1,6 +1,6 @@ package algorithmzuo.b_体系学习班.c0104_链表; -import common.datastruct.LinkedNode; +import common.datastruct.ListNode; import org.junit.Test; public class Code05_SmallerEqualBigger { @@ -10,13 +10,13 @@ public class Code05_SmallerEqualBigger { */ @Test public void test() { - LinkedNode head1 = new LinkedNode(7); - head1.next = new LinkedNode(9); - head1.next.next = new LinkedNode(1); - head1.next.next.next = new LinkedNode(8); - head1.next.next.next.next = new LinkedNode(5); - head1.next.next.next.next.next = new LinkedNode(2); - head1.next.next.next.next.next.next = new LinkedNode(5); + ListNode head1 = new ListNode(7); + head1.next = new ListNode(9); + head1.next.next = new ListNode(1); + head1.next.next.next = new ListNode(8); + head1.next.next.next.next = new ListNode(5); + head1.next.next.next.next.next = new ListNode(2); + head1.next.next.next.next.next.next = new ListNode(5); printLinkedList(head1); // head1 = listPartition1(head1, 4); head1 = listPartition2(head1, 5); @@ -24,60 +24,60 @@ public void test() { } - public static LinkedNode listPartition1(LinkedNode head, int pivot) { + public static ListNode listPartition1(ListNode head, int pivot) { if (head == null) { return head; } - LinkedNode cur = head; + ListNode cur = head; int i = 0; while (cur != null) { i++; cur = cur.next; } - LinkedNode[] LinkedNodeArr = new LinkedNode[i]; + ListNode[] listNodeArr = new ListNode[i]; i = 0; cur = head; - for (i = 0; i != LinkedNodeArr.length; i++) { - LinkedNodeArr[i] = cur; + for (i = 0; i != listNodeArr.length; i++) { + listNodeArr[i] = cur; cur = cur.next; } - arrPartition(LinkedNodeArr, pivot); - for (i = 1; i != LinkedNodeArr.length; i++) { - LinkedNodeArr[i - 1].next = LinkedNodeArr[i]; + arrPartition(listNodeArr, pivot); + for (i = 1; i != listNodeArr.length; i++) { + listNodeArr[i - 1].next = listNodeArr[i]; } - LinkedNodeArr[i - 1].next = null; - return LinkedNodeArr[0]; + listNodeArr[i - 1].next = null; + return listNodeArr[0]; } - public static void arrPartition(LinkedNode[] LinkedNodeArr, int pivot) { + public static void arrPartition(ListNode[] listNodeArr, int pivot) { int small = -1; - int big = LinkedNodeArr.length; + int big = listNodeArr.length; int index = 0; while (index != big) { - if (LinkedNodeArr[index].val < pivot) { - swap(LinkedNodeArr, ++small, index++); - } else if (LinkedNodeArr[index].val == pivot) { + if (listNodeArr[index].val < pivot) { + swap(listNodeArr, ++small, index++); + } else if (listNodeArr[index].val == pivot) { index++; } else { - swap(LinkedNodeArr, --big, index); + swap(listNodeArr, --big, index); } } } - public static void swap(LinkedNode[] LinkedNodeArr, int a, int b) { - LinkedNode tmp = LinkedNodeArr[a]; - LinkedNodeArr[a] = LinkedNodeArr[b]; - LinkedNodeArr[b] = tmp; + public static void swap(ListNode[] listNodeArr, int a, int b) { + ListNode tmp = listNodeArr[a]; + listNodeArr[a] = listNodeArr[b]; + listNodeArr[b] = tmp; } - public static LinkedNode listPartition2(LinkedNode head, int pivot) { - LinkedNode sH = null; // small head - LinkedNode sT = null; // small tail - LinkedNode eH = null; // equal head - LinkedNode eT = null; // equal tail - LinkedNode mH = null; // big head - LinkedNode mT = null; // big tail - LinkedNode next = null; // save next LinkedNode + public static ListNode listPartition2(ListNode head, int pivot) { + ListNode sH = null; // small head + ListNode sT = null; // small tail + ListNode eH = null; // equal head + ListNode eT = null; // equal tail + ListNode mH = null; // big head + ListNode mT = null; // big tail + ListNode next = null; // save next LinkedNode // every LinkedNode distributed to three lists while (head != null) { next = head.next; @@ -124,11 +124,11 @@ public static LinkedNode listPartition2(LinkedNode head, int pivot) { return sH != null ? sH : (eH != null ? eH : mH); } - public static void printLinkedList(LinkedNode LinkedNode) { + public static void printLinkedList(ListNode ListNode) { System.out.print("Linked List: "); - while (LinkedNode != null) { - System.out.print(LinkedNode.val + " "); - LinkedNode = LinkedNode.next; + while (ListNode != null) { + System.out.print(ListNode.val + " "); + ListNode = ListNode.next; } System.out.println(); } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" new file mode 100644 index 00000000..9d4c7fa5 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" @@ -0,0 +1,42 @@ +package algorithmzuo.b_体系学习班.c0104_链表; + +import common.CommonConstants; +import common.datastruct.ListNode; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +/** + * Created by nibnait on 2022/10/25 + */ +@Slf4j +public class Code07_FindFirstIntersectListNode { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + + + + + } + + /** + * 给定两个可能有环也可能无环的单链表,头节点head1和head2 + * 请实现一个函数,如果两个链表相交,请返回相交的第一个节点。如果不相交返回null + * 要求如果两个链表长度之和为N,时间复杂度请达到O(N),额外空间复杂度请达到O(1) + */ + private ListNode getIntersectListNode(ListNode head1, ListNode head2) { + if (head1 == null || head2 == null) { + return null; + } + + return null; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" index 3ff94bec..a54fb124 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" @@ -11,4 +11,24 @@ Master 公式: ### 堆 和 加强堆 [堆相关](../../../data_struct/堆) -### \ No newline at end of file +### 排序算法总结 + +| | 时间复杂度 | 额外空间复杂度 | 稳定性 | +| -------- | ---------- | -------------- | ------ | +| 选择排序 | O(N^2) | O(1) | 无 | +| 冒泡排序 | O(N^2) | O(1) | 有 | +| 插入排序 | O(N^2) | O(1) | 有 | +| 归并排序 | O(NxlogN) | O(N) | 有 | +| 随机快排 | O(NxlogN) | O(logN) | 无 | +| 堆排序 | O(NxlogN) | O(1) | 无 | +| === | === | === | === | +| 计数排序 | O(N) | O(1) | 有 | +| 基数排序 | O(N) | O(1) | 有 | + +1)不基于比较的排序,对样本数据有严格要求,不易改写 +2)基于比较的排序,只要规定好两个样本怎么比大小就可以直接复用 +3)基于比较的排序,时间复杂度的极限是O(N*logN) +4)时间复杂度O(N*logN)、额外空间复杂度低于O(N)、且稳定的基于比较的 +排序是不存在的。 +5)为了绝对的速度选快排、为了省空间选堆排、为了稳定性选归并 + From f7c860b2f51e556120d69e0ecda2d34cdf80eff5 Mon Sep 17 00:00:00 2001 From: tianbin Date: Tue, 25 Oct 2022 09:17:53 +0800 Subject: [PATCH 19/36] =?UTF-8?q?=E9=93=BE=E8=A1=A8=E7=9B=B8=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../c01xx_summary.md" | 3 +-- .../c0201_/package-info.java" | 1 - .../Code01_1_ReverseListNode.java" | 2 +- .../Code01_2_ReverseDoubleListNode.java" | 2 +- .../Code02_DeleteGivenValue.java" | 2 +- .../Code03_LinkedListMid.java" | 2 +- .../Code04_IsPalindromeList.java" | 2 +- .../Code05_SmallerEqualBigger.java" | 2 +- .../Code06_CopyListWithRandom.java" | 2 +- .../Code07_FindFirstIntersectListNode.java" | 2 +- .../Code01_TrieTree.java" | 2 +- .../c02xx_summary.md" | 13 +++---------- 12 files changed, 13 insertions(+), 22 deletions(-) delete mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" (98%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code04_IsPalindromeList.java" (99%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" (98%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0202_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" (99%) diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" index a54fb124..27321f08 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" @@ -1,5 +1,4 @@ -## 体系学习班 -class01 - class10 +## 排序、二分查找、异或运算、栈和队列 ### 用master公式来估计时间复杂度 Master 公式: diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" deleted file mode 100644 index 307102a1..00000000 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_/package-info.java" +++ /dev/null @@ -1 +0,0 @@ -package algorithmzuo.b_体系学习班.c0201_; \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" similarity index 97% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" index 5adb1822..4db039cc 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.CommonConstants; import common.datastruct.ListNode; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" similarity index 97% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" index cb95f959..90a1a807 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.CommonConstants; import common.datastruct.ListNode; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" similarity index 96% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" index 5daf38fe..0f958a86 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.CommonConstants; import common.datastruct.ListNode; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" similarity index 98% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" index 524852a2..88403148 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code03_LinkedListMid.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.datastruct.ListNode; import org.junit.Test; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code04_IsPalindromeList.java" similarity index 99% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code04_IsPalindromeList.java" index 787bbe76..a688b9b5 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code04_IsPalindromeList.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code04_IsPalindromeList.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.datastruct.ListNode; import org.junit.Test; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" similarity index 98% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" index 50d8c139..331dd623 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.datastruct.ListNode; import org.junit.Test; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" similarity index 97% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" index 83c238a2..14c33db4 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import java.util.HashMap; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" similarity index 94% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" index 9d4c7fa5..b73fccd7 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0104_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0104_链表; +package algorithmzuo.b_体系学习班.c0201_链表; import common.CommonConstants; import common.datastruct.ListNode; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0202_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" similarity index 99% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0202_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" index d3536dc4..b1e96339 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0106_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0202_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0106_前缀树; +package algorithmzuo.b_体系学习班.c0202_前缀树; import java.util.HashMap; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" index 934e1e71..da290a0d 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" @@ -1,12 +1,5 @@ -## 体系学习班 -class01 - class10 +### 链表 三板斧 +双指针 -### 用master公式来估计时间复杂度 -Master 公式: -形如 T(N) = a * T(N/b) + O(N^d) (a、b、d都是常数)的递归函数,可以直接通过 Master 公式来确定时间复杂度 -- 如果 log(b,a) < d, 复杂度为 O(N^d) -- 如果 log(b,a) > d, 复杂度为 O(N^log(b,a)) -- 如果 log(b,a) == d, 复杂度为 O(N^d * logN) -### 堆 和 加强堆 -[堆相关](../../../data_struct/堆) \ No newline at end of file +### 二叉树 \ No newline at end of file From 9d95244aa60ab2bb81b74def883d3539dcb8c30f Mon Sep 17 00:00:00 2001 From: tianbin Date: Sun, 30 Oct 2022 23:47:37 +0800 Subject: [PATCH 20/36] =?UTF-8?q?feat=20=E4=BA=8C=E5=8F=89=E6=A0=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 6 + ...\345\205\245\344\275\215\347\275\256.java" | 2 +- ...\345\271\263\346\226\271\346\240\271.java" | 6 +- ...\345\244\215\345\205\203\347\264\240.java" | 4 +- .../H051_N\347\232\207\345\220\216.java" | 10 +- ...\345\205\245\345\214\272\351\227\264.java" | 8 +- ...\350\276\221\350\267\235\347\246\273.java" | 8 +- ...\347\232\204\345\256\271\345\231\250.java" | 4 +- ...\346\225\260\344\271\213\345\222\214.java" | 2 +- ...\346\225\260\344\271\213\345\222\214.java" | 2 +- ...\344\270\252\350\212\202\347\202\271.java" | 4 +- ...\345\272\217\346\225\260\347\273\204.java" | 8 +- ...\344\270\252\344\275\215\347\275\256.java" | 6 +- ...\345\220\210\346\200\273\345\222\214.java" | 20 +- ...345\220\210\346\200\273\345\222\2142.java" | 18 +- ...\345\271\266\345\214\272\351\227\264.java" | 2 +- ...\344\270\252\346\216\222\345\210\227.java" | 14 +- ...\350\275\254\351\223\276\350\241\250.java" | 10 +- ...\345\220\214\350\267\257\345\276\204.java" | 8 +- ...345\220\214\350\267\257\345\276\2042.java" | 10 +- ...\347\273\264\347\237\251\351\230\265.java" | 6 +- ...350\275\254\351\223\276\350\241\2502.java" | 2 +- ...\345\272\217\351\201\215\345\216\206.java" | 2 +- ...\347\232\204\346\225\260\351\207\217.java" | 2 +- ...\346\220\234\347\264\242\346\240\221.java" | 10 +- ...\344\272\214\345\217\211\346\240\221.java" | 4 +- ...\345\244\247\346\267\261\345\272\246.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 4 +- ...\345\260\217\346\267\261\345\272\246.java" | 2 +- ...\344\275\263\346\227\266\346\234\272.java" | 4 +- ...344\275\263\346\227\266\346\234\2722.java" | 12 +- ...\345\256\266\345\212\253\350\210\215.java" | 8 +- ...344\275\263\346\227\266\346\234\2723.java" | 14 +- ...\350\267\257\345\276\204\345\222\214.java" | 14 +- ...\347\273\255\345\272\217\345\210\227.java" | 4 +- ...350\257\215\346\213\206\345\210\2062.java" | 12 +- ...\345\244\247\351\227\264\350\267\235.java" | 4 +- ...344\275\263\346\227\266\346\234\2724.java" | 6 +- ...\346\254\241\351\201\215\345\216\206.java" | 2 +- ...\350\257\215\346\216\245\351\276\231.java" | 8 +- ...\345\212\240\346\262\271\347\253\231.java" | 8 +- ...\350\257\215\346\213\206\345\210\206.java" | 4 +- ...\345\272\217\351\201\215\345\216\206.java" | 2 +- ...\345\272\217\351\201\215\345\216\206.java" | 2 +- ...\345\255\230\346\234\272\345\210\266.java" | 4 +- ...\345\205\245\346\216\222\345\272\217.java" | 6 +- ...\345\272\217\351\223\276\350\241\250.java" | 6 +- ...\346\234\200\345\260\217\345\200\274.java" | 2 +- ...\345\215\225\345\205\203\346\240\274.java" | 6 +- ...\345\205\254\345\233\240\345\255\220.java" | 8 +- ...\345\257\271\346\216\222\345\272\217.java" | 16 +- ...\345\206\231\345\215\225\350\257\215.java" | 12 +- ...\347\232\204\347\273\223\347\202\271.java" | 6 +- ...\345\274\202\344\275\215\350\257\215.java" | 2 +- ...\345\272\217\345\210\227\345\214\226.java" | 6 +- ...\350\257\276\347\250\213\350\241\250.java" | 14 +- ...350\257\276\347\250\213\350\241\2502.java" | 16 +- ...345\256\266\345\212\253\350\210\2152.java" | 8 +- ...\345\244\247\345\205\203\347\264\240.java" | 2 +- ...345\220\210\346\200\273\345\222\2143.java" | 4 +- ...\347\202\271\344\270\252\346\225\260.java" | 2 +- ...\345\242\236\350\267\257\345\276\204.java" | 4 +- ...\345\255\220\345\272\217\345\210\227.java" | 6 +- ...\345\206\267\345\206\273\346\234\237.java" | 2 +- ...\351\222\261\345\205\221\346\215\242.java" | 8 +- ...345\256\266\345\212\253\350\210\2153.java" | 6 +- ...\345\243\266\351\227\256\351\242\230.java" | 4 +- ...345\244\247\345\205\203\347\264\2401.java" | 12 +- .../H460_LFU\347\274\223\345\255\230.java" | 8 +- ...\344\275\215\346\225\260\345\255\227.java" | 4 +- ...\345\273\272\351\230\237\345\210\227.java" | 2 +- ...\345\222\214\345\255\220\351\233\206.java" | 4 +- ...\347\210\206\346\260\224\347\220\203.java" | 8 +- ...\344\270\200\345\222\214\351\233\266.java" | 6 +- ...\347\233\256\346\240\207\345\222\214.java" | 2 +- ...\347\224\261\344\271\213\350\267\257.java" | 18 +- ...\345\255\220\345\272\217\345\210\227.java" | 4 +- ...351\222\261\345\205\221\346\215\2422.java" | 4 +- ...\346\234\213\345\217\213\345\234\210.java" | 4 +- ...\345\244\247\351\235\242\347\247\257.java" | 8 +- ...\345\210\206\346\237\245\346\211\276.java" | 12 +- ...\346\211\213\347\273\255\350\264\271.java" | 6 +- ...\351\227\264\347\273\223\347\202\271.java" | 10 +- ...\350\233\213\346\216\211\350\220\275.java" | 10 +- ...\345\272\217\346\225\260\347\273\204.java" | 6 +- ...345\272\217\346\225\260\347\273\2042.java" | 8 +- ...345\220\214\350\267\257\345\276\2043.java" | 4 +- ...\345\272\217\346\225\260\347\273\204.java" | 6 +- ...\345\260\217\345\242\236\351\207\217.java" | 4 +- ...347\232\204K\344\270\252\347\202\271.java" | 4 +- src/main/java/common/datastruct/TreeNode.java | 4 + src/main/java/common/util/CompareUtils.java | 51 ++++- .../java/common/util/ConstructBinaryTree.java | 51 ++++- .../java/common/util/PrintBinaryTree.java | 31 ++- ...00\347\232\204\347\256\227\346\263\225.md" | 0 .../Code07_FindFirstIntersectListNode.java" | 38 ++++ .../Code01_RecursiveTraversalBT.java" | 111 ++++++++++ .../Code02_UnRecursiveTraversalBT.java" | 117 +++++++++++ .../Code03_LevelTraversalBT.java" | 67 ++++++ .../Code04_SerializeAndReconstructTree.java" | 24 +++ ...de04_SerializeAndReconstructTreeImpl.java" | 192 ++++++++++++++++++ .../Code05_EncodeNaryTreeToBinaryTree.java" | 19 ++ .../Code06_TreeMaxWidth.java" | 85 ++++++++ .../Code01_IsBalanced.java" | 85 ++++++++ .../Code02_IsBST.java" | 110 ++++++++++ .../Code03_MaxDistance.java" | 131 ++++++++++++ .../Code04_IsFull.java" | 95 +++++++++ .../Code05_MaxSubBSTSize.java" | 87 ++++++++ .../Code06_IsCBT.java" | 90 ++++++++ .../Code07_MaxSubBSTHead.java" | 91 +++++++++ .../Code08_lowestAncestor.java" | 93 +++++++++ .../Code09_MaxHappy.java" | 110 ++++++++++ .../c02xx_summary.md" | 5 - ...76\350\241\250\345\222\214\346\240\221.md" | 36 ++++ 114 files changed, 1996 insertions(+), 323 deletions(-) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" => "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" (100%) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code05_EncodeNaryTreeToBinaryTree.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" delete mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" diff --git a/pom.xml b/pom.xml index 303a5a6d..41df4132 100644 --- a/pom.xml +++ b/pom.xml @@ -22,6 +22,12 @@ 1.0-SNAPSHOT + + org.skyscreamer + jsonassert + 1.5.1 + + cglib diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" "b/src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" index 8a60fa75..a7622598 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" @@ -12,7 +12,7 @@ 输入: [1,3,5,6], 5 输出: 2 -示例 2: +示例 2: 输入: [1,3,5,6], 2 输出: 1 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" "b/src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" index f0404d3f..194a6eca 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" @@ -4,9 +4,9 @@ import org.junit.Test; /* -实现 int sqrt(int x) 函数。 +实现 int sqrt(int x) 函数。 -计算并返回 x 的平方根,其中 x 是非负整数。 +计算并返回 x 的平方根,其中 x 是非负整数。 由于返回类型是整数,结果只保留整数的部分,小数部分将被舍去。 @@ -18,7 +18,7 @@ 输入: 8 输出: 2 说明: 8 的平方根是 2.82842..., -  由于返回类型是整数,小数部分将被舍去。 + 由于返回类型是整数,小数部分将被舍去。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/sqrtx diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" "b/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" index ed2571cd..ec9f8063 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" @@ -9,11 +9,11 @@ /* 给定一个排序链表,删除所有重复的元素,使得每个元素只出现一次。 -示例 1: +示例 1: 输入: 1->1->2 输出: 1->2 -示例 2: +示例 2: 输入: 1->1->2->3->3 输出: 1->2->3 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" index 92e99775..1c17fd4e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" @@ -9,7 +9,7 @@ import java.util.List; /* -n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。 +n 皇后问题研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。 [".Q..", "...Q", @@ -18,11 +18,11 @@ 上图为 8 皇后问题的一种解法。 -给定一个整数 n,返回所有不同的 n 皇后问题的解决方案。 +给定一个整数 n,返回所有不同的 n 皇后问题的解决方案。 -每一种解法包含一个明确的 n 皇后问题的棋子放置方案,该方案中 'Q' 和 '.' 分别代表了皇后和空位。 +每一种解法包含一个明确的 n 皇后问题的棋子放置方案,该方案中 'Q' 和 '.' 分别代表了皇后和空位。 -  + 示例: @@ -39,7 +39,7 @@ ".Q.."] ] 解释: 4 皇后问题存在两个不同的解法。 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" index 79e962dc..fd220e8d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" @@ -11,17 +11,17 @@ 在列表中插入一个新的区间,你需要确保列表中的区间仍然有序且不重叠(如果有必要的话,可以合并区间)。 -  + -示例 1: +示例 1: 输入:intervals = [[1,3],[6,9]], newInterval = [2,5] 输出:[[1,5],[6,9]] -示例 2: +示例 2: 输入:intervals = [[1,2],[3,5],[6,7],[8,10],[12,16]], newInterval = [4,8] 输出:[[1,2],[3,10],[12,16]] -解释:这是因为新的区间 [4,8] 与 [3,5],[6,7],[8,10] 重叠。 +解释:这是因为新的区间 [4,8] 与 [3,5],[6,7],[8,10] 重叠。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" index 1e0e6ff4..e09421ac 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" @@ -4,16 +4,16 @@ import org.junit.Test; /* -给你两个单词 word1 和 word2,请你计算出将 word1 转换成 word2 所使用的最少操作数 。 +给你两个单词 word1 和 word2,请你计算出将 word1 转换成 word2 所使用的最少操作数 。 你可以对一个单词进行如下三种操作: 插入一个字符 删除一个字符 替换一个字符 -  + -示例 1: +示例 1: 输入:word1 = "horse", word2 = "ros" 输出:3 @@ -21,7 +21,7 @@ horse -> rorse (将 'h' 替换为 'r') rorse -> rose (删除 'r') rose -> ros (删除 'e') -示例 2: +示例 2: 输入:word1 = "intention", word2 = "execution" 输出:5 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" index 6d4f819f..311cead3 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" @@ -4,8 +4,8 @@ import org.junit.Test; /* -给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 -说明:你不能倾斜容器,且 n 的值至少为 2。 +给定 n 个非负整数 a1,a2,...,an,每个数代表坐标中的一个点 (i, ai) 。在坐标内画 n 条垂直线,垂直线 i 的两个端点分别为 (i, ai) 和 (i, 0)。找出其中的两条线,使得它们与 x 轴共同构成的容器可以容纳最多的水。 +说明:你不能倾斜容器,且 n 的值至少为 2。 示例: 输入: [1,8,6,2,5,4,8,3,7] diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" index c2484e09..16797958 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" @@ -10,7 +10,7 @@ import java.util.List; /* -给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组。 +给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组。 注意:答案中不可以包含重复的三元组。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" index 2ee6c094..97aa6e0e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" @@ -6,7 +6,7 @@ import java.util.Arrays; /* -给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 +给定一个包括 n 个整数的数组 nums 和 一个目标值 target。找出 nums 中的三个整数,使得它们的和与 target 最接近。返回这三个数的和。假定每组输入只存在唯一答案。 例如,给定数组 nums = [-1,2,1,-4], 和 target = 1. 与 target 最接近的三个数的和为 2. (-1 + 2 + 1 = 2). diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" index 3d5ec103..5e1190c2 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" @@ -7,7 +7,7 @@ import org.junit.Test; /* -给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。 +给定一个链表,删除链表的倒数第 n 个节点,并且返回链表的头结点。 示例: 给定一个链表: 1->2->3->4->5, 和 n = 2. @@ -15,7 +15,7 @@ 当删除了倒数第二个节点后,链表变为 1->2->3->5. 说明: -给定的 n 保证是有效的。 +给定的 n 保证是有效的。 进阶: 你能尝试使用一趟扫描实现吗? diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" index d6fd08c0..ac978125 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" @@ -7,19 +7,19 @@ /* 假设按照升序排序的数组在预先未知的某个点上进行了旋转。 -( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 +( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 -搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回 -1 。 +搜索一个给定的目标值,如果数组中存在这个目标值,则返回它的索引,否则返回 -1 。 你可以假设数组中不存在重复的元素。 -你的算法时间复杂度必须是 O(log n) 级别。 +你的算法时间复杂度必须是 O(log n) 级别。 示例 1: 输入: nums = [4,5,6,7,0,1,2], target = 0 输出: 4 -示例 2: +示例 2: 输入: nums = [4,5,6,7,0,1,2], target = 3 输出: -1 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" index 503cc43e..935c7ed7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" @@ -6,14 +6,14 @@ /* 给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。 -你的算法时间复杂度必须是 O(log n) 级别。 -如果数组中不存在目标值,返回 [-1, -1]。 +你的算法时间复杂度必须是 O(log n) 级别。 +如果数组中不存在目标值,返回 [-1, -1]。 示例 1: 输入: nums = [5,7,7,8,8,10], target = 8 输出: [3,4] -示例 2: +示例 2: 输入: nums = [5,7,7,8,8,10], target = 6 输出: [-1,-1] diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" index 1e90ce3d..b602648a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" @@ -7,15 +7,15 @@ import java.util.*; /* -给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 +给定一个无重复元素的数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 -candidates 中的数字可以无限制重复被选取。 +candidates 中的数字可以无限制重复被选取。 说明: -所有数字(包括 target)都是正整数。 -解集不能包含重复的组合。  -示例 1: +所有数字(包括 target)都是正整数。 +解集不能包含重复的组合。 +示例 1: 输入:candidates = [2,3,6,7], target = 7, 所求解集为: @@ -23,16 +23,16 @@ [7], [2,2,3] ] -示例 2: +示例 2: 输入:candidates = [2,3,5], target = 8, 所求解集为: [ -  [2,2,2,2], -  [2,3,3], -  [3,5] + [2,2,2,2], + [2,3,3], + [3,5] ] -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" index dc18d8c6..33d99ef1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" @@ -8,17 +8,17 @@ import java.util.stream.Collectors; /* -给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 +给定一个数组 candidates 和一个目标数 target ,找出 candidates 中所有可以使数字和为 target 的组合。 -candidates 中的每个数字在每个组合中只能使用一次。 +candidates 中的每个数字在每个组合中只能使用一次。 说明: 所有数字(包括目标数)都是正整数。 -解集不能包含重复的组合。  -示例 1: +解集不能包含重复的组合。 +示例 1: -输入: candidates = [10,1,2,7,6,1,5], target = 8, +输入: candidates = [10,1,2,7,6,1,5], target = 8, 所求解集为: [ [1, 7], @@ -26,13 +26,13 @@ [2, 6], [1, 1, 6] ] -示例 2: +示例 2: -输入: candidates = [2,5,2,1,2], target = 5, +输入: candidates = [2,5,2,1,2], target = 5, 所求解集为: [ -  [1,2,2], -  [5] + [1,2,2], + [5] ] diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" index d9c455a4..30bc5150 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" @@ -14,7 +14,7 @@ 输出: [[1,6],[8,10],[15,18]] 解释: 区间 [1,3] 和 [2,6] 重叠, 将它们合并为 [1,6]. -示例 2: +示例 2: 输入: [[1,4],[4,5]] 输出: [[1,5]] 解释: 区间 [1,4] 和 [4,5] 可被视为重叠区间。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" index 743b55f2..48d7d414 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" @@ -5,9 +5,9 @@ import org.junit.Test; /* -给出集合 [1,2,3,…,n],其所有元素共有 n! 种排列。 +给出集合 [1,2,3,…,n],其所有元素共有 n! 种排列。 -按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下: +按大小顺序列出所有排列情况,并一一标记,当 n = 3 时, 所有排列如下: "123" "132" @@ -15,17 +15,17 @@ "231" "312" "321" -给定 n 和 k,返回第 k 个排列。 +给定 n 和 k,返回第 k 个排列。 说明: -给定 n 的范围是 [1, 9]。 -给定 k 的范围是[1,  n!]。 -示例 1: +给定 n 的范围是 [1, 9]。 +给定 k 的范围是[1, n!]。 +示例 1: 输入: n = 3, k = 3 输出: "213" -示例 2: +示例 2: 输入: n = 4, k = 9 输出: "2314" diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" index 1f6b85f0..e0205500 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" @@ -7,23 +7,23 @@ import org.junit.Test; /* -给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数。 +给定一个链表,旋转链表,将链表每个节点向右移动 k 个位置,其中 k 是非负数。 -示例 1: +示例 1: 输入: 1->2->3->4->5->NULL, k = 2 输出: 4->5->1->2->3->NULL 解释: 向右旋转 1 步: 5->1->2->3->4->NULL 向右旋转 2 步: 4->5->1->2->3->NULL -示例 2: +示例 2: 输入: 0->1->2->NULL, k = 4 输出: 2->0->1->NULL 解释: 向右旋转 1 步: 2->0->1->NULL 向右旋转 2 步: 1->2->0->NULL -向右旋转 3 步: 0->1->2->NULL -向右旋转 4 步: 2->0->1->NULL +向右旋转 3 步: 0->1->2->NULL +向右旋转 4 步: 2->0->1->NULL 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/rotate-list diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" index 109adc31..80ab4f30 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" @@ -14,9 +14,9 @@ 例如,上图是一个7 x 3 的网格。有多少可能的路径? -  + -示例 1: +示例 1: 输入: m = 3, n = 2 输出: 3 @@ -25,11 +25,11 @@ 1. 向右 -> 向右 -> 向下 2. 向右 -> 向下 -> 向右 3. 向下 -> 向右 -> 向右 -示例 2: +示例 2: 输入: m = 7, n = 3 输出: 28 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" index 4a693364..2e71e1de 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" @@ -14,15 +14,15 @@ 网格中的障碍物和空位置分别用 1 和 0 来表示。 -说明:m 和 n 的值均不超过 100。 +说明:m 和 n 的值均不超过 100。 -示例 1: +示例 1: 输入: [ -  [0,0,0], -  [0,1,0], -  [0,0,0] + [0,0,0], + [0,1,0], + [0,0,0] ] 输出: 2 解释: diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" index 6b154797..6bc9cdb2 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" @@ -4,11 +4,11 @@ import org.junit.Test; /* -编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性: +编写一个高效的算法来判断 m x n 矩阵中,是否存在一个目标值。该矩阵具有如下特性: 每行中的整数从左到右按升序排列。 每行的第一个整数大于前一行的最后一个整数。 -示例 1: +示例 1: 输入: matrix = [ [1, 3, 5, 7], @@ -18,7 +18,7 @@ target = 3 输出: true -示例 2: +示例 2: 输入: matrix = [ [1, 3, 5, 7], diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index 8c6c5db0..afecd71c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -11,7 +11,7 @@ 反转从位置 m 到 n 的链表。请使用一趟扫描完成反转。 说明: - 1 ≤ m ≤ n ≤ 链表长度。 + 1 ≤ m ≤ n ≤ 链表长度。 示例: diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" index daa50517..93077f2c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" @@ -23,7 +23,7 @@ 输出: [1,3,2] -进阶: 递归算法很简单,你可以通过迭代算法完成吗? +进阶: 递归算法很简单,你可以通过迭代算法完成吗? 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/binary-tree-inorder-traversal diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" index 9f9d96d0..013f6d0e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" @@ -4,7 +4,7 @@ import org.junit.Test; /* -给定一个整数 n,求以 1 ... n 为结点组成的二叉搜索树有多少种? +给定一个整数 n,求以 1 ... n 为结点组成的二叉搜索树有多少种? 示例: diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" index 09b833be..c0ddee46 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" @@ -15,24 +15,24 @@ 结点的左子树只包含小于当前结点的数。 结点的右子树只包含大于当前结点的数。 所有左子树和右子树自身必须也是二叉搜索树。 -示例 1: +示例 1: 输入: 2 / \ 1 3 输出: true -示例 2: +示例 2: 输入: 5 / \ 1 4 -  / \ -  3 6 + / \ + 3 6 输出: false 解释: 输入为: [5,1,4,null,null,3,6]。 -  根结点的值为 5 ,但是其右子结点值为 4 。 + 根结点的值为 5 ,但是其右子结点值为 4 。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/validate-binary-search-tree diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" index 46b0c468..260cd89d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" @@ -8,7 +8,7 @@ /* 给定一个二叉树,检查它是否是镜像对称的。 - 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 + 例如,二叉树 [1,2,2,3,4,4,3] 是对称的。 1 / \ @@ -16,7 +16,7 @@ / \ / \ 3 4 4 3 - 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: + 但是下面这个 [1,2,2,null,3,null,3] 则不是镜像对称的: 1 / \ 2 2 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" index 32f708af..405f9fdc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" @@ -13,7 +13,7 @@ 二叉树的深度为根节点到最远叶子节点的最长路径上的节点数。 -说明: 叶子节点是指没有子节点的节点。 +说明: 叶子节点是指没有子节点的节点。 示例: 给定二叉树 [3,9,20,null,null,15,7], @@ -23,7 +23,7 @@ 9 20 / \ 15 7 -返回它的最大深度 3 。 +返回它的最大深度 3 。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" index 849963dc..0ab61ff0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" @@ -8,7 +8,7 @@ /* 给定一个二叉树,判断它是否是高度平衡的二叉树。 本题中,一棵高度平衡二叉树定义为: - 一个二叉树每个结点 的左右两个子树的高度差的绝对值不超过1。 + 一个二叉树每个结点 的左右两个子树的高度差的绝对值不超过1。 示例 1: 给定二叉树 [3,9,20,null,null,15,7] @@ -28,7 +28,7 @@ 3 3 / \ 4 4 -返回 false 。 +返回 false 。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/balanced-binary-tree diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" index 6a10a560..7af7244c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" @@ -31,7 +31,7 @@ 输入:root = [2,null,3,null,4,null,5,null,6] 输出:5 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" index 0737512d..8d88b218 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" @@ -4,13 +4,13 @@ import org.junit.Test; /* -给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 +给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 如果你最多只允许完成一笔交易(即买入和卖出一支股票一次),设计一个算法来计算你所能获取的最大利润。 注意:你不能在买入股票前卖出股票。 -  + 示例 1: diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" index c309a41d..1453ea84 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" @@ -4,28 +4,28 @@ import org.junit.Test; /* -给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 +给定一个数组,它的第 i 个元素是一支给定股票第 i 天的价格。 设计一个算法来计算你所能获取的最大利润。你可以尽可能地完成更多的交易(多次买卖一支股票)。 注意:你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 -  + 示例 1: 输入: [7,1,5,3,6,4] 输出: 7 解释: 在第 2 天(股票价格 = 1)的时候买入,在第 3 天(股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。 -  随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。 + 随后,在第 4 天(股票价格 = 3)的时候买入,在第 5 天(股票价格 = 6)的时候卖出, 这笔交易所能获得利润 = 6-3 = 3 。 示例 2: 输入: [1,2,3,4,5] 输出: 4 解释: 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。 -  注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。 -  因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。 -示例 3: + 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。 + 因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。 +示例 3: 输入: [7,6,4,3,1] 输出: 0 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" index 446a38f9..c32b59ef 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" @@ -8,21 +8,21 @@ 给定一个代表每个房屋存放金额的非负整数数组,计算你 不触动警报装置的情况下 ,一夜之内能够偷窃到的最高金额。 -  + 示例 1: 输入:[1,2,3,1] 输出:4 解释:偷窃 1 号房屋 (金额 = 1) ,然后偷窃 3 号房屋 (金额 = 3)。 -  偷窃到的最高金额 = 1 + 3 = 4 。 + 偷窃到的最高金额 = 1 + 3 = 4 。 示例 2: 输入:[2,7,9,3,1] 输出:12 解释:偷窃 1 号房屋 (金额 = 2), 偷窃 3 号房屋 (金额 = 9),接着偷窃 5 号房屋 (金额 = 1)。 -  偷窃到的最高金额 = 2 + 9 + 1 = 12 。 -  + 偷窃到的最高金额 = 2 + 9 + 1 = 12 。 + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" index 7b07458e..2810b18f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" @@ -6,23 +6,23 @@ /* 给定一个数组,它的第 i 个元素是一支给定的股票在第 i 天的价格。 -设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。 +设计一个算法来计算你所能获取的最大利润。你最多可以完成 两笔 交易。 -注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 +注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 -示例 1: +示例 1: 输入: [3,3,5,0,0,3,1,4] 输出: 6 解释: 在第 4 天(股票价格 = 0)的时候买入,在第 6 天(股票价格 = 3)的时候卖出,这笔交易所能获得利润 = 3-0 = 3 。 -  随后,在第 7 天(股票价格 = 1)的时候买入,在第 8 天 (股票价格 = 4)的时候卖出,这笔交易所能获得利润 = 4-1 = 3 。 + 随后,在第 7 天(股票价格 = 1)的时候买入,在第 8 天 (股票价格 = 4)的时候卖出,这笔交易所能获得利润 = 4-1 = 3 。 示例 2: 输入: [1,2,3,4,5] 输出: 4 -解释: 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。   -  注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。   -  因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。 +解释: 在第 1 天(股票价格 = 1)的时候买入,在第 5 天 (股票价格 = 5)的时候卖出, 这笔交易所能获得利润 = 5-1 = 4 。 + 注意你不能在第 1 天和第 2 天接连购买股票,之后再将它们卖出。 + 因为这样属于同时参与了多笔交易,你必须在再次购买前出售掉之前的股票。 示例 3: 输入: [7,6,4,3,1] diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" index fc14e36d..1c2cd737 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" @@ -10,7 +10,7 @@ 本题中,路径被定义为一条从树中任意节点出发,沿父节点-子节点连接,达到任意节点的序列。该路径至少包含一个节点,且不一定经过根节点。 -  + 示例 1: @@ -21,15 +21,15 @@ 2 3 输出:6 -示例 2: +示例 2: 输入:[-10,9,20,null,null,15,7] -  -10 -   / \ -  9  20 -    /  \ -   15   7 + -10 + / \ + 9 20 + / \ + 15 7 输出:42 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" index 3441b9f9..d5349f16 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" @@ -8,11 +8,11 @@ /* 给定一个未排序的整数数组,找出最长连续序列的长度。 -要求算法的时间复杂度为 O(n)。 +要求算法的时间复杂度为 O(n)。 示例: -输入: [100, 4, 200, 1, 3, 2] +输入: [100, 4, 200, 1, 3, 2] 输出: 4 解释: 最长连续序列是 [1, 2, 3, 4]。它的长度为 4。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" index 1fecbdd9..4a8e1f5a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" @@ -21,8 +21,8 @@ wordDict = ["cat", "cats", "and", "sand", "dog"] 输出: [ -  "cats and dog", -  "cat sand dog" + "cats and dog", + "cat sand dog" ] 示例 2: @@ -31,12 +31,12 @@ wordDict = ["apple", "pen", "applepen", "pine", "pineapple"] 输出: [ -  "pine apple pen apple", -  "pineapple pen apple", -  "pine applepen apple" + "pine apple pen apple", + "pineapple pen apple", + "pine applepen apple" ] 解释: 注意你可以重复使用字典中的单词。 -示例 3: +示例 3: 输入: s = "catsandog" diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" index 7624a3e1..54b431a4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" @@ -11,12 +11,12 @@ 如果数组元素个数小于 2,则返回 0。 -示例 1: +示例 1: 输入: [3,6,9,1] 输出: 3 解释: 排序后的数组是 [1,3,6,9], 其中相邻元素 (3,6) 和 (6,9) 之间都存在最大差值 3。 -示例 2: +示例 2: 输入: [10] 输出: 0 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" index 24360181..8ef068fe 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" @@ -8,9 +8,9 @@ 设计一个算法来计算你所能获取的最大利润。你最多可以完成 k 笔交易。 -注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 +注意: 你不能同时参与多笔交易(你必须在再次购买前出售掉之前的股票)。 -示例 1: +示例 1: 输入: [2,4,1], k = 2 输出: 2 @@ -20,7 +20,7 @@ 输入: [3,2,6,5,0,3], k = 2 输出: 7 解释: 在第 2 天 (股票价格 = 2) 的时候买入,在第 3 天 (股票价格 = 6) 的时候卖出, 这笔交易所能获得利润 = 6-2 = 4 。 -  随后,在第 5 天 (股票价格 = 0) 的时候买入,在第 6 天 (股票价格 = 3) 的时候卖出, 这笔交易所能获得利润 = 3-0 = 3 。 + 随后,在第 5 天 (股票价格 = 0) 的时候买入,在第 6 天 (股票价格 = 3) 的时候卖出, 这笔交易所能获得利润 = 3-0 = 3 。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" index f314ad9d..4fdf4a78 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" @@ -11,7 +11,7 @@ 给定一个二叉树,返回其按层次遍历的节点值。 (即逐层地,从左到右访问所有节点)。 例如: -给定二叉树: [3,9,20,null,null,15,7], +给定二叉树: [3,9,20,null,null,15,7], 3 / \ diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" index 17bcea0a..bab22208 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" @@ -7,7 +7,7 @@ import java.util.*; /* -给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则: +给定两个单词(beginWord 和 endWord)和一个字典,找到从 beginWord 到 endWord 的最短转换序列的长度。转换需遵循如下规则: 每次转换只能改变一个字母。 转换过程中的中间单词必须是字典中的单词。 @@ -18,7 +18,7 @@ 所有单词只由小写字母组成。 字典中不存在重复的单词。 你可以假设 beginWord 和 endWord 是非空的,且二者不相同。 -示例 1: +示例 1: 输入: beginWord = "hit", @@ -36,9 +36,9 @@ endWord = "cog" wordList = ["hot","dot","dog","lot","log"] -输出: 0 +输出: 0 -解释: endWord "cog" 不在字典中,所以无法进行转换。 +解释: endWord "cog" 不在字典中,所以无法进行转换。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/word-ladder diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" index aa5d2267..b585a03e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" @@ -4,18 +4,18 @@ import org.junit.Test; /** - * 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 + * 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 *

- * 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。 + * 你有一辆油箱容量无限的的汽车,从第 i 个加油站开往第 i+1 个加油站需要消耗汽油 cost[i] 升。你从其中的一个加油站出发,开始时油箱为空。 *

* 如果你可以绕环路行驶一周,则返回出发时加油站的编号,否则返回 -1。 *

- * 说明:  + * 说明: *

* 如果题目有解,该答案即为唯一答案。 * 输入数组均为非空数组,且长度相同。 * 输入数组中的元素均为非负数。 - * 示例 1: + * 示例 1: *

* 输入: * gas = [1,2,3,4,5] diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" index 181fb60f..4a846672 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" @@ -10,7 +10,7 @@ import java.util.Set; /* -给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 +给定一个非空字符串 s 和一个包含非空单词的列表 wordDict,判定 s 是否可以被空格拆分为一个或多个在字典中出现的单词。 说明: @@ -26,7 +26,7 @@ 输入: s = "applepenapple", wordDict = ["apple", "pen"] 输出: true 解释: 返回 true 因为 "applepenapple" 可以被拆分成 "apple pen apple"。 -  注意你可以重复使用字典中的单词。 + 注意你可以重复使用字典中的单词。 示例 3: 输入: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"] diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" index b445c54d..cd21cbcc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" @@ -22,7 +22,7 @@ 3 输出: [1,2,3] -进阶: 递归算法很简单,你可以通过迭代算法完成吗? +进阶: 递归算法很简单,你可以通过迭代算法完成吗? 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/binary-tree-preorder-traversal diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" index 0b2c7f56..57f0cbf6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" @@ -23,7 +23,7 @@ 3 输出: [3,2,1] -进阶: 递归算法很简单,你可以通过迭代算法完成吗? +进阶: 递归算法很简单,你可以通过迭代算法完成吗? 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/binary-tree-postorder-traversal diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" index 084ed096..0f235e7a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" @@ -6,13 +6,13 @@ import java.util.HashMap; /* -运用你所掌握的数据结构,设计和实现一个  LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和 写入数据 put 。 +运用你所掌握的数据结构,设计和实现一个 LRU (最近最少使用) 缓存机制。它应该支持以下操作: 获取数据 get 和 写入数据 put 。 获取数据 get(key) - 如果密钥 (key) 存在于缓存中,则获取密钥的值(总是正数),否则返回 -1。 写入数据 put(key, val) - 如果密钥不存在,则写入其数据值。当缓存容量达到上限时,它应该在写入新数据之前删除最近最少使用的数据值,从而为新的数据值留出空间。 进阶: -你是否可以在 O(1) 时间复杂度内完成这两种操作? +你是否可以在 O(1) 时间复杂度内完成这两种操作? 示例: diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index 765e8a56..f08c35ba 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -14,20 +14,20 @@ 插入排序的动画演示如上。从第一个元素开始,该链表可以被认为已经部分排序(用黑色表示)。 每次迭代时,从输入数据中移除一个元素(用红色表示),并原地将其插入到已排好序的链表中。 -   + 插入排序算法: 插入排序是迭代的,每次只移动一个元素,直到所有元素可以形成一个有序的输出列表。 每次迭代中,插入排序只从输入数据中移除一个待排序的元素,找到它在序列中适当的位置,并将其插入。 重复直到所有输入数据插入完为止。 -   + 示例 1: 输入: 4->2->1->3 输出: 1->2->3->4 - 示例 2: + 示例 2: 输入: -1->5->3->4->0 输出: -1->0->3->4->5 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 49e1b107..2f7607d9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -8,11 +8,11 @@ import org.junit.Test; /** - 给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表 。 + 给你链表的头结点 head ,请将其按 升序 排列并返回 排序后的链表 。 进阶: - 你可以在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序吗? -   + 你可以在 O(n log n) 时间复杂度和常数级空间复杂度下,对链表进行排序吗? + 示例 1: 输入:head = [4,2,1,3] diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" index 77e6d6d6..96bfeea1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" @@ -5,7 +5,7 @@ /* 假设按照升序排序的数组在预先未知的某个点上进行了旋转。 -( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 +( 例如,数组 [0,1,2,4,5,6,7] 可能变为 [4,5,6,7,0,1,2] )。 请找出其中最小的元素。 你可以假设数组中不存在重复元素。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" "b/src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" index c868b59b..9d604986 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" @@ -10,11 +10,11 @@ /** 给出 R 行 C 列的矩阵,其中的单元格的整数坐标为 (r, c),满足 0 <= r < R 且 0 <= c < C。 - 另外,我们在该矩阵中给出了一个坐标为 (r0, c0) 的单元格。 + 另外,我们在该矩阵中给出了一个坐标为 (r0, c0) 的单元格。 返回矩阵中的所有单元格的坐标,并按到 (r0, c0) 的距离从最小到最大的顺序排,其中,两单元格(r1, c1) 和 (r2, c2) 之间的距离是曼哈顿距离,|r1 - r2| + |c1 - c2|。(你可以按任何满足此条件的顺序返回答案。) -   + 示例 1: @@ -33,7 +33,7 @@ 输出:[[1,2],[0,2],[1,1],[0,1],[1,0],[0,0]] 解释:从 (r0, c0) 到其他单元格的距离为:[0,1,1,2,2,3] 其他满足题目要求的答案也会被视为正确,例如 [[1,2],[1,1],[0,2],[1,0],[0,1],[0,0]]。 -   + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" "b/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" index 2a5e6127..25581c96 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" @@ -4,8 +4,8 @@ import org.junit.Test; /* -对于字符串 S 和 T,只有在 S = T + ... + T(T 与自身连接 1 次或多次)时,我们才认定 “T 能除尽 S”。 -返回最长字符串 X,要求满足 X 能除尽 str1 且 X 能除尽 str2。 +对于字符串 S 和 T,只有在 S = T + ... + T(T 与自身连接 1 次或多次)时,我们才认定 “T 能除尽 S”。 +返回最长字符串 X,要求满足 X 能除尽 str1 且 X 能除尽 str2。 示例 1: @@ -19,13 +19,13 @@ 输入:str1 = "LEET", str2 = "CODE" 输出:"" -  + 提示: 1 <= str1.length <= 1000 1 <= str2.length <= 1000 -str1[i] 和 str2[i] 为大写英文字母 +str1[i] 和 str2[i] 为大写英文字母 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/greatest-common-divisor-of-strings diff --git "a/src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" "b/src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" index f7f800bd..1b4d5d7e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" @@ -7,26 +7,26 @@ import java.util.Map; /** - 给你两个数组,arr1 和 arr2, + 给你两个数组,arr1 和 arr2, - arr2 中的元素各不相同 - arr2 中的每个元素都出现在 arr1 中 - 对 arr1 中的元素进行排序,使 arr1 中项的相对顺序和 arr2 中的相对顺序相同。未在 arr2 中出现过的元素需要按照升序放在 arr1 的末尾。 + arr2 中的元素各不相同 + arr2 中的每个元素都出现在 arr1 中 + 对 arr1 中的元素进行排序,使 arr1 中项的相对顺序和 arr2 中的相对顺序相同。未在 arr2 中出现过的元素需要按照升序放在 arr1 的末尾。 -   + 示例: 输入:arr1 = [2,3,1,3,2,4,6,7,9,2,19], arr2 = [2,1,4,3,9,6] 输出:[2,2,2,1,4,3,3,9,6,7,19] -   + 提示: 1 <= arr1.length, arr2.length <= 1000 0 <= arr1[i], arr2[i] <= 1000 - arr2 中的元素 arr2[i] 各不相同 - arr2 中的每个元素 arr2[i] 都出现在 arr1 中 + arr2 中的元素 arr2[i] 各不相同 + arr2 中的每个元素 arr2[i] 都出现在 arr1 中 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" "b/src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" index b6d5f9fd..dbe5d7a0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" @@ -4,15 +4,15 @@ import org.junit.Test; /* -给你一份『词汇表』(字符串数组) words 和一张『字母表』(字符串) chars。 +给你一份『词汇表』(字符串数组) words 和一张『字母表』(字符串) chars。 -假如你可以用 chars 中的『字母』(字符)拼写出 words 中的某个『单词』(字符串),那么我们就认为你掌握了这个单词。 +假如你可以用 chars 中的『字母』(字符)拼写出 words 中的某个『单词』(字符串),那么我们就认为你掌握了这个单词。 注意:每次拼写时,chars 中的每个字母都只能用一次。 -返回词汇表 words 中你掌握的所有单词的 长度之和。 +返回词汇表 words 中你掌握的所有单词的 长度之和。 -  + 示例 1: @@ -26,12 +26,12 @@ 输出:10 解释: 可以形成字符串 "hello" 和 "world",所以答案是 5 + 5 = 10。 -  + 提示: 1 <= words.length <= 1000 -1 <= words[i].length, chars.length <= 100 +1 <= words[i].length, chars.length <= 100 所有字符串中都仅包含小写英文字母 diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" index 800b24de..a2cc7dc6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" @@ -8,17 +8,17 @@ /* 请编写一个函数,使其可以删除某个链表中给定的(非末尾)结点,你将只被给定要求被删除的结点。 -现有一个链表 -- head = [4,5,1,9],它可以表示为: 4->5->1->9 +现有一个链表 -- head = [4,5,1,9],它可以表示为: 4->5->1->9 示例 1: 输入: head = [4,5,1,9], node = 5 输出: [4,1,9] -解释: 给定你链表中值为 5 的第二个结点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9. +解释: 给定你链表中值为 5 的第二个结点,那么在调用了你的函数之后,该链表应变为 4 -> 1 -> 9. 示例 2: 输入: head = [4,5,1,9], node = 1 输出: [4,5,9] -解释: 给定你链表中值为 1 的第三个结点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9. +解释: 给定你链表中值为 1 的第三个结点,那么在调用了你的函数之后,该链表应变为 4 -> 5 -> 9. 说明: 链表至少包含两个节点。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" index 9ae43586..1c402d94 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" @@ -9,7 +9,7 @@ /* 给定两个字符串 s 和 t ,编写一个函数来判断 t 是否是 s 的字母异位词。 - 示例 1: + 示例 1: 输入: s = "anagram", t = "nagaram" 输出: true diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" "b/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" index 37cc48c7..75366fe1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" @@ -14,7 +14,7 @@ 请设计一个算法来实现二叉树的序列化与反序列化。这里不限定你的序列 / 反序列化算法执行逻辑,你只需要保证一个二叉树可以被序列化为一个字符串并且将这个字符串反序列化为原始的树结构。 -示例:  +示例: 你可以将以下二叉树: @@ -25,9 +25,9 @@ 4 5 序列化为 "[1,2,3,null,null,4,5]" -提示: 这与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这种方式,你也可以采用其他的方法解决这个问题。 +提示: 这与 LeetCode 目前使用的方式一致,详情请参阅 LeetCode 序列化二叉树的格式。你并非必须采取这种方式,你也可以采用其他的方法解决这个问题。 -说明: 不要使用类的成员 / 全局 / 静态变量来存储状态,你的序列化和反序列化算法应该是无状态的。 +说明: 不要使用类的成员 / 全局 / 静态变量来存储状态,你的序列化和反序列化算法应该是无状态的。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/serialize-and-deserialize-binary-tree diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" index f42fb4cc..c13747c7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" @@ -6,31 +6,31 @@ import java.util.*; /* -你这个学期必须选修 numCourse 门课程,记为 0 到 numCourse-1 。 +你这个学期必须选修 numCourse 门课程,记为 0 到 numCourse-1 。 -在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们:[0,1] +在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们:[0,1] 给定课程总量以及它们的先决条件,请你判断是否可能完成所有课程的学习? -  + 示例 1: 输入: 2, [[1,0]] 输出: true -解释: 总共有 2 门课程。学习课程 1 之前,你需要完成课程 0。所以这是可能的。 +解释: 总共有 2 门课程。学习课程 1 之前,你需要完成课程 0。所以这是可能的。 示例 2: 输入: 2, [[1,0],[0,1]] 输出: false -解释: 总共有 2 门课程。学习课程 1 之前,你需要先完成​课程 0;并且学习课程 0 之前,你还应先完成课程 1。这是不可能的。 -  +解释: 总共有 2 门课程。学习课程 1 之前,你需要先完成​课程 0;并且学习课程 0 之前,你还应先完成课程 1。这是不可能的。 + 提示: 输入的先决条件是由 边缘列表 表示的图形,而不是 邻接矩阵 。详情请参见图的表示法。 你可以假定输入的先决条件中没有重复的边。 -1 <= numCourses <= 10^5 +1 <= numCourses <= 10^5 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" index a8a28496..11dda101 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" @@ -7,25 +7,25 @@ import java.util.*; /* -现在你总共有 n 门课需要选,记为 0 到 n-1。 +现在你总共有 n 门课需要选,记为 0 到 n-1。 -在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] +在选修某些课程之前需要一些先修课程。 例如,想要学习课程 0 ,你需要先完成课程 1 ,我们用一个匹配来表示他们: [0,1] 给定课程总量以及它们的先决条件,返回你为了学完所有课程所安排的学习顺序。 可能会有多个正确的顺序,你只要返回一种就可以了。如果不可能完成所有课程,返回一个空数组。 -示例 1: +示例 1: 输入: 2, [[1,0]] 输出: [0,1] -解释: 总共有 2 门课程。要学习课程 1,你需要先完成课程 0。因此,正确的课程顺序为 [0,1] 。 -示例 2: +解释: 总共有 2 门课程。要学习课程 1,你需要先完成课程 0。因此,正确的课程顺序为 [0,1] 。 +示例 2: 输入: 4, [[1,0],[2,0],[3,1],[3,2]] 输出: [0,1,2,3] or [0,2,1,3] -解释: 总共有 4 门课程。要学习课程 3,你应该先完成课程 1 和课程 2。并且课程 1 和课程 2 都应该排在课程 0 之后。 -  因此,一个正确的课程顺序是 [0,1,2,3] 。另一个正确的排序是 [0,2,1,3] 。 +解释: 总共有 4 门课程。要学习课程 3,你应该先完成课程 1 和课程 2。并且课程 1 和课程 2 都应该排在课程 0 之后。 + 因此,一个正确的课程顺序是 [0,1,2,3] 。另一个正确的排序是 [0,2,1,3] 。 说明: 输入的先决条件是由边缘列表表示的图形,而不是邻接矩阵。详情请参见图的表示法。 @@ -34,7 +34,7 @@ 这个问题相当于查找一个循环是否存在于有向图中。如果存在循环,则不存在拓扑排序,因此不可能选取所有课程进行学习。 通过 DFS 进行拓扑排序 - 一个关于Coursera的精彩视频教程(21分钟),介绍拓扑排序的基本概念。 -拓扑排序也可以通过 BFS 完成。 +拓扑排序也可以通过 BFS 完成。 来源:力扣(LeetCode) 链接:https://leetcode-cn.com/problems/course-schedule-ii diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" index 4dfa71a6..b14d3d3a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" @@ -8,9 +8,9 @@ 给定一个代表每个房屋存放金额的非负整数数组,计算你 在不触动警报装置的情况下 ,能够偷窃到的最高金额。 -  + -示例 1: +示例 1: 输入:nums = [2,3,2] 输出:3 @@ -20,12 +20,12 @@ 输入:nums = [1,2,3,1] 输出:4 解释:你可以先偷窃 1 号房屋(金额 = 1),然后偷窃 3 号房屋(金额 = 3)。 -  偷窃到的最高金额 = 1 + 3 = 4 。 + 偷窃到的最高金额 = 1 + 3 = 4 。 示例 3: 输入:nums = [0] 输出:0 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" index 77866c87..be663cc6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" @@ -12,7 +12,7 @@ 输入: [3,2,1,5,6,4] 和 k = 2 输出: 5 -示例 2: +示例 2: 输入: [3,2,3,1,2,4,5,5,6] 和 k = 4 输出: 4 diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" index 87cc8017..4239b64b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" @@ -10,12 +10,12 @@ import java.util.List; /* -找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。 +找出所有相加之和为 n 的 k 个数的组合。组合中只允许含有 1 - 9 的正整数,并且每种组合中不存在重复的数字。 说明: 所有数字都是正整数。 -解集不能包含重复的组合。  +解集不能包含重复的组合。 示例 1: 输入: k = 3, n = 7 diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" index 9d5d07b2..ab4e215d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" @@ -10,7 +10,7 @@ 说明: -完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置。若最底层为第 h 层,则该层包含 1~ 2h 个节点。 +完全二叉树的定义如下:在完全二叉树中,除了最底层节点可能没填满外,其余每层节点数都达到最大值,并且最下面一层的节点都集中在该层最左边的若干位置。若最底层为第 h 层,则该层包含 1~ 2h 个节点。 示例: diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" "b/src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" index c0e3d2f4..69deffcf 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" @@ -17,7 +17,7 @@ [2,1,1] ] 输出: 4 -解释: 最长递增路径为 [1, 2, 6, 9]。 +解释: 最长递增路径为 [1, 2, 6, 9]。 示例 2: 输入: nums = @@ -27,7 +27,7 @@ [2,2,1] ] 输出: 4 -解释: 最长递增路径是 [3, 4, 5, 6]。注意不允许在对角线方向上移动。 +解释: 最长递增路径是 [3, 4, 5, 6]。注意不允许在对角线方向上移动。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" index 6e65164e..ed8873ff 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" @@ -13,12 +13,12 @@ 输入: [10,9,2,5,3,7,101,18] 输出: 4 -解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。 +解释: 最长的上升子序列是 [2,3,7,101],它的长度是 4。 说明: 可能会有多种最长上升子序列的组合,你只需要输出对应的长度即可。 -你算法的时间复杂度应该为 O(n2) 。 -进阶: 你能将算法的时间复杂度降低到 O(n log n) 吗? +你算法的时间复杂度应该为 O(n2) 。 +进阶: 你能将算法的时间复杂度降低到 O(n log n) 吗? diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" index 7ea1b294..328a5409 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" @@ -4,7 +4,7 @@ import org.junit.Test; /* -给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格 。​ +给定一个整数数组,其中第 i 个元素代表了第 i 天的股票价格 。​ 设计一个算法计算出最大利润。在满足以下约束条件下,你可以尽可能地完成更多的交易(多次买卖一支股票): diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" index 7b26a4fb..a0ba02a1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" @@ -5,13 +5,13 @@ import org.junit.Test; /* -给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。 +给定不同面额的硬币 coins 和一个总金额 amount。编写一个函数来计算可以凑成总金额所需的最少的硬币个数。如果没有任何一种硬币组合能组成总金额,返回 -1。 你可以认为每种硬币的数量是无限的。 -  + -示例 1: +示例 1: 输入:coins = [1, 2, 5], amount = 11 输出:3 @@ -32,7 +32,7 @@ 输入:coins = [1], amount = 2 输出:2 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" index 7c253749..fd1305e2 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" @@ -26,19 +26,19 @@ 3 1 输出: 7 -解释: 小偷一晚能够盗取的最高金额 = 3 + 3 + 1 = 7. +解释: 小偷一晚能够盗取的最高金额 = 3 + 3 + 1 = 7. 示例 2: 输入: [3,4,5,1,3,null,1] -  3 + 3 / \ 4 5 / \ \ 1 3 1 输出: 9 -解释: 小偷一晚能够盗取的最高金额 = 4 + 5 = 9. +解释: 小偷一晚能够盗取的最高金额 = 4 + 5 = 9. 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" index 98e5435c..8051edb2 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" @@ -4,9 +4,9 @@ import org.junit.Test; /* -有两个容量分别为 x升 和 y升 的水壶以及无限多的水。请判断能否通过使用这两个水壶,从而可以得到恰好 z升 的水? +有两个容量分别为 x升 和 y升 的水壶以及无限多的水。请判断能否通过使用这两个水壶,从而可以得到恰好 z升 的水? -如果可以,最后请用以上水壶中的一或两个来盛放取得的 z升 水。 +如果可以,最后请用以上水壶中的一或两个来盛放取得的 z升 水。 你允许: diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" "b/src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" index 3c83d655..7decc500 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" @@ -8,11 +8,11 @@ import java.util.Stack; /* -给定两个 没有重复元素 的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集。找到 nums1 中每个元素在 nums2 中的下一个比其大的值。 +给定两个 没有重复元素 的数组 nums1 和 nums2 ,其中nums1 是 nums2 的子集。找到 nums1 中每个元素在 nums2 中的下一个比其大的值。 -nums1 中数字 x 的下一个更大元素是指 x 在 nums2 中对应位置的右边的第一个比 x 大的元素。如果不存在,对应位置输出 -1 。 +nums1 中数字 x 的下一个更大元素是指 x 在 nums2 中对应位置的右边的第一个比 x 大的元素。如果不存在,对应位置输出 -1 。 -  + 示例 1: @@ -27,14 +27,14 @@ 输入: nums1 = [2,4], nums2 = [1,2,3,4]. 输出: [3,-1] 解释: -  对于 num1 中的数字 2 ,第二个数组中的下一个较大数字是 3 。 + 对于 num1 中的数字 2 ,第二个数组中的下一个较大数字是 3 。 对于 num1 中的数字 4 ,第二个数组中没有下一个更大的数字,因此输出 -1 。 -  + 提示: nums1和nums2中所有元素是唯一的。 -nums1和nums2 的数组大小都不超过1000。 +nums1和nums2 的数组大小都不超过1000。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" "b/src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" index 8ee22946..57daca41 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" @@ -6,13 +6,13 @@ import java.util.HashMap; /* -设计并实现最不经常使用(LFU)缓存的数据结构。它应该支持以下操作:get 和 put。 +设计并实现最不经常使用(LFU)缓存的数据结构。它应该支持以下操作:get 和 put。 -get(key) - 如果键存在于缓存中,则获取键的值(总是正数),否则返回 -1。 -put(key, val) - 如果键不存在,请设置或插入值。当缓存达到其容量时,它应该在插入新项目之前,使最不经常使用的项目无效。在此问题中,当存在平局(即两个或更多个键具有相同使用频率)时,最近最少使用的键将被去除。 +get(key) - 如果键存在于缓存中,则获取键的值(总是正数),否则返回 -1。 +put(key, val) - 如果键不存在,请设置或插入值。当缓存达到其容量时,它应该在插入新项目之前,使最不经常使用的项目无效。在此问题中,当存在平局(即两个或更多个键具有相同使用频率)时,最近最少使用的键将被去除。 进阶: -你是否可以在 O(1) 时间复杂度内执行两项操作? +你是否可以在 O(1) 时间复杂度内执行两项操作? 示例: diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" "b/src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" index 122f1fc2..bc0010d4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" @@ -8,11 +8,11 @@ import java.util.Stack; /** - * 给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小。 + * 给定一个以字符串表示的非负整数 num,移除这个数中的 k 位数字,使得剩下的数字最小。 *

* 注意: *

- * num 的长度小于 10002 且 ≥ k。 + * num 的长度小于 10002 且 ≥ k。 * num 不会包含任何前导零。 * 示例 1 : *

diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" index f22d4ea0..0c3b8ccd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" @@ -16,7 +16,7 @@ 输入:[[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]] 输出:[[5,0], [7,0], [5,2], [6,1], [4,4], [7,1]] -   + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" "b/src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" index abda1a72..459c5331 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" @@ -18,9 +18,9 @@ 输出: true 解释: 数组可以分割成 [1, 5, 5] 和 [11]. -  + -示例 2: +示例 2: 输入: [1, 2, 3, 5] diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" "b/src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" index 625d3e43..9fcd836f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" @@ -9,11 +9,11 @@ /* 在二维空间中有许多球形的气球。对于每个气球,提供的输入是水平方向上,气球直径的开始和结束坐标。由于它是水平的,所以纵坐标并不重要,因此只要知道开始和结束的横坐标就足够了。开始坐标总是小于结束坐标。 -一支弓箭可以沿着 x 轴从不同点完全垂直地射出。在坐标 x 处射出一支箭,若有一个气球的直径的开始和结束坐标为 xstart,xend, 且满足  xstart ≤ x ≤ xend,则该气球会被引爆。可以射出的弓箭的数量没有限制。 弓箭一旦被射出之后,可以无限地前进。我们想找到使得所有气球全部被引爆,所需的弓箭的最小数量。 +一支弓箭可以沿着 x 轴从不同点完全垂直地射出。在坐标 x 处射出一支箭,若有一个气球的直径的开始和结束坐标为 xstart,xend, 且满足 xstart ≤ x ≤ xend,则该气球会被引爆。可以射出的弓箭的数量没有限制。 弓箭一旦被射出之后,可以无限地前进。我们想找到使得所有气球全部被引爆,所需的弓箭的最小数量。 给你一个数组 points ,其中 points [i] = [xstart,xend] ,返回引爆所有气球所必须射出的最小弓箭数。 -  + 示例 1: 输入:points = [[10,16],[2,8],[1,6],[7,12]] @@ -35,13 +35,13 @@ 输入:points = [[2,3],[2,3]] 输出:1 -  + 提示: 0 <= points.length <= 104 points[i].length == 2 --231 <= xstart < xend <= 231 - 1 +-231 <= xstart < xend <= 231 - 1 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" "b/src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" index 795db5f7..33941b25 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" @@ -10,7 +10,7 @@ 如果 x 的所有元素也是 y 的元素,集合 x 是集合 y 的 子集 。 -  + 示例 1: @@ -23,13 +23,13 @@ 输入:strs = ["10", "0", "1"], m = 1, n = 1 输出:2 解释:最大的子集是 {"0", "1"} ,所以答案是 2 。 -  + 提示: 1 <= strs.length <= 600 1 <= strs[i].length <= 100 -strs[i] 仅由 '0' 和 '1' 组成 +strs[i] 仅由 '0' 和 '1' 组成 1 <= m, n <= 100 diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" index 16bcc36c..172063cc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" @@ -4,7 +4,7 @@ import org.junit.Test; /* -给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在你有两个符号 + 和 -。对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面。 +给定一个非负整数数组,a1, a2, ..., an, 和一个目标数,S。现在你有两个符号 + 和 -。对于数组中的任意一个整数,你都可以从 + 或 -中选择一个符号添加在前面。 返回可以使最终数组和为目标数 S 的所有添加符号的方法数。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" "b/src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" index 5d9ac16f..dd5b6981 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" @@ -8,20 +8,20 @@ /* 电子游戏“辐射4”中,任务“通向自由”要求玩家到达名为“Freedom Trail Ring”的金属表盘,并使用表盘拼写特定关键词才能开门。 -给定一个字符串 ring,表示刻在外环上的编码;给定另一个字符串 key,表示需要拼写的关键词。您需要算出能够拼写关键词中所有字符的最少步数。 +给定一个字符串 ring,表示刻在外环上的编码;给定另一个字符串 key,表示需要拼写的关键词。您需要算出能够拼写关键词中所有字符的最少步数。 -最初,ring 的第一个字符与12:00方向对齐。您需要顺时针或逆时针旋转 ring 以使 key 的一个字符在 12:00 方向对齐,然后按下中心按钮,以此逐个拼写完 key 中的所有字符。 +最初,ring 的第一个字符与12:00方向对齐。您需要顺时针或逆时针旋转 ring 以使 key 的一个字符在 12:00 方向对齐,然后按下中心按钮,以此逐个拼写完 key 中的所有字符。 -旋转 ring 拼出 key 字符 key[i] 的阶段中: +旋转 ring 拼出 key 字符 key[i] 的阶段中: -您可以将 ring 顺时针或逆时针旋转一个位置,计为1步。旋转的最终目的是将字符串 ring 的一个字符与 12:00 方向对齐,并且这个字符必须等于字符 key[i] 。 -如果字符 key[i] 已经对齐到12:00方向,您需要按下中心按钮进行拼写,这也将算作 1 步。按完之后,您可以开始拼写 key 的下一个字符(下一阶段), 直至完成所有拼写。 +您可以将 ring 顺时针或逆时针旋转一个位置,计为1步。旋转的最终目的是将字符串 ring 的一个字符与 12:00 方向对齐,并且这个字符必须等于字符 key[i] 。 +如果字符 key[i] 已经对齐到12:00方向,您需要按下中心按钮进行拼写,这也将算作 1 步。按完之后,您可以开始拼写 key 的下一个字符(下一阶段), 直至完成所有拼写。 示例: -  + -  + 输入: ring = "godding", key = "gd" 输出: 4 解释: @@ -31,9 +31,9 @@ 因此最终的输出是 4。 提示: -ring 和 key 的字符串长度取值范围均为 1 至 100; +ring 和 key 的字符串长度取值范围均为 1 至 100; 两个字符串中都只有小写字符,并且均可能存在重复字符; -字符串 key 一定可以由字符串 ring 旋转拼出。 +字符串 key 一定可以由字符串 ring 旋转拼出。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" index ce119861..7ede6420 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" @@ -6,7 +6,7 @@ /* 给定一个字符串 s ,找到其中最长的回文子序列,并返回该序列的长度。可以假设 s 的最大长度为 1000 。 -  + 示例 1: 输入: @@ -26,7 +26,7 @@ 2 一个可能的最长回文子序列为 "bb"。 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" "b/src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" index bcb3262c..7e831bb7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" @@ -4,9 +4,9 @@ import org.junit.Test; /* -给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。  +给定不同面额的硬币和一个总金额。写出函数来计算可以凑成总金额的硬币组合数。假设每一种面额的硬币有无限个。 -  + 示例 1: diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" "b/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" index dedebb03..b188b1cd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" @@ -7,9 +7,9 @@ import java.util.Queue; /* -班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友。所谓的朋友圈,是指所有朋友的集合。 +班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友。所谓的朋友圈,是指所有朋友的集合。 -给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系。如果M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道。你必须输出所有学生中的已知的朋友圈总数。 +给定一个 N * N 的矩阵 M,表示班级中学生之间的朋友关系。如果M[i][j] = 1,表示已知第 i 个和 j 个学生互为朋友关系,否则为不知道。你必须输出所有学生中的已知的朋友圈总数。 示例 1: diff --git "a/src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" "b/src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" index 493afd17..040c59c6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" @@ -4,7 +4,7 @@ import org.junit.Test; /* -给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合。你可以假设二维矩阵的四个边缘都被水包围着。 +给定一个包含了一些 0 和 1的非空二维数组 grid , 一个 岛屿 是由四个方向 (水平或垂直) 的 1 (代表土地) 构成的组合。你可以假设二维矩阵的四个边缘都被水包围着。 找到给定的二维数组中最大的岛屿面积。(如果没有岛屿,则返回面积为0。) @@ -18,14 +18,14 @@ [0,0,0,0,0,0,0,0,0,0,1,0,0], [0,0,0,0,0,0,0,1,1,1,0,0,0], [0,0,0,0,0,0,0,1,1,0,0,0,0]] -对于上面这个给定矩阵应返回 6。注意答案不应该是11,因为岛屿只能包含水平或垂直的四个方向的‘1’。 +对于上面这个给定矩阵应返回 6。注意答案不应该是11,因为岛屿只能包含水平或垂直的四个方向的‘1’。 示例 2: [[0,0,0,0,0,0,0,0]] -对于上面这个给定的矩阵, 返回 0。 +对于上面这个给定的矩阵, 返回 0。 -注意: 给定的矩阵grid 的长度和宽度都不超过 50。 +注意: 给定的矩阵grid 的长度和宽度都不超过 50。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" "b/src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" index b7255ffd..7199372e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" @@ -4,7 +4,7 @@ import org.junit.Test; /* -给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target  ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。 +给定一个 n 个元素有序的(升序)整型数组 nums 和一个目标值 target ,写一个函数搜索 nums 中的 target,如果目标值存在返回下标,否则返回 -1。 示例 1: @@ -12,18 +12,18 @@ 输入: nums = [-1,0,3,5,9,12], target = 9 输出: 4 解释: 9 出现在 nums 中并且下标为 4 -示例 2: +示例 2: 输入: nums = [-1,0,3,5,9,12], target = 2 输出: -1 解释: 2 不存在 nums 中因此返回 -1 -  + 提示: -你可以假设 nums 中的所有元素是不重复的。 -n 将在 [1, 10000]之间。 -nums 的每个元素都将在 [-9999, 9999]之间。 +你可以假设 nums 中的所有元素是不重复的。 +n 将在 [1, 10000]之间。 +nums 的每个元素都将在 [-9999, 9999]之间。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" "b/src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" index 33bc2f8c..5c63e89b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" @@ -4,7 +4,7 @@ import org.junit.Test; /* -给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 ;非负整数 fee 代表了交易股票的手续费用。 +给定一个整数数组 prices,其中第 i 个元素代表了第 i 天的股票价格 ;非负整数 fee 代表了交易股票的手续费用。 你可以无限次地完成交易,但是你每笔交易都需要付手续费。如果你已经购买了一个股票,在卖出它之前你就不能再继续购买股票了。 @@ -17,11 +17,11 @@ 输入: prices = [1, 3, 2, 8, 4, 9], fee = 2 输出: 8 解释: 能够达到的最大利润: -在此处买入 prices[0] = 1 +在此处买入 prices[0] = 1 在此处卖出 prices[3] = 8 在此处买入 prices[4] = 4 在此处卖出 prices[5] = 9 -总利润: ((8 - 1) - 2) + ((9 - 4) - 2) = 8. +总利润: ((8 - 1) - 2) + ((9 - 4) - 2) = 8. 注意: 0 < prices.length <= 50000. diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" index 50ad96f5..9c2e07c5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" @@ -10,11 +10,11 @@ import java.util.List; /* -给定一个带有头结点 head 的非空单链表,返回链表的中间结点。 +给定一个带有头结点 head 的非空单链表,返回链表的中间结点。 如果有两个中间结点,则返回第二个中间结点。 -  + 示例 1: @@ -23,16 +23,16 @@ 返回的结点值为 3 。 (测评系统对该结点序列化表述是 [3,4,5])。 注意,我们返回了一个 ListNode 类型的对象 ans,这样: ans.val = 3, ans.next.val = 4, ans.next.next.val = 5, 以及 ans.next.next.next = NULL. -示例 2: +示例 2: 输入:[1,2,3,4,5,6] 输出:此列表中的结点 4 (序列化形式:[4,5,6]) 由于该列表有两个中间结点,值分别为 3 和 4,我们返回第二个结点。 -  + 提示: -给定链表的结点数介于 1 和 100 之间。 +给定链表的结点数介于 1 和 100 之间。 来源:力扣(LeetCode) diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" "b/src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" index bcaf85c9..29281202 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" @@ -1,19 +1,19 @@ package algorithm_practice.LeetCode.code800; /* -你将获得 K 个鸡蛋,并可以使用一栋从 1 到 N  共有 N 层楼的建筑。 +你将获得 K 个鸡蛋,并可以使用一栋从 1 到 N 共有 N 层楼的建筑。 每个蛋的功能都是一样的,如果一个蛋碎了,你就不能再把它掉下去。 -你知道存在楼层 F ,满足 0 <= F <= N 任何从高于 F 的楼层落下的鸡蛋都会碎,从 F 楼层或比它低的楼层落下的鸡蛋都不会破。 +你知道存在楼层 F ,满足 0 <= F <= N 任何从高于 F 的楼层落下的鸡蛋都会碎,从 F 楼层或比它低的楼层落下的鸡蛋都不会破。 -每次移动,你可以取一个鸡蛋(如果你有完整的鸡蛋)并把它从任一楼层 X 扔下(满足 1 <= X <= N)。 +每次移动,你可以取一个鸡蛋(如果你有完整的鸡蛋)并把它从任一楼层 X 扔下(满足 1 <= X <= N)。 你的目标是确切地知道 F 的值是多少。 无论 F 的初始值如何,你确定 F 的值的最小移动次数是多少? -  + 示例 1: @@ -32,7 +32,7 @@ 输入:K = 3, N = 14 输出:4 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" "b/src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" index a79d0988..b8736ae4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" @@ -3,18 +3,18 @@ import org.junit.Test; /* -给定一个非负整数数组 A,返回一个数组,在该数组中, A 的所有偶数元素之后跟着所有奇数元素。 +给定一个非负整数数组 A,返回一个数组,在该数组中, A 的所有偶数元素之后跟着所有奇数元素。 你可以返回满足此条件的任何数组作为答案。 -  + 示例: 输入:[3,1,2,4] 输出:[2,4,3,1] 输出 [4,2,3,1],[2,4,1,3] 和 [4,2,1,3] 也会被接受。 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" "b/src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" index f52c15f7..fa1bfbe0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" @@ -1,20 +1,20 @@ package algorithm_practice.LeetCode.code900; /* -给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数。 +给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数。 -对数组进行排序,以便当 A[i] 为奇数时,i 也是奇数;当 A[i] 为偶数时, i 也是偶数。 +对数组进行排序,以便当 A[i] 为奇数时,i 也是奇数;当 A[i] 为偶数时, i 也是偶数。 你可以返回任何满足上述条件的数组作为答案。 -  + 示例: 输入:[4,2,5,7] 输出:[4,5,2,7] 解释:[4,7,2,5],[2,5,4,7],[2,7,4,5] 也会被接受。 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" "b/src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" index 7270e390..ee22c0e7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" @@ -14,7 +14,7 @@ 每一个无障碍方格都要通过一次,但是一条路径中不能重复通过同一个方格。 -  + 示例 1: @@ -39,7 +39,7 @@ 解释: 没有一条路能完全穿过每一个空的方格一次。 请注意,起始和结束方格可以位于网格中的任意位置。 -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" "b/src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" index 4abe034e..46359c9f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" @@ -4,9 +4,9 @@ import org.junit.Test; /* -给你一个整数数组 nums,请你将该数组升序排列。 +给你一个整数数组 nums,请你将该数组升序排列。 -  + 示例 1: @@ -16,7 +16,7 @@ 输入:nums = [5,1,1,2,0,0] 输出:[0,0,1,1,2,5] -  + 提示: diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" "b/src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" index 039a6830..877c0203 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" @@ -6,9 +6,9 @@ import java.util.Arrays; /* -给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1。 +给定整数数组 A,每次 move 操作将会选择任意 A[i],并将其递增 1。 -返回使 A 中的每个值都是唯一的最少操作次数。 +返回使 A 中的每个值都是唯一的最少操作次数。 示例 1: diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" "b/src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" index da5589f4..478f2061 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" @@ -16,7 +16,7 @@ 你可以按任何顺序返回答案。除了点坐标的顺序之外,答案确保是唯一的。 -  + 示例 1: @@ -32,7 +32,7 @@ 输入:points = [[3,3],[5,-1],[-2,4]], K = 2 输出:[[3,3],[-2,4]] (答案 [[-2,4],[3,3]] 也会被接受。) -  + 提示: diff --git a/src/main/java/common/datastruct/TreeNode.java b/src/main/java/common/datastruct/TreeNode.java index 22ac5427..10072fa5 100644 --- a/src/main/java/common/datastruct/TreeNode.java +++ b/src/main/java/common/datastruct/TreeNode.java @@ -12,6 +12,10 @@ public TreeNode(Integer val) { this.val = val; } + public TreeNode(String val) { + this.val = Integer.valueOf(val); + } + public TreeNode(Integer val, TreeNode left, TreeNode right) { this.val = val; this.left = left; diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java index 2d8f1270..17911914 100644 --- a/src/main/java/common/util/CompareUtils.java +++ b/src/main/java/common/util/CompareUtils.java @@ -1,12 +1,30 @@ package common.util; import common.datastruct.ListNode; +import common.datastruct.TreeNode; /** * Created by nibnait on 2022/04/11 */ public class CompareUtils { + /** + * 正序排列 + */ + public static boolean isSortAsc(int[] arr) { + if (arr == null || arr.length < 2) { + return true; + } + + for (int i = 0; i < arr.length - 1; i++) { + if (arr[i] > arr[i + 1]) { + return false; + } + } + + return true; + } + /** * 对比两个链表 */ @@ -34,20 +52,35 @@ public static boolean compareDoubleListNode(ListNode left, ListNode right) { } /** - * 正序排列 + * 对比两棵二叉树 */ - public static boolean isSortAsc(int[] arr) { - if (arr == null || arr.length < 2) { + public static boolean isSameValueStructure(TreeNode head1, TreeNode head2) { + if (head1 == null && head2 != null) { + return false; + } + if (head1 != null && head2 == null) { + return false; + } + if (head1 == null && head2 == null) { return true; } - - for (int i = 0; i < arr.length - 1; i++) { - if (arr[i] > arr[i + 1]) { - return false; - } + if (head1.val != head2.val) { + return false; } + return isSameValueStructure(head1.left, head2.left) && isSameValueStructure(head1.right, head2.right); + } - return true; + /** + * 三目最大值 + */ + public static int max(int a, int b, int c) { + return Math.max(a, Math.max(b, c)); } + /** + * 三目最小值 + */ + public static int min(int a, int b, int c) { + return Math.min(a, Math.min(b, c)); + } } diff --git a/src/main/java/common/util/ConstructBinaryTree.java b/src/main/java/common/util/ConstructBinaryTree.java index 387fc1b1..a12595e1 100644 --- a/src/main/java/common/util/ConstructBinaryTree.java +++ b/src/main/java/common/util/ConstructBinaryTree.java @@ -3,11 +3,12 @@ import common.datastruct.TreeNode; import org.junit.Test; +import java.util.ArrayList; import java.util.LinkedList; -/* - 构造二叉树 - Created by nibnait on 2019-07-17 +/** + * 构造二叉树 + * Created by nibnait on 2019-07-17 */ public class ConstructBinaryTree { @@ -34,6 +35,9 @@ private static TreeNode constructByPreOrderArray(Integer[] preOrderArray, int st return head; } + /** + * 根据按层遍历的数组,生成一棵二叉树 + */ public static TreeNode constructByBFSArray(Integer[] bfsArray) { if (bfsArray == null || bfsArray.length == 0) { return null; @@ -65,6 +69,47 @@ public static TreeNode constructByBFSArray(Integer[] bfsArray) { return head; } + /** + * 生成一个随机树 + * @param maxLevel 指定最大的层数 + * @param maxValue 指定树里节点的最大值 + */ + public static TreeNode generateRandomBinaryTree(int maxLevel, int maxValue) { + return generate(1, maxLevel, maxValue); + } + + private static TreeNode generate(int level, int maxLevel, int maxValue) { + if (level > maxLevel || Math.random() < 0.5) { + return null; + } + TreeNode head = new TreeNode((int) (Math.random() * maxValue)); + head.left = generate(level + 1, maxLevel, maxValue); + head.right = generate(level + 1, maxLevel, maxValue); + return head; + } + + /** + * 随机 pick 树中的一个节点 + */ + public static TreeNode pickRandomOne(TreeNode head) { + if (head == null) { + return null; + } + ArrayList arr = new ArrayList<>(); + fillPrelist(head, arr); + int randomIndex = (int) (Math.random() * arr.size()); + return arr.get(randomIndex); + } + + private static void fillPrelist(TreeNode head, ArrayList arr) { + if (head == null) { + return; + } + arr.add(head); + fillPrelist(head.left, arr); + fillPrelist(head.right, arr); + } + @Test public void testCase() { Integer[] preOrderArray1 = {1, null, 2, 3}; diff --git a/src/main/java/common/util/PrintBinaryTree.java b/src/main/java/common/util/PrintBinaryTree.java index f6c11644..e06657be 100644 --- a/src/main/java/common/util/PrintBinaryTree.java +++ b/src/main/java/common/util/PrintBinaryTree.java @@ -6,7 +6,7 @@ /** * 打印二叉树 - * + *

* Created by nibnait on 2016/9/15. */ public class PrintBinaryTree { @@ -15,7 +15,7 @@ public class PrintBinaryTree { /** * ‘*’ 代表根结点 - * ‘~’ 代表左子结点 + * ‘^’ 代表左子结点 * ‘_’ 代表右子结点 * * @param head 树的根结点 @@ -28,17 +28,17 @@ public static void print(BinaryTreeNode head) { } private static void printInOrder(BinaryTreeNode head, int height, String to) { - if (head == null){ + if (head == null) { return; } - printInOrder(head.left, height+1, "~"); + printInOrder(head.left, height + 1, "^"); String val = to + head.value + to; int lenM = val.length(); int lenL = (NODE_LENGTH - lenM) / 2; int lenR = NODE_LENGTH - lenL - lenM; - val = getSpace(height*NODE_LENGTH + lenL) + val + getSpace(lenR); + val = getSpace(height * NODE_LENGTH + lenL) + val + getSpace(lenR); System.out.println(val); - printInOrder(head.right, height+1, "_"); + printInOrder(head.right, height + 1, "_"); } public static void print(TreeNode head) { @@ -48,19 +48,19 @@ public static void print(TreeNode head) { } private static void printInOrder(TreeNode head, int height, String to) { - if (head == null){ + if (head == null) { return; } - printInOrder(head.left, height+1, "~"); + printInOrder(head.left, height + 1, "^"); String val = to + head.val + to; int lenM = val.length(); int lenL = (NODE_LENGTH - lenM) / 2; int lenR = NODE_LENGTH - lenL - lenM; - val = getSpace(height*NODE_LENGTH + lenL) + val + getSpace(lenR); - if (!val.contains("null")){ + val = getSpace(height * NODE_LENGTH + lenL) + val + getSpace(lenR); + if (!val.contains("null")) { System.out.println(val); } - printInOrder(head.right, height+1, "_"); + printInOrder(head.right, height + 1, "_"); } private static String getSpace(int n) { @@ -71,6 +71,15 @@ private static String getSpace(int n) { return sb.toString(); } + public static void printPreOrder(TreeNode head) { + if (head == null) { + return; + } + System.out.print(head.val + ", "); + printPreOrder(head.left); + printPreOrder(head.right); + } + public static void main(String[] args) { BinaryTreeNode head = new BinaryTreeNode(1); head.left = new BinaryTreeNode(-222222222); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" similarity index 100% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_summary.md" rename to "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" index b73fccd7..4c82557e 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" @@ -20,9 +20,45 @@ public void loopTestCase() { @Test public void testCase() { + // 1->2->3->4->5->6->7->null + ListNode head1 = new ListNode(1); + head1.next = new ListNode(2); + head1.next.next = new ListNode(3); + head1.next.next.next = new ListNode(4); + head1.next.next.next.next = new ListNode(5); + head1.next.next.next.next.next = new ListNode(6); + head1.next.next.next.next.next.next = new ListNode(7); + // 0->9->8->6->7->null + ListNode head2 = new ListNode(0); + head2.next = new ListNode(9); + head2.next.next = new ListNode(8); + head2.next.next.next = head1.next.next.next.next.next; // 8->6 + System.out.println(getIntersectListNode(head1, head2).val); + // 1->2->3->4->5->6->7->4... + head1 = new ListNode(1); + head1.next = new ListNode(2); + head1.next.next = new ListNode(3); + head1.next.next.next = new ListNode(4); + head1.next.next.next.next = new ListNode(5); + head1.next.next.next.next.next = new ListNode(6); + head1.next.next.next.next.next.next = new ListNode(7); + head1.next.next.next.next.next.next = head1.next.next.next; // 7->4 + // 0->9->8->2... + head2 = new ListNode(0); + head2.next = new ListNode(9); + head2.next.next = new ListNode(8); + head2.next.next.next = head1.next; // 8->2 + System.out.println(getIntersectListNode(head1, head2).val); + + // 0->9->8->6->4->5->6.. + head2 = new ListNode(0); + head2.next = new ListNode(9); + head2.next.next = new ListNode(8); + head2.next.next.next = head1.next.next.next.next.next; // 8->6 + System.out.println(getIntersectListNode(head1, head2).val); } @@ -30,6 +66,8 @@ public void testCase() { * 给定两个可能有环也可能无环的单链表,头节点head1和head2 * 请实现一个函数,如果两个链表相交,请返回相交的第一个节点。如果不相交返回null * 要求如果两个链表长度之和为N,时间复杂度请达到O(N),额外空间复杂度请达到O(1) + * + * https://leetcode.cn/problems/3u1WK4/ */ private ListNode getIntersectListNode(ListNode head1, ListNode head2) { if (head1 == null || head2 == null) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" new file mode 100644 index 00000000..418f9b77 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" @@ -0,0 +1,111 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import com.google.common.collect.Lists; +import common.datastruct.TreeNode; +import common.util.PrintBinaryTree; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +/** + * Created by nibnait on 2022/10/27 + */ +@Slf4j +public class Code01_RecursiveTraversalBT { + + @Test + public void testCase() { + TreeNode head = new TreeNode(5); + head.left = new TreeNode(3); + head.right = new TreeNode(8); + head.left.left = new TreeNode(2); + head.left.right = new TreeNode(4); + head.left.left.left = new TreeNode(1); + head.right.left = new TreeNode(7); + head.right.left.left = new TreeNode(6); + head.right.right = new TreeNode(10); + head.right.right.left = new TreeNode(9); + head.right.right.right = new TreeNode(11); + + PrintBinaryTree.print(head); + + List preOrderArr = preOrderRecur(head); + List expectPreOrderArr = Lists.newArrayList(5, 3, 2, 1, 4, 8, 7, 6, 10, 9, 11); + Assert.assertTrue(CompareUtils.match(preOrderArr, expectPreOrderArr)); + + List inOrderArr = inOrderRecur(head); + List expectInOrderArr = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + Assert.assertTrue(CompareUtils.match(inOrderArr, expectInOrderArr)); + + List posOrderArr = posOrderRecur(head); + List expectPosOrderArr = Lists.newArrayList(1, 2, 4, 3, 6, 7, 9, 11, 10, 8, 5); + Assert.assertTrue(CompareUtils.match(posOrderArr, expectPosOrderArr)); + + } + + /** + * 先序 + */ + private List preOrderRecur(TreeNode head) { + List travelArr = Lists.newArrayList(); + if (head == null) { + return travelArr; + } + + processPreOrder(head, travelArr); + return travelArr; + } + + private void processPreOrder(TreeNode head, List travelArr) { + if (head == null) { + return; + } + + travelArr.add(head.val); + processPreOrder(head.left, travelArr); + processPreOrder(head.right, travelArr); + } + + private List inOrderRecur(TreeNode head) { + List travelArr = Lists.newArrayList(); + if (head == null) { + return travelArr; + } + + processInOrder(head, travelArr); + return travelArr; + } + + private void processInOrder(TreeNode head, List travelArr) { + if (head == null) { + return; + } + + processInOrder(head.left, travelArr); + travelArr.add(head.val); + processInOrder(head.right, travelArr); + } + + private List posOrderRecur(TreeNode head) { + List travelArr = Lists.newArrayList(); + if (head == null) { + return travelArr; + } + + processPosOrder(head, travelArr); + return travelArr; + } + + private void processPosOrder(TreeNode head, List travelArr) { + if (head == null) { + return; + } + + processPosOrder(head.left, travelArr); + processPosOrder(head.right, travelArr); + travelArr.add(head.val); + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" new file mode 100644 index 00000000..6bebb0e7 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" @@ -0,0 +1,117 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import com.google.common.collect.Lists; +import common.datastruct.TreeNode; +import common.util.PrintBinaryTree; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; +import java.util.Stack; + +/** + * Created by nibnait on 2022/10/27 + */ +@Slf4j +public class Code02_UnRecursiveTraversalBT { + + @Test + public void testCase() { + TreeNode head = new TreeNode(5); + head.left = new TreeNode(3); + head.right = new TreeNode(8); + head.left.left = new TreeNode(2); + head.left.right = new TreeNode(4); + head.left.left.left = new TreeNode(1); + head.right.left = new TreeNode(7); + head.right.left.left = new TreeNode(6); + head.right.right = new TreeNode(10); + head.right.right.left = new TreeNode(9); + head.right.right.right = new TreeNode(11); + + PrintBinaryTree.print(head); + + List preOrderArr = preOrderUnRecur(head); + List expectPreOrderArr = Lists.newArrayList(5, 3, 2, 1, 4, 8, 7, 6, 10, 9, 11); + Assert.assertTrue(CompareUtils.match(preOrderArr, expectPreOrderArr)); + + List inOrderArr = inOrderUnRecur(head); + List expectInOrderArr = Lists.newArrayList(1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11); + Assert.assertTrue(CompareUtils.match(inOrderArr, expectInOrderArr)); + + List posOrderArr = posOrderUnRecur(head); + List expectPosOrderArr = Lists.newArrayList(1, 2, 4, 3, 6, 7, 9, 11, 10, 8, 5); + Assert.assertTrue(CompareUtils.match(posOrderArr, expectPosOrderArr)); + + } + + private List preOrderUnRecur(TreeNode head) { + List travelArr = Lists.newArrayList(); + if (head == null) { + return travelArr; + } + + Stack stack = new Stack<>(); + travelArr.add(head.val); + stack.push(head.right); + stack.push(head.left); + + while (!stack.isEmpty()) { + head = stack.pop(); + if (head == null) { + continue; + } + travelArr.add(head.val); + stack.push(head.right); + stack.push(head.left); + } + + return travelArr; + } + + /** + * 所有的左子树,组成了这一棵二叉树 + */ + private List inOrderUnRecur(TreeNode head) { + List travelArr = Lists.newArrayList(); + if (head == null) { + return travelArr; + } + + Stack stack = new Stack<>(); + while (head != null) { + stack.push(head); + head = head.left; + } + + while (!stack.isEmpty()) { + head = stack.pop(); + travelArr.add(head.val); + if (head.right != null) { + head = head.right; + + while (head != null) { + stack.push(head); + head = head.left; + } + } + + } + return travelArr; + } + + private List posOrderUnRecur(TreeNode head) { + List travelArr = Lists.newArrayList(); + if (head == null) { + return travelArr; + } + + + + + return travelArr; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" new file mode 100644 index 00000000..de00cfb8 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" @@ -0,0 +1,67 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import com.google.common.collect.Lists; +import common.datastruct.TreeNode; +import common.util.PrintBinaryTree; +import io.github.nibnait.common.utils.compare.CompareUtils; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +/** + * Created by nibnait on 2022/10/27 + */ +@Slf4j +public class Code03_LevelTraversalBT { + + @Test + public void testCase() { + TreeNode head = new TreeNode(5); + head.left = new TreeNode(3); + head.right = new TreeNode(8); + head.left.left = new TreeNode(2); + head.left.right = new TreeNode(4); + head.left.left.left = new TreeNode(1); + head.right.left = new TreeNode(7); + head.right.left.left = new TreeNode(6); + head.right.right = new TreeNode(10); + head.right.right.left = new TreeNode(9); + head.right.right.right = new TreeNode(11); + + PrintBinaryTree.print(head); + + List levelOrderArr = levelTravel(head); + List expectOrderArr = Lists.newArrayList(5, 3, 8, 2, 4, 7, 10, 1, 6, 9, 11); + Assert.assertTrue(CompareUtils.match(levelOrderArr, expectOrderArr)); + } + + private List levelTravel(TreeNode head) { + List travelArr = new ArrayList<>(); + if (head == null) { + return travelArr; + } + + Queue queue = new LinkedList<>(); + queue.offer(head); + + while (!queue.isEmpty()) { + head = queue.poll(); + travelArr.add(head.val); + + if (head.left != null) { + queue.offer(head.left); + } + if (head.right != null) { + queue.offer(head.right); + } + } + + return travelArr; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" new file mode 100644 index 00000000..9def42e8 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" @@ -0,0 +1,24 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import common.datastruct.TreeNode; + +import java.util.Queue; + +/** + * Created by nibnait on 2022/10/27 + */ +public interface Code04_SerializeAndReconstructTree { + + Queue preSerial(TreeNode head); + + Queue posSerial(TreeNode head); + + Queue levelSerial(TreeNode head); + + TreeNode buildByPreQueue(Queue pre); + + TreeNode buildByPosQueue(Queue pos); + + TreeNode buildByLevelQueue(Queue level); + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" new file mode 100644 index 00000000..6015b9f5 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" @@ -0,0 +1,192 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.*; +import lombok.extern.slf4j.Slf4j; +import org.junit.Assert; +import org.junit.Test; + +import java.util.LinkedList; +import java.util.Queue; +import java.util.Stack; + +/** + * Created by nibnait on 2022/10/27 + */ +@Slf4j +public class Code04_SerializeAndReconstructTreeImpl implements Code04_SerializeAndReconstructTree { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); + PrintBinaryTree.print(head); + SysOut.printSeparator(); + + Queue pre = preSerial(head); + Queue pos = posSerial(head); + Queue level = levelSerial(head); + TreeNode preBuild = buildByPreQueue(pre); + TreeNode posBuild = buildByPosQueue(pos); + TreeNode levelBuild = buildByLevelQueue(level); + + Assert.assertTrue(CompareUtils.isSameValueStructure(head, preBuild)); + Assert.assertTrue(CompareUtils.isSameValueStructure(preBuild, posBuild)); + Assert.assertTrue(CompareUtils.isSameValueStructure(posBuild, levelBuild)); + } + + private static final String NULL_HEAD = "#"; + + @Override + public Queue preSerial(TreeNode head) { + Queue travelArr = new LinkedList<>(); + if (head == null) { + return travelArr; + } + + processPreSerial(head, travelArr); + return travelArr; + } + + private void processPreSerial(TreeNode head, Queue travelArr) { + if (head == null) { + travelArr.add(NULL_HEAD); + } else { + travelArr.add(String.valueOf(head.val)); + processPreSerial(head.left, travelArr); + processPreSerial(head.right, travelArr); + } + } + + @Override + public Queue posSerial(TreeNode head) { + Queue travelArr = new LinkedList<>(); + if (head == null) { + return travelArr; + } + processPosSerial(head, travelArr); + return travelArr; + } + + private void processPosSerial(TreeNode head, Queue travelArr) { + if (head == null) { + travelArr.add(NULL_HEAD); + } else { + processPosSerial(head.left, travelArr); + processPosSerial(head.right, travelArr); + travelArr.add(String.valueOf(head.val)); + } + } + + @Override + public Queue levelSerial(TreeNode head) { + Queue travelArr = new LinkedList<>(); + if (head == null) { + travelArr.add(NULL_HEAD); + } else { + travelArr.add(String.valueOf(head.val)); + Queue queue = new LinkedList<>(); + travelArr.add(String.valueOf(head.val)); + queue.add(head); + while (!queue.isEmpty()) { + if (head.left != null) { + queue.add(head.left); + travelArr.add(String.valueOf(head.left.val)); + } else { + travelArr.add(NULL_HEAD); + } + + if (head.right != null) { + queue.add(head.right); + travelArr.add(String.valueOf(head.right.val)); + } else { + travelArr.add(NULL_HEAD); + } + } + } + return travelArr; + } + + @Override + public TreeNode buildByPreQueue(Queue pre) { + if (pre == null || pre.isEmpty()) { + return null; + } + return processBuildByPreQueue(pre); + } + + private TreeNode processBuildByPreQueue(Queue pre) { + String headVal = pre.poll(); + if (NULL_HEAD.equals(headVal)) { + return null; + } + TreeNode head = new TreeNode(headVal); + head.left = processBuildByPreQueue(pre); + head.right = processBuildByPreQueue(pre); + return head; + } + + @Override + public TreeNode buildByPosQueue(Queue pos) { + if (pos == null || pos.isEmpty()) { + return null; + } + + // 左右中 -> 中右左 + Stack stack = new Stack(); + while (!pos.isEmpty()) { + stack.push(pos.poll()); + } + return processBuildByPosQueue(stack); + } + + private TreeNode processBuildByPosQueue(Stack stack) { + String headVal = stack.pop(); + TreeNode head = new TreeNode(headVal); + head.right = processBuildByPosQueue(stack); + head.left = processBuildByPosQueue(stack); + return head; + } + + @Override + public TreeNode buildByLevelQueue(Queue level) { + if (level == null || level.isEmpty()) { + return null; + } + TreeNode head = generateNode(level.poll()); + Queue queue = new LinkedList<>(); + if (head != null) { + queue.add(head); + } + while (!queue.isEmpty()) { + head = queue.poll(); + head.left = generateNode(level.poll()); + head.right = generateNode(level.poll()); + if (head.left != null) { + queue.add(head.left); + } + if (head.right != null) { + queue.add(head.right); + } + } + return head; + } + + private TreeNode generateNode(String headVal) { + if (headVal == null || NULL_HEAD.equals(headVal)) { + return null; + } + return new TreeNode(headVal); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code05_EncodeNaryTreeToBinaryTree.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code05_EncodeNaryTreeToBinaryTree.java" new file mode 100644 index 00000000..a1ab4eef --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code05_EncodeNaryTreeToBinaryTree.java" @@ -0,0 +1,19 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import org.junit.Test; + +/** + * Created by nibnait on 2022/10/27 + */ +public class Code05_EncodeNaryTreeToBinaryTree { + + @Test + public void test() { + + } + + /** + * N叉树如何通过二叉树来序列化、并完成反序列化 + * https://leetcode.com/problems/encode-n-ary-tree-to-binary-tree + */ +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" new file mode 100644 index 00000000..dcae9514 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" @@ -0,0 +1,85 @@ +package algorithmzuo.b_体系学习班.c0203_树; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.PrintBinaryTree; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.LinkedList; +import java.util.Queue; + +/** + * Created by nibnait on 2022/10/30 + */ +public class Code06_TreeMaxWidth { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 10); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); + PrintBinaryTree.print(head); + SysOut.printSeparator(); + + int result = maxWidth(head); + + Assert.assertEquals(comparator(head), result); + + } + + /** + * 求二叉树的最大宽度 + */ + private int maxWidth(TreeNode head) { + return 0; + } + + //-------------------------- 对数器 --------------------------// + private int comparator(TreeNode head) { + if (head == null) { + return 0; + } + Queue queue = new LinkedList<>(); + queue.add(head); + // key 在 哪一层,value + HashMap levelMap = new HashMap<>(); + levelMap.put(head, 1); + int curLevel = 1; // 当前你正在统计哪一层的宽度 + int curLevelNodes = 0; // 当前层curLevel层,宽度目前是多少 + int max = 0; + while (!queue.isEmpty()) { + TreeNode cur = queue.poll(); + int curNodeLevel = levelMap.get(cur); + if (cur.left != null) { + levelMap.put(cur.left, curNodeLevel + 1); + queue.add(cur.left); + } + if (cur.right != null) { + levelMap.put(cur.right, curNodeLevel + 1); + queue.add(cur.right); + } + if (curNodeLevel == curLevel) { + curLevelNodes++; + } else { + max = Math.max(max, curLevelNodes); + curLevel++; + curLevelNodes = 1; + } + } + max = Math.max(max, curLevelNodes); + return max; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" new file mode 100644 index 00000000..800b7134 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" @@ -0,0 +1,85 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +public class Code01_IsBalanced { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(0, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); +// PrintBinaryTree.print(head); +// PrintBinaryTree.printPreOrder(head); + + boolean result = isBalanced(head); + + Assert.assertEquals(comparator(head), result); + } + + /** + * 判断二叉树是不是平衡二叉树 + * 即:任何一棵子树的 | 左高度 - 右高度 | <= 1 + */ + private boolean isBalanced(TreeNode head) { + if (head == null) { + return true; + } + + return process(head).isBalance; + } + + private Info process(TreeNode head) { + if (head == null) { + return new Info(0, true); + } + + Info left = process(head.left); + Info right = process(head.right); + + int height = Math.max(left.height, right.height) + 1; + boolean isBalance = left.isBalance && right.isBalance && Math.abs(left.height - right.height) <= 1; + return new Info(height, isBalance); + } + + @AllArgsConstructor + private class Info { + public int height; + public boolean isBalance; + } + + //-------------------------- 对数器 --------------------------// + private boolean comparator(TreeNode head) { + boolean[] ans = new boolean[1]; + ans[0] = true; + process1(head, ans); + return ans[0]; + } + + private int process1(TreeNode head, boolean[] ans) { + if (!ans[0] || head == null) { + return -1; + } + int leftHeight = process1(head.left, ans); + int rightHeight = process1(head.right, ans); + if (Math.abs(leftHeight - rightHeight) > 1) { + ans[0] = false; + } + return Math.max(leftHeight, rightHeight) + 1; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" new file mode 100644 index 00000000..34bc6c95 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" @@ -0,0 +1,110 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.*; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +/** + * Created by nibnait on 2022/10/28 + */ +public class Code02_IsBST { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); +// PrintBinaryTree.print(head); +// SysOut.printSeparator(); + + boolean result = isBST(head); + + Assert.assertEquals(comparator(head), result); + } + + /** + * 判断二叉树是不是搜索二叉树(整棵树无重复节点) + * 即:任何一棵子树。都是搜索二叉树 + */ + private boolean isBST(TreeNode head) { + if (head == null) { + return true; + } + return process(head).isBST; + } + + private Info process(TreeNode head) { + if (head == null) { + return null; + } + + Info left = process(head.left); + Info right = process(head.right); + + int max = CompareUtils.max(head.val, + left != null ? left.max : Integer.MIN_VALUE, + right != null ? right.max : Integer.MIN_VALUE); + int min = CompareUtils.min(head.val, + left != null ? left.min : Integer.MAX_VALUE, + right != null ? right.min : Integer.MAX_VALUE); + + boolean isBST = true; + if (left != null && !left.isBST) { + isBST = false; + } + if (right != null && !right.isBST) { + isBST = false; + } + if (left != null && left.max >= head.val) { + isBST = false; + } + if (right != null && right.min <= head.val) { + isBST = false; + } + return new Info(max, min, isBST); + } + + @AllArgsConstructor + private class Info { + public int max; + public int min; + public boolean isBST; + } + + //-------------------------- 对数器 --------------------------// + private boolean comparator(TreeNode head) { + if (head == null) { + return true; + } + ArrayList arr = new ArrayList<>(); + in(head, arr); + for (int i = 1; i < arr.size(); i++) { + if (arr.get(i).val <= arr.get(i - 1).val) { + return false; + } + } + return true; + } + + public static void in(TreeNode head, ArrayList arr) { + if (head == null) { + return; + } + in(head.left, arr); + arr.add(head); + in(head.right, arr); + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" new file mode 100644 index 00000000..293bfa36 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" @@ -0,0 +1,131 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.*; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashMap; +import java.util.HashSet; + +/** + * Created by nibnait on 2022/10/29 + */ +public class Code03_MaxDistance { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); + PrintBinaryTree.print(head); + SysOut.printSeparator(); + + int result = maxDistance(head); + + Assert.assertEquals(comparator(head), result); + } + + /** + * 给定一棵二叉树的头节点head,任何两个节点之间都存在距离,返回整棵二叉树的最大距离 + */ + private int maxDistance(TreeNode head) { + if (head == null) { + return 0; + } + return 0; + } + + @AllArgsConstructor + private class Info { + + } + + //-------------------------- 对数器 --------------------------// + private int comparator(TreeNode head) { + if (head == null) { + return 0; + } + ArrayList arr = getPrelist(head); + HashMap parentMap = getParentMap(head); + int max = 0; + for (int i = 0; i < arr.size(); i++) { + for (int j = i; j < arr.size(); j++) { + max = Math.max(max, distance(parentMap, arr.get(i), arr.get(j))); + } + } + return max; + } + + public static ArrayList getPrelist(TreeNode head) { + ArrayList arr = new ArrayList<>(); + fillPrelist(head, arr); + return arr; + } + + public static void fillPrelist(TreeNode head, ArrayList arr) { + if (head == null) { + return; + } + arr.add(head); + fillPrelist(head.left, arr); + fillPrelist(head.right, arr); + } + + public static HashMap getParentMap(TreeNode head) { + HashMap map = new HashMap<>(); + map.put(head, null); + fillParentMap(head, map); + return map; + } + + public static void fillParentMap(TreeNode head, HashMap parentMap) { + if (head.left != null) { + parentMap.put(head.left, head); + fillParentMap(head.left, parentMap); + } + if (head.right != null) { + parentMap.put(head.right, head); + fillParentMap(head.right, parentMap); + } + } + + public static int distance(HashMap parentMap, TreeNode o1, TreeNode o2) { + HashSet o1Set = new HashSet<>(); + TreeNode cur = o1; + o1Set.add(cur); + while (parentMap.get(cur) != null) { + cur = parentMap.get(cur); + o1Set.add(cur); + } + cur = o2; + while (!o1Set.contains(cur)) { + cur = parentMap.get(cur); + } + TreeNode lowestAncestor = cur; + cur = o1; + int distance1 = 1; + while (cur != lowestAncestor) { + cur = parentMap.get(cur); + distance1++; + } + cur = o2; + int distance2 = 1; + while (cur != lowestAncestor) { + cur = parentMap.get(cur); + distance2++; + } + return distance1 + distance2 - 1; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" new file mode 100644 index 00000000..e3b4c31a --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" @@ -0,0 +1,95 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.PrintBinaryTree; +import common.util.SysOut; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/10/29 + */ +public class Code04_IsFull { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); + PrintBinaryTree.print(head); + SysOut.printSeparator(); + + Assert.assertEquals(isFull1(head), isFull2(head)); + } + + /** + * 判断二叉树是不是满二叉树 + */ + private boolean isFull1(TreeNode head) { + if (head == null) { + return true; + } + return process1(head).isFull; + } + + private Info1 process1(TreeNode head) { + if (head == null) { + return new Info1(true, 0); + } + + Info1 left = process1(head.left); + Info1 right = process1(head.right); + + boolean isFull = left.isFull && right.isFull && left.height == right.height; + int height = Math.max(left.height, right.height) + 1; + + return new Info1(isFull, height); + } + + @AllArgsConstructor + private class Info1 { + public boolean isFull; + public int height; + } + + /** + * 法2: 只有满二叉树满足 : 2 ^ h - 1 == n + */ + private boolean isFull2(TreeNode head) { + if (head == null) { + return true; + } + Info2 headInfo = process2(head); + return headInfo.size == Math.pow(2, headInfo.height) - 1; + } + + private Info2 process2(TreeNode head) { + if (head == null) { + return new Info2(0, 0); + } + Info2 left = process2(head.left); + Info2 right = process2(head.right); + + int size = left.size + right.size + 1; + int height = Math.max(left.height, right.height) + 1; + return new Info2(size, height); + } + + @AllArgsConstructor + private class Info2 { + public int size; + public int height; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" new file mode 100644 index 00000000..98b9bbf5 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" @@ -0,0 +1,87 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Test; + +import java.util.ArrayList; + +/** + * Created by nibnait on 2022/10/29 + */ +public class Code05_MaxSubBSTSize { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); +// PrintBinaryTree.print(head); +// SysOut.printSeparator(); + + int result = maxSubBSTSize(head); + +// Assert.assertEquals(result, maxSubBSTSize1(head)); + } + + /** + * 给定一棵二叉树的头节点head,返回这颗二叉树中最大的二叉搜索子树的大小 + */ + private int maxSubBSTSize(TreeNode head) { + if (head == null) { + return 0; + } + return 1; + } + + + @AllArgsConstructor + private class Info { + } + + //-------------------------- 对数器 --------------------------// + private int maxSubBSTSize1(TreeNode head) { + if (head == null) { + return 0; + } + int h = getBSTSize(head); + if (h != 0) { + return h; + } + return Math.max(maxSubBSTSize1(head.left), maxSubBSTSize1(head.right)); + } + + public static int getBSTSize(TreeNode head) { + if (head == null) { + return 0; + } + ArrayList arr = new ArrayList<>(); + in(head, arr); + for (int i = 1; i < arr.size(); i++) { + if (arr.get(i).val <= arr.get(i - 1).val) { + return 0; + } + } + return arr.size(); + } + + public static void in(TreeNode head, ArrayList arr) { + if (head == null) { + return; + } + in(head.left, arr); + arr.add(head); + in(head.right, arr); + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" new file mode 100644 index 00000000..71aae475 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" @@ -0,0 +1,90 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Test; + +import java.util.LinkedList; + +/** + * Created by nibnait on 2022/10/29 + */ +public class Code06_IsCBT { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); +// PrintBinaryTree.print(head); +// SysOut.printSeparator(); + + boolean result = isCBT(head); +// Assert.assertEquals(comparator(head), result); + } + + /** + * 判断二叉树是不是完全二叉树 + * 每棵子树,都有左右孩子。 + */ + private boolean isCBT(TreeNode head) { + if (head == null) { + return true; + } + return true; + } + + @AllArgsConstructor + private class Info { + + } + + + //-------------------------- 对数器 --------------------------// + private boolean comparator(TreeNode head) { + if (head == null) { + return true; + } + LinkedList queue = new LinkedList<>(); + // 是否遇到过左右两个孩子不双全的节点 + boolean leaf = false; + TreeNode l = null; + TreeNode r = null; + queue.add(head); + while (!queue.isEmpty()) { + head = queue.poll(); + l = head.left; + r = head.right; + if ( + // 如果遇到了不双全的节点之后,又发现当前节点不是叶节点 + (leaf && (l != null || r != null)) + || + (l == null && r != null) + + ) { + return false; + } + if (l != null) { + queue.add(l); + } + if (r != null) { + queue.add(r); + } + if (l == null || r == null) { + leaf = true; + } + } + return true; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" new file mode 100644 index 00000000..66b4fea1 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" @@ -0,0 +1,91 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.PrintBinaryTree; +import common.util.SysOut; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; + +/** + * Created by nibnait on 2022/10/31 + */ +public class Code07_MaxSubBSTHead { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); + PrintBinaryTree.print(head); + SysOut.printSeparator(); + + TreeNode result = maxSubBSTHead(head); + + Assert.assertEquals(result, maxSubBSTHead1(head)); + } + + /** + * 给定一棵二叉树的头节点head,返回这颗二叉树中最大的二叉搜索子树的头节点 + */ + private TreeNode maxSubBSTHead(TreeNode head) { + if (head == null) { + return null; + } + return null; + } + + + @AllArgsConstructor + private class Info { + } + + //-------------------------- 对数器 --------------------------// + private TreeNode maxSubBSTHead1(TreeNode head) { + if (head == null) { + return null; + } + if (getBSTSize(head) != 0) { + return head; + } + TreeNode leftAns = maxSubBSTHead1(head.left); + TreeNode rightAns = maxSubBSTHead1(head.right); + return getBSTSize(leftAns) >= getBSTSize(rightAns) ? leftAns : rightAns; + } + + public static int getBSTSize(TreeNode head) { + if (head == null) { + return 0; + } + ArrayList arr = new ArrayList<>(); + in(head, arr); + for (int i = 1; i < arr.size(); i++) { + if (arr.get(i).val <= arr.get(i - 1).val) { + return 0; + } + } + return arr.size(); + } + + public static void in(TreeNode head, ArrayList arr) { + if (head == null) { + return; + } + in(head.left, arr); + arr.add(head); + in(head.right, arr); + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" new file mode 100644 index 00000000..d7006f98 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" @@ -0,0 +1,93 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import common.util.ConstructBinaryTree; +import common.util.PrintBinaryTree; +import common.util.SysOut; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.HashSet; + +/** + * Created by nibnait on 2022/10/31 + */ +public class Code08_lowestAncestor { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = SysRandom.randomInt(1, 6); + int maxValue = SysRandom.random(100); + + TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); + TreeNode o1 = ConstructBinaryTree.pickRandomOne(head); + TreeNode o2 = ConstructBinaryTree.pickRandomOne(head); + PrintBinaryTree.print(head); + SysOut.printSeparator(); + + TreeNode result = lowestAncestor(head, o1, o2); + Assert.assertEquals(comparator(head, o1, o2), result); + } + + /** + * 给定一棵二叉树的头节点head,和另外两个节点a和b,返回a和b的最低公共祖先 + */ + private TreeNode lowestAncestor(TreeNode head, TreeNode o1, TreeNode o2) { + if (head == null) { + return null; + } + return null; + } + + @AllArgsConstructor + private class Info { + + } + + + //-------------------------- 对数器 --------------------------// + private TreeNode comparator(TreeNode head, TreeNode o1, TreeNode o2) { + if (head == null) { + return null; + } + // key的父节点是value + HashMap parentMap = new HashMap<>(); + parentMap.put(head, null); + fillParentMap(head, parentMap); + HashSet o1Set = new HashSet<>(); + TreeNode cur = o1; + o1Set.add(cur); + while (parentMap.get(cur) != null) { + cur = parentMap.get(cur); + o1Set.add(cur); + } + cur = o2; + while (!o1Set.contains(cur)) { + cur = parentMap.get(cur); + } + return cur; + } + + + public void fillParentMap(TreeNode head, HashMap parentMap) { + if (head.left != null) { + parentMap.put(head.left, head); + fillParentMap(head.left, parentMap); + } + if (head.right != null) { + parentMap.put(head.right, head); + fillParentMap(head.right, parentMap); + } + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" new file mode 100644 index 00000000..e4dc980a --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" @@ -0,0 +1,110 @@ +package algorithmzuo.b_体系学习班.c0204_树型DP; + +import common.CommonConstants; +import common.datastruct.TreeNode; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by nibnait on 2022/10/31 + */ +public class Code09_MaxHappy { + + private static class Employee { + public int happy; + public List nexts; + + public Employee(int h) { + happy = h; + nexts = new ArrayList<>(); + } + } + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLevel = 4; + int maxNexts = 7; + int maxHappy = 100; + int testTimes = 100000; + + Employee boss = genarateBoss(maxLevel, maxNexts, maxHappy); + + TreeNode result = maxHappy(boss); + + Assert.assertEquals(result, maxHappy1(boss)); + } + + private TreeNode maxHappy(Employee boss) { + return null; + } + + @AllArgsConstructor + private class Info { + + } + + //-------------------------- 对数器 --------------------------// + private int maxHappy1(Employee boss) { + if (boss == null) { + return 0; + } + return process1(boss, false); + } + + // 当前来到的节点叫cur, + // up表示cur的上级是否来, + // 该函数含义: + // 如果up为true,表示在cur上级已经确定来,的情况下,cur整棵树能够提供最大的快乐值是多少? + // 如果up为false,表示在cur上级已经确定不来,的情况下,cur整棵树能够提供最大的快乐值是多少? + public static int process1(Employee cur, boolean up) { + if (up) { // 如果cur的上级来的话,cur没得选,只能不来 + int ans = 0; + for (Employee next : cur.nexts) { + ans += process1(next, false); + } + return ans; + } else { // 如果cur的上级不来的话,cur可以选,可以来也可以不来 + int p1 = cur.happy; + int p2 = 0; + for (Employee next : cur.nexts) { + p1 += process1(next, true); + p2 += process1(next, false); + } + return Math.max(p1, p2); + } + } + + // for test + public static Employee genarateBoss(int maxLevel, int maxNexts, int maxHappy) { + if (Math.random() < 0.02) { + return null; + } + Employee boss = new Employee((int) (Math.random() * (maxHappy + 1))); + genarateNexts(boss, 1, maxLevel, maxNexts, maxHappy); + return boss; + } + + // for test + public static void genarateNexts(Employee e, int level, int maxLevel, int maxNexts, int maxHappy) { + if (level > maxLevel) { + return; + } + int nextsSize = (int) (Math.random() * (maxNexts + 1)); + for (int i = 0; i < nextsSize; i++) { + Employee next = new Employee((int) (Math.random() * (maxHappy + 1))); + e.nexts.add(next); + genarateNexts(next, level + 1, maxLevel, maxNexts, maxHappy); + } + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" deleted file mode 100644 index da290a0d..00000000 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_summary.md" +++ /dev/null @@ -1,5 +0,0 @@ -### 链表 三板斧 -双指针 - - -### 二叉树 \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" new file mode 100644 index 00000000..89933904 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" @@ -0,0 +1,36 @@ +## 链表 + +[链表专题](../../../../main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/README.md) + +## 二叉树 +[二叉树专题(一)](../../../../main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/README.md) +[二叉树专题(二)](../../../../main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/README.md) +[二叉树专题(三)](../../../../main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/README.md) + + - [Code01_先序、中序、后序遍历-递归](./c0203_树/Code01_RecursiveTraversalBT.java) + - [Code02_先序、中序、后序遍历-非递归](./c0203_树/Code02_UnRecursiveTraversalBT.java) + - [Code03_二叉树的按层遍历](./c0203_树/Code03_LevelTraversalBT.java) + - [Code04_二叉树的序列化和反序列化](./c0203_树/Code04_SerializeAndReconstructTree.java) + - [Code05_N叉树如何通过二叉树来序列化、并完成反序列化](./c0203_树/Code05_EncodeNaryTreeToBinaryTree.java) + - [Code06_求二叉树的最大宽度](./c0203_树/Code06_TreeMaxWidth.java) + +### 树型 DP 的通用套路 + + - [Code01_判断二叉树是不是平衡二叉树](./c0204_树型DP/Code01_IsBalanced.java) + - [Code02_判断二叉树是不是搜索二叉树](./c0204_树型DP/Code02_IsBST.java) + - ⭐️[Code03_给定一棵二叉树的头节点head,任何两个节点之间都存在距离,返回整棵二叉树的最大距离](./c0204_树型DP/Code03_MaxDistance.java) + - [Code04_判断二叉树是不是满二叉树](./c0204_树型DP/Code04_IsFull.java) + - ⭐️[Code05_给定一棵二叉树的头节点head,返回这颗二叉树中最大的二叉搜索子树的大小](./c0204_树型DP/Code05_MaxSubBSTSize.java) + - ⭐️[Code06_判断二叉树是不是完全二叉树](./c0204_树型DP/Code06_IsCBT.java) + - ️[Code07_给定一棵二叉树的头节点head,返回这颗二叉树中最大的二叉搜索子树的头节点](./c0204_树型DP/Code07_MaxSubBSTHead.java) + - ️[Code08_给定一棵二叉树的头节点head,和另外两个节点a和b,返回a和b的最低公共祖先](./c0204_树型DP/Code08_lowestAncestor.java) + - ️[Code09_派对的最大快乐值](./c0204_树型DP/Code09_MaxHappy.java) + + +**二叉树的递归套路** +1)假设以X节点为头,假设可以向X左树和X右树要任何信息 +2)在上一步的假设下,讨论以X为头节点的树,得到答案的可能性(最重要) +3)列出所有可能性后,确定到底需要向左树和右树要什么样的信息 +4)把左树信息和右树信息求全集,就是任何一棵子树都需要返回的信息S +5)递归函数都返回S,每一棵子树都这么要求 +6)写代码,在代码中考虑如何把左树的信息和右树信息整合出整棵树的信息 \ No newline at end of file From a485181107f655fa2fa816872b78604d28797f62 Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 2 Nov 2022 07:56:10 +0800 Subject: [PATCH 21/36] =?UTF-8?q?feat=20=E6=A0=91=E5=9E=8BDP=20=E8=BF=98?= =?UTF-8?q?=E5=BE=97=E7=BB=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\345\241\224\351\227\256\351\242\230.java" | 4 +- ...\345\272\217\351\201\215\345\216\206.java" | 2 +- ...\346\220\234\347\264\242\346\240\221.java" | 2 +- ...\344\272\214\345\217\211\346\240\221.java" | 2 +- ...\345\244\247\346\267\261\345\272\246.java" | 2 +- ...\344\272\214\345\217\211\346\240\221.java" | 2 +- ...\345\260\217\346\267\261\345\272\246.java" | 5 +- ...\350\267\257\345\276\204\345\222\214.java" | 2 +- ...\346\254\241\351\201\215\345\216\206.java" | 2 +- ...\345\272\217\351\201\215\345\216\206.java" | 2 +- ...\345\272\217\351\201\215\345\216\206.java" | 2 +- ...\345\217\263\350\247\206\345\233\276.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 4 +- ...\345\272\217\345\210\227\345\214\226.java" | 4 +- ...\347\202\271\344\270\252\346\225\260.java" | 2 +- ...345\256\266\345\212\253\350\210\2153.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 2 +- .../\346\240\221/MorrisTraversal.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 2 +- ...\344\272\214\345\217\211\346\240\221.java" | 2 +- .../bh160907/BiggestSubBSTInTree.java | 2 +- .../bh160907/PreInPosTraversal.java | 2 +- .../bi160914/MorrisTraversal.java | 2 +- src/main/java/common/util/SysOut.java | 6 +- .../{ => binaryTree}/ConstructBinaryTree.java | 23 ++++++- .../{ => binaryTree}/PrintBinaryTree.java | 43 ++----------- .../SerializeAndReConstructTree.java | 4 +- .../SerializeAndReConstructTreeImpl.java | 24 ++++---- .../SerializeAndReConstructTreeUtils.java | 61 +++++++++++++++++++ src/main/java/data_struct/README.md | 12 ++-- .../data_struct/ds1_\345\240\206/Heap.java" | 2 +- .../ds1_\345\240\206/HeapGreater.java" | 2 +- .../data_struct/ds1_\345\240\206/MyHeap.java" | 2 +- .../BinarySearchTree.java" | 2 +- .../BinarySearchTreeImpl.java" | 2 +- .../BinarySearchTreeNode.java" | 2 +- .../BinarySearchTreeTest.java" | 2 +- .../AVLNode.java" | 4 +- .../AVLTree.java" | 2 +- .../AVLTreeImpl.java" | 2 +- .../AVLTreeTest.java" | 2 +- .../RedBlackNode.java" | 2 +- .../RedBlackTree.java" | 2 +- .../RedBlackTreeImpl.java" | 2 +- .../RedBlackTreeTest.java" | 2 +- .../data_struct/ds4_\345\233\276/BFS.java" | 3 +- .../data_struct/ds4_\345\233\276/DFS.java" | 2 +- .../data_struct/ds4_\345\233\276/Graph.java" | 4 +- .../Code01_RecursiveTraversalBT.java" | 2 +- .../Code02_UnRecursiveTraversalBT.java" | 2 +- .../Code03_LevelTraversalBT.java" | 2 +- .../Code06_TreeMaxWidth.java" | 4 +- .../Code01_IsBalanced.java" | 4 +- .../Code02_IsBST.java" | 3 +- .../Code03_MaxDistance.java" | 26 ++++++-- .../Code04_IsFull.java" | 8 +-- .../Code05_MaxSubBSTSize.java" | 14 +++-- .../Code06_IsCBT.java" | 47 +++++++++++--- .../Code07_MaxSubBSTHead.java" | 5 +- .../Code08_lowestAncestor.java" | 56 +++++++++++++---- .../Code09_MaxHappy.java" | 20 +++++- ...76\350\241\250\345\222\214\346\240\221.md" | 2 +- 62 files changed, 307 insertions(+), 163 deletions(-) rename src/main/java/common/util/{ => binaryTree}/ConstructBinaryTree.java (87%) rename src/main/java/common/util/{ => binaryTree}/PrintBinaryTree.java (59%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" => src/main/java/common/util/binaryTree/SerializeAndReConstructTree.java (79%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" => src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java (90%) create mode 100644 src/main/java/common/util/binaryTree/SerializeAndReConstructTreeUtils.java rename "src/main/java/data_struct/\345\240\206/Heap.java" => "src/main/java/data_struct/ds1_\345\240\206/Heap.java" (99%) rename "src/main/java/data_struct/\345\240\206/HeapGreater.java" => "src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" (99%) rename "src/main/java/data_struct/\345\240\206/MyHeap.java" => "src/main/java/data_struct/ds1_\345\240\206/MyHeap.java" (95%) rename "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" => "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" (98%) rename "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" => "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" (99%) rename "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" => "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" (93%) rename "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" => "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" (98%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" (75%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" (96%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" (95%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" (83%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" (94%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" (98%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" (98%) rename "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" => "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" (93%) rename "src/main/java/data_struct/\345\233\276/BFS.java" => "src/main/java/data_struct/ds4_\345\233\276/BFS.java" (98%) rename "src/main/java/data_struct/\345\233\276/DFS.java" => "src/main/java/data_struct/ds4_\345\233\276/DFS.java" (98%) rename "src/main/java/data_struct/\345\233\276/Graph.java" => "src/main/java/data_struct/ds4_\345\233\276/Graph.java" (95%) diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" "b/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" index 2b34f532..d29d0beb 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" +++ "b/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" @@ -37,9 +37,9 @@ public class P06_用栈来解决汉诺塔问题 extends TestCase { @Test public void testCase() { int nums = 2; - SysOut.printSeparator("递归"); + SysOut.printSeparatorSuffixTitle("递归"); SysOut.println("It will move %s steps.", hanoiUsingRecursive(nums)); - SysOut.printSeparator("非递归(用栈)"); + SysOut.printSeparatorSuffixTitle("非递归(用栈)"); SysOut.println("It will move %s steps.", hanoiUsingStack(nums)); // SysOut.printSeparator("非递归(按照递归的思路转义,建立两个函数栈)"); // SysOut.println("It will move %s steps.", hanoiUsingStack(nums)); diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" index 93077f2c..c3470a72 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" index c0ddee46..8fc5bfbe 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" index 260cd89d..797a6842 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" index 405f9fdc..6fa8764c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" index 0ab61ff0..e4d88d6a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" "b/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" index 7af7244c..9ab25409 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" @@ -1,15 +1,12 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; import java.util.LinkedList; -import java.util.Map; import java.util.Queue; -import java.util.Set; /* 给定一个二叉树,找出其最小深度。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" index 1c2cd737..eb4b7d00 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" index 4fdf4a78..4381c81e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" index cd21cbcc..95aa4783 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" index 57f0cbf6..63e52e97 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code100; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" index 9f2576a8..b837870f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" @@ -1,9 +1,7 @@ package algorithm_practice.LeetCode.code100; -import com.alibaba.fastjson.JSON; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" index 44dcd63f..6f3173d5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" "b/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" index 75366fe1..c3391231 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" @@ -1,8 +1,8 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" "b/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" index ab4e215d..778550d0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code200; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" "b/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" index fd1305e2..0fdff871 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" @@ -1,13 +1,11 @@ package algorithm_practice.LeetCode.code300; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; -import java.util.ArrayList; import java.util.HashMap; -import java.util.List; import java.util.Map; /* diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" index ee2ba2ae..1b2e9cb4 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ package algorithm_practice.SwordOffer.old; import common.datastruct.BinaryTreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import java.util.HashMap; diff --git "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" "b/src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" index e6e81a7c..93c214af 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" @@ -1,8 +1,8 @@ package algorithm_practice.SwordOffer.树; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" index 3837df21..99139d21 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ package algorithm_practice.SwordOffer.树; import common.datastruct.BinaryTreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" index 34d7624e..bddaa966 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ package algorithm_practice.SwordOffer.树; import common.datastruct.BinaryTreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java index 89f839a1..2965119b 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java +++ b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java @@ -1,7 +1,7 @@ package algorithm_practice.nowcoder.b_2nd_Season.bh160907; import common.datastruct.BinaryTreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; /** * 找到二叉树中的最大搜索二叉子树 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java index 2880acb8..861b1bef 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java +++ b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java @@ -1,7 +1,7 @@ package algorithm_practice.nowcoder.b_2nd_Season.bh160907; import common.datastruct.BinaryTreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java index 4861ba24..7dcfd4a2 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java +++ b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java @@ -1,7 +1,7 @@ package algorithm_practice.nowcoder.b_2nd_Season.bi160914; import common.datastruct.BinaryTreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; /** * 二叉树的神级遍历 diff --git a/src/main/java/common/util/SysOut.java b/src/main/java/common/util/SysOut.java index e67581a9..f49a296d 100644 --- a/src/main/java/common/util/SysOut.java +++ b/src/main/java/common/util/SysOut.java @@ -35,7 +35,11 @@ public static void printSeparator() { println("==========================================="); } - public static void printSeparator(String title) { + public static void printSeparator(String str) { + println(str + "==========================================="); + } + + public static void printSeparatorSuffixTitle(String title) { println("===========================================\n%s:\n", title); } diff --git a/src/main/java/common/util/ConstructBinaryTree.java b/src/main/java/common/util/binaryTree/ConstructBinaryTree.java similarity index 87% rename from src/main/java/common/util/ConstructBinaryTree.java rename to src/main/java/common/util/binaryTree/ConstructBinaryTree.java index a12595e1..218d9529 100644 --- a/src/main/java/common/util/ConstructBinaryTree.java +++ b/src/main/java/common/util/binaryTree/ConstructBinaryTree.java @@ -1,10 +1,12 @@ -package common.util; +package common.util.binaryTree; import common.datastruct.TreeNode; import org.junit.Test; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedList; +import java.util.Map; /** * 构造二叉树 @@ -110,6 +112,25 @@ private static void fillPrelist(TreeNode head, ArrayList arr) { fillPrelist(head.right, arr); } + public static TreeNode pickOne(TreeNode head, int val) { + if (head == null) { + return null; + } + Map map = new HashMap<>(); + fillPreMap(head, map); + return map.get(val); + } + + private static void fillPreMap(TreeNode head, Map map) { + if (head == null) { + return; + } + map.put(head.val, head); + fillPreMap(head.left, map); + fillPreMap(head.right, map); + } + + @Test public void testCase() { Integer[] preOrderArray1 = {1, null, 2, 3}; diff --git a/src/main/java/common/util/PrintBinaryTree.java b/src/main/java/common/util/binaryTree/PrintBinaryTree.java similarity index 59% rename from src/main/java/common/util/PrintBinaryTree.java rename to src/main/java/common/util/binaryTree/PrintBinaryTree.java index e06657be..f24d06c2 100644 --- a/src/main/java/common/util/PrintBinaryTree.java +++ b/src/main/java/common/util/binaryTree/PrintBinaryTree.java @@ -1,8 +1,11 @@ -package common.util; +package common.util.binaryTree; import common.datastruct.BinaryTreeNode; import common.datastruct.TreeNode; +import common.util.SysOut; + +import java.util.Queue; /** * 打印二叉树 @@ -71,42 +74,4 @@ private static String getSpace(int n) { return sb.toString(); } - public static void printPreOrder(TreeNode head) { - if (head == null) { - return; - } - System.out.print(head.val + ", "); - printPreOrder(head.left); - printPreOrder(head.right); - } - - public static void main(String[] args) { - BinaryTreeNode head = new BinaryTreeNode(1); - head.left = new BinaryTreeNode(-222222222); - head.right = new BinaryTreeNode(3); - head.left.left = new BinaryTreeNode(Integer.MIN_VALUE); - head.right.left = new BinaryTreeNode(55555555); - head.right.right = new BinaryTreeNode(66); - head.left.left.right = new BinaryTreeNode(777); - print(head); - - head = new BinaryTreeNode(1); - head.left = new BinaryTreeNode(2); - head.right = new BinaryTreeNode(3); - head.left.left = new BinaryTreeNode(4); - head.right.left = new BinaryTreeNode(5); - head.right.right = new BinaryTreeNode(6); - head.left.left.right = new BinaryTreeNode(7); - print(head); - - head = new BinaryTreeNode(1); - head.left = new BinaryTreeNode(1); - head.right = new BinaryTreeNode(1); - head.left.left = new BinaryTreeNode(1); - head.right.left = new BinaryTreeNode(1); - head.right.right = new BinaryTreeNode(1); - head.left.left.right = new BinaryTreeNode(1); - print(head); - - } } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" b/src/main/java/common/util/binaryTree/SerializeAndReConstructTree.java similarity index 79% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" rename to src/main/java/common/util/binaryTree/SerializeAndReConstructTree.java index 9def42e8..e98750a2 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTree.java" +++ b/src/main/java/common/util/binaryTree/SerializeAndReConstructTree.java @@ -1,4 +1,4 @@ -package algorithmzuo.b_体系学习班.c0203_树; +package common.util.binaryTree; import common.datastruct.TreeNode; @@ -7,7 +7,7 @@ /** * Created by nibnait on 2022/10/27 */ -public interface Code04_SerializeAndReconstructTree { +public interface SerializeAndReConstructTree { Queue preSerial(TreeNode head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" b/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java similarity index 90% rename from "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" rename to src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java index 6015b9f5..35275a47 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code04_SerializeAndReconstructTreeImpl.java" +++ b/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java @@ -1,8 +1,10 @@ -package algorithmzuo.b_体系学习班.c0203_树; +package common.util.binaryTree; import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.*; +import common.util.CompareUtils; +import common.util.SysOut; +import common.util.SysRandom; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; import org.junit.Test; @@ -15,7 +17,7 @@ * Created by nibnait on 2022/10/27 */ @Slf4j -public class Code04_SerializeAndReconstructTreeImpl implements Code04_SerializeAndReconstructTree { +public class SerializeAndReConstructTreeImpl implements SerializeAndReConstructTree { @Test public void loopTestCase() { @@ -96,9 +98,9 @@ public Queue levelSerial(TreeNode head) { } else { travelArr.add(String.valueOf(head.val)); Queue queue = new LinkedList<>(); - travelArr.add(String.valueOf(head.val)); queue.add(head); while (!queue.isEmpty()) { + head = queue.poll(); if (head.left != null) { queue.add(head.left); travelArr.add(String.valueOf(head.left.val)); @@ -169,14 +171,14 @@ public TreeNode buildByLevelQueue(Queue level) { queue.add(head); } while (!queue.isEmpty()) { - head = queue.poll(); - head.left = generateNode(level.poll()); - head.right = generateNode(level.poll()); - if (head.left != null) { - queue.add(head.left); + TreeNode curHead = queue.poll(); + curHead.left = generateNode(level.poll()); + curHead.right = generateNode(level.poll()); + if (curHead.left != null) { + queue.add(curHead.left); } - if (head.right != null) { - queue.add(head.right); + if (curHead.right != null) { + queue.add(curHead.right); } } return head; diff --git a/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeUtils.java b/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeUtils.java new file mode 100644 index 00000000..c6796c95 --- /dev/null +++ b/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeUtils.java @@ -0,0 +1,61 @@ +package common.util.binaryTree; + +import common.datastruct.TreeNode; +import common.util.SysOut; +import org.apache.commons.collections4.CollectionUtils; + +import java.util.LinkedList; +import java.util.List; +import java.util.Queue; + +/** + * Created by nibnait on 2022/11/02 + */ +public class SerializeAndReConstructTreeUtils { + + /** + * 序列化 + */ + public static void serialByPreOrder(TreeNode head) { + printTravelArr(new SerializeAndReConstructTreeImpl().preSerial(head)); + } + public static void serialByPosOrder(TreeNode head) { + printTravelArr(new SerializeAndReConstructTreeImpl().posSerial(head)); + } + public static void serialByLevelOrder(TreeNode head) { + printTravelArr(new SerializeAndReConstructTreeImpl().levelSerial(head)); + } + + /** + * 反序列化 + */ + public static TreeNode buildByPreOrder(List pre) { + return new SerializeAndReConstructTreeImpl().buildByPreQueue(convert2LinkedList(pre)); + } + public static TreeNode buildByPosOrder(List pos) { + return new SerializeAndReConstructTreeImpl().buildByPosQueue(convert2LinkedList(pos)); + } + public static TreeNode buildByLevelOrder(List level) { + return new SerializeAndReConstructTreeImpl().buildByLevelQueue(convert2LinkedList(level)); + } + + private static LinkedList convert2LinkedList(List pre) { + LinkedList queue = new LinkedList<>(); + if (CollectionUtils.isEmpty(pre)) { + return queue; + } + for (String s : pre) { + queue.add(s); + } + return queue; + } + + private static void printTravelArr(Queue travelArr) { + if (travelArr == null) { + return; + } + while (!travelArr.isEmpty()) { + SysOut.print("\"" + travelArr.poll() + "\", "); + } + } +} diff --git a/src/main/java/data_struct/README.md b/src/main/java/data_struct/README.md index 9d3dd083..5497c8ae 100644 --- a/src/main/java/data_struct/README.md +++ b/src/main/java/data_struct/README.md @@ -9,15 +9,15 @@ Source Code:[https://algs4.cs.princeton.edu/code/](https://algs4.cs.princeton.ed ### 平衡二叉树 - [S110_平衡二叉树](../algorithm_practice/LeetCode/E110_平衡二叉树.java) -### [BST(二叉查找树)](./树/二叉查找树) -### [AVL(平衡二叉查找树)](./树/平衡查找树) +### [BST(二叉查找树)](./ds2_树/二叉查找树) +### [AVL(平衡二叉查找树)](./ds2_树/平衡查找树) ## 图 - - [BFS(广度优先遍历)](./图/BFS.java) - - [DFS(深度优先遍历)](./图/DFS.java) + - [BFS(广度优先遍历)](./ds4_图/BFS.java) + - [DFS(深度优先遍历)](./ds4_图/DFS.java) - [M547_朋友圈](../algorithm_practice/LeetCode/code500/M547_朋友圈.java) ## 堆(堆排序问题) - - [大顶堆](./堆/MaxHeap.java) - - [小顶堆](./堆/MinHeap.java) + - [大顶堆](./ds1_堆/MaxHeap.java) + - [小顶堆](./ds1_堆/MinHeap.java) - [M215_数组中的第K个最大元素](../algorithm_practice/LeetCode/code200/M215_数组中的第K个最大元素.java) \ No newline at end of file diff --git "a/src/main/java/data_struct/\345\240\206/Heap.java" "b/src/main/java/data_struct/ds1_\345\240\206/Heap.java" similarity index 99% rename from "src/main/java/data_struct/\345\240\206/Heap.java" rename to "src/main/java/data_struct/ds1_\345\240\206/Heap.java" index 949769d0..c8ab8bf9 100644 --- "a/src/main/java/data_struct/\345\240\206/Heap.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/Heap.java" @@ -1,4 +1,4 @@ -package data_struct.堆; +package data_struct.ds1_堆; import common.util.SwapUtil; import common.util.SysOut; diff --git "a/src/main/java/data_struct/\345\240\206/HeapGreater.java" "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" similarity index 99% rename from "src/main/java/data_struct/\345\240\206/HeapGreater.java" rename to "src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" index ae8a2266..1a13fb64 100644 --- "a/src/main/java/data_struct/\345\240\206/HeapGreater.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" @@ -1,4 +1,4 @@ -package data_struct.堆; +package data_struct.ds1_堆; import common.model.Person; import common.util.SysOut; diff --git "a/src/main/java/data_struct/\345\240\206/MyHeap.java" "b/src/main/java/data_struct/ds1_\345\240\206/MyHeap.java" similarity index 95% rename from "src/main/java/data_struct/\345\240\206/MyHeap.java" rename to "src/main/java/data_struct/ds1_\345\240\206/MyHeap.java" index 64837352..45da8e84 100644 --- "a/src/main/java/data_struct/\345\240\206/MyHeap.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/MyHeap.java" @@ -1,4 +1,4 @@ -package data_struct.堆; +package data_struct.ds1_堆; import java.util.List; diff --git "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" similarity index 98% rename from "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" index abe7750a..cd2963f6 100644 --- "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" @@ -1,4 +1,4 @@ -package data_struct.树.二叉查找树; +package data_struct.ds2_树.二叉查找树; /** * 二叉搜索树 diff --git "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" similarity index 99% rename from "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" index 2267e362..baa19921 100644 --- "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" @@ -1,4 +1,4 @@ -package data_struct.树.二叉查找树; +package data_struct.ds2_树.二叉查找树; import java.util.LinkedList; import java.util.Queue; diff --git "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" similarity index 93% rename from "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" index 64fabcf0..a30056b0 100644 --- "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" @@ -1,4 +1,4 @@ -package data_struct.树.二叉查找树; +package data_struct.ds2_树.二叉查找树; /** * 二叉搜索树结点 diff --git "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" similarity index 98% rename from "src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" index f1440597..9a09c185 100644 --- "a/src/main/java/data_struct/\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" @@ -1,4 +1,4 @@ -package data_struct.树.二叉查找树; +package data_struct.ds2_树.二叉查找树; import common.util.SysOut; import junit.framework.TestCase; diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" similarity index 75% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" index ae2a87a4..1510cdd1 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" @@ -1,6 +1,6 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; -import data_struct.树.二叉查找树.BinarySearchTreeNode; +import data_struct.ds2_树.二叉查找树.BinarySearchTreeNode; /** * 平衡查找树结点 diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" similarity index 96% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" index 6413c9ef..13f424fc 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; /** * 平衡查找树 diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" similarity index 95% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" index 544af55d..19e10bf1 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; /** * 平衡查找树实现 diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" similarity index 83% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" index bf7162dc..87970f2f 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" similarity index 94% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" index ac63b79b..b91e4cbd 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; /** * 红黑树结点 diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" similarity index 98% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" index 153a04f3..0cbcdfd1 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; /** * 红黑树 diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" similarity index 98% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" index d3f6c8fc..1e3e3b82 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; /** * 红黑树实现 diff --git "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" similarity index 93% rename from "src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" rename to "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" index 65ade195..66f03cef 100644 --- "a/src/main/java/data_struct/\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" +++ "b/src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" @@ -1,4 +1,4 @@ -package data_struct.树.平衡查找树; +package data_struct.ds2_树.平衡查找树; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/data_struct/\345\233\276/BFS.java" "b/src/main/java/data_struct/ds4_\345\233\276/BFS.java" similarity index 98% rename from "src/main/java/data_struct/\345\233\276/BFS.java" rename to "src/main/java/data_struct/ds4_\345\233\276/BFS.java" index 8dbae1de..5dc09458 100644 --- "a/src/main/java/data_struct/\345\233\276/BFS.java" +++ "b/src/main/java/data_struct/ds4_\345\233\276/BFS.java" @@ -1,11 +1,10 @@ -package data_struct.图; +package data_struct.ds4_图; import common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; import java.io.IOException; -import java.io.InputStream; import java.util.*; /** diff --git "a/src/main/java/data_struct/\345\233\276/DFS.java" "b/src/main/java/data_struct/ds4_\345\233\276/DFS.java" similarity index 98% rename from "src/main/java/data_struct/\345\233\276/DFS.java" rename to "src/main/java/data_struct/ds4_\345\233\276/DFS.java" index b31dd641..d3d0636e 100644 --- "a/src/main/java/data_struct/\345\233\276/DFS.java" +++ "b/src/main/java/data_struct/ds4_\345\233\276/DFS.java" @@ -1,4 +1,4 @@ -package data_struct.图; +package data_struct.ds4_图; import common.util.SysOut; import junit.framework.TestCase; diff --git "a/src/main/java/data_struct/\345\233\276/Graph.java" "b/src/main/java/data_struct/ds4_\345\233\276/Graph.java" similarity index 95% rename from "src/main/java/data_struct/\345\233\276/Graph.java" rename to "src/main/java/data_struct/ds4_\345\233\276/Graph.java" index 2f96ccf1..1eaa488b 100644 --- "a/src/main/java/data_struct/\345\233\276/Graph.java" +++ "b/src/main/java/data_struct/ds4_\345\233\276/Graph.java" @@ -1,12 +1,10 @@ -package data_struct.图; +package data_struct.ds4_图; import lombok.Getter; import java.io.BufferedInputStream; import java.io.IOException; import java.io.InputStream; -import java.nio.file.Files; -import java.nio.file.Path; import java.util.*; /** diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" index 418f9b77..200a8c83 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" @@ -2,7 +2,7 @@ import com.google.common.collect.Lists; import common.datastruct.TreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import io.github.nibnait.common.utils.compare.CompareUtils; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" index 6bebb0e7..cbe04a26 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" @@ -2,7 +2,7 @@ import com.google.common.collect.Lists; import common.datastruct.TreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import io.github.nibnait.common.utils.compare.CompareUtils; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" index de00cfb8..44c07d1f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" @@ -2,7 +2,7 @@ import com.google.common.collect.Lists; import common.datastruct.TreeNode; -import common.util.PrintBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import io.github.nibnait.common.utils.compare.CompareUtils; import lombok.extern.slf4j.Slf4j; import org.junit.Assert; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" index dcae9514..5263caf1 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" @@ -2,8 +2,8 @@ import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import common.util.SysOut; import common.util.SysRandom; import org.junit.Assert; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" index 800b7134..915184ba 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" @@ -2,7 +2,7 @@ import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import common.util.SysRandom; import lombok.AllArgsConstructor; import org.junit.Assert; @@ -35,7 +35,7 @@ public void testCase() { * 判断二叉树是不是平衡二叉树 * 即:任何一棵子树的 | 左高度 - 右高度 | <= 1 */ - private boolean isBalanced(TreeNode head) { + protected boolean isBalanced(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" index 34bc6c95..229146f4 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" @@ -3,6 +3,7 @@ import common.CommonConstants; import common.datastruct.TreeNode; import common.util.*; +import common.util.binaryTree.ConstructBinaryTree; import lombok.AllArgsConstructor; import org.junit.Assert; import org.junit.Test; @@ -39,7 +40,7 @@ public void testCase() { * 判断二叉树是不是搜索二叉树(整棵树无重复节点) * 即:任何一棵子树。都是搜索二叉树 */ - private boolean isBST(TreeNode head) { + protected boolean isBST(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" index 293bfa36..053d462e 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" @@ -3,6 +3,7 @@ import common.CommonConstants; import common.datastruct.TreeNode; import common.util.*; +import common.util.binaryTree.ConstructBinaryTree; import lombok.AllArgsConstructor; import org.junit.Assert; import org.junit.Test; @@ -29,8 +30,8 @@ public void testCase() { int maxValue = SysRandom.random(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); - PrintBinaryTree.print(head); - SysOut.printSeparator(); +// PrintBinaryTree.print(head); +// SysOut.printSeparator(); int result = maxDistance(head); @@ -40,16 +41,31 @@ public void testCase() { /** * 给定一棵二叉树的头节点head,任何两个节点之间都存在距离,返回整棵二叉树的最大距离 */ - private int maxDistance(TreeNode head) { + protected int maxDistance(TreeNode head) { if (head == null) { return 0; } - return 0; + return process(head).maxDistance; + } + + private Info process(TreeNode head) { + if (head == null) { + return new Info(0, 0); + } + + Info left = process(head.left); + Info right = process(head.right); + + int height = Math.max(left.height, right.height) + 1; + int maxDistance = CompareUtils.max(left.maxDistance, right.maxDistance, left.height + right.height + 1); + + return new Info(height, maxDistance); } @AllArgsConstructor private class Info { - + public int height; + public int maxDistance; } //-------------------------- 对数器 --------------------------// diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" index e3b4c31a..2efab373 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" @@ -2,8 +2,8 @@ import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import common.util.SysOut; import common.util.SysRandom; import lombok.AllArgsConstructor; @@ -37,7 +37,7 @@ public void testCase() { /** * 判断二叉树是不是满二叉树 */ - private boolean isFull1(TreeNode head) { + protected boolean isFull1(TreeNode head) { if (head == null) { return true; } @@ -67,7 +67,7 @@ private class Info1 { /** * 法2: 只有满二叉树满足 : 2 ^ h - 1 == n */ - private boolean isFull2(TreeNode head) { + protected boolean isFull2(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" index 98b9bbf5..ff00c0d9 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" @@ -2,9 +2,12 @@ import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; +import common.util.SysOut; import common.util.SysRandom; import lombok.AllArgsConstructor; +import org.junit.Assert; import org.junit.Test; import java.util.ArrayList; @@ -27,25 +30,24 @@ public void testCase() { int maxValue = SysRandom.random(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); -// PrintBinaryTree.print(head); -// SysOut.printSeparator(); + PrintBinaryTree.print(head); + SysOut.printSeparator(); int result = maxSubBSTSize(head); -// Assert.assertEquals(result, maxSubBSTSize1(head)); + Assert.assertEquals(result, maxSubBSTSize1(head)); } /** * 给定一棵二叉树的头节点head,返回这颗二叉树中最大的二叉搜索子树的大小 */ - private int maxSubBSTSize(TreeNode head) { + protected int maxSubBSTSize(TreeNode head) { if (head == null) { return 0; } return 1; } - @AllArgsConstructor private class Info { } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" index 71aae475..48ccf722 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" @@ -2,9 +2,10 @@ import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; import common.util.SysRandom; import lombok.AllArgsConstructor; +import org.junit.Assert; import org.junit.Test; import java.util.LinkedList; @@ -31,25 +32,55 @@ public void testCase() { // SysOut.printSeparator(); boolean result = isCBT(head); -// Assert.assertEquals(comparator(head), result); + Assert.assertEquals(comparator(head), result); } /** - * 判断二叉树是不是完全二叉树 - * 每棵子树,都有左右孩子。 + * 判断二叉树是不是完全二叉树(正在变成满二叉树的过程中) */ - private boolean isCBT(TreeNode head) { + protected boolean isCBT(TreeNode head) { if (head == null) { return true; } - return true; + return process(head).isCBT; } - @AllArgsConstructor - private class Info { + private Info process(TreeNode head) { + if (head == null) { + return new Info(true, true, 0); + } + + Info left = process(head.left); + Info right = process(head.right); + boolean isFull = left.isFull && right.isFull && left.height == right.height; + int height = Math.max(left.height, right.height) + 1; + boolean isCBT = false; + if (left.isFull && right.isCBT && left.height == right.height) { + isCBT = true; + } else if (left.isFull && right.isFull && left.height == right.height) { + isCBT = true; + } else if (left.isCBT && right.isFull && left.height == right.height + 1) { + isCBT = true; + } else if (left.isFull && right.isFull && left.height == right.height + 1) { + isCBT = true; + } + + return new Info(isFull, isCBT, height); } + /** + * 左满 右完全 -> 左高 == 右高 + * 左满 右满 -> 左高 == 右高 + * 左完全 右满 -> 左高 == 右高+1 + * 左满 右满 -> 左高 == 右高+1 + */ + @AllArgsConstructor + private class Info { + public boolean isFull; + public boolean isCBT; + public int height; + } //-------------------------- 对数器 --------------------------// private boolean comparator(TreeNode head) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" index 66b4fea1..3d6d366a 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" @@ -2,8 +2,8 @@ import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; import common.util.SysOut; import common.util.SysRandom; import lombok.AllArgsConstructor; @@ -51,6 +51,7 @@ private TreeNode maxSubBSTHead(TreeNode head) { @AllArgsConstructor private class Info { + } //-------------------------- 对数器 --------------------------// diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" index d7006f98..258f6b4b 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" @@ -1,11 +1,13 @@ package algorithmzuo.b_体系学习班.c0204_树型DP; +import com.google.common.collect.Lists; import common.CommonConstants; import common.datastruct.TreeNode; -import common.util.ConstructBinaryTree; -import common.util.PrintBinaryTree; import common.util.SysOut; import common.util.SysRandom; +import common.util.binaryTree.ConstructBinaryTree; +import common.util.binaryTree.PrintBinaryTree; +import common.util.binaryTree.SerializeAndReConstructTreeUtils; import lombok.AllArgsConstructor; import org.junit.Assert; import org.junit.Test; @@ -31,33 +33,63 @@ public void testCase() { int maxValue = SysRandom.random(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); - TreeNode o1 = ConstructBinaryTree.pickRandomOne(head); - TreeNode o2 = ConstructBinaryTree.pickRandomOne(head); PrintBinaryTree.print(head); - SysOut.printSeparator(); + TreeNode a = ConstructBinaryTree.pickRandomOne(head); + TreeNode b = ConstructBinaryTree.pickRandomOne(head); + if (head != null) { + SysOut.println("\na=%s, b=%s", a.val, b.val); + } + SerializeAndReConstructTreeUtils.serialByLevelOrder(head); + SysOut.printSeparator("\n"); - TreeNode result = lowestAncestor(head, o1, o2); - Assert.assertEquals(comparator(head, o1, o2), result); + TreeNode result = lowestAncestor(head, a, b); + if (head == null) { + Assert.assertNull(result); + } else { + Assert.assertEquals(comparator(head, a, b).val, result.val); + } + } + + @Test + public void testSpecialCase() { + TreeNode head = SerializeAndReConstructTreeUtils.buildByLevelOrder(Lists.newArrayList("53", "#", "30", "#", "37", "23", "3", "61", "27", "9", "35", "#", "#", "#", "#", "#", "#", "#", "#")); + PrintBinaryTree.print(head); + TreeNode a = ConstructBinaryTree.pickOne(head, 35); + TreeNode b = ConstructBinaryTree.pickOne(head, 37); + if (head != null) { + SysOut.println("\na=%s, b=%s", a.val, b.val); + } + SerializeAndReConstructTreeUtils.serialByLevelOrder(head); + SysOut.printSeparator("\n"); + + TreeNode result = lowestAncestor(head, a, b); + TreeNode expectResult = comparator(head, a, b); + SysOut.println("\nresult=%s, expectResult=%s", result.val, expectResult.val); + if (head == null) { + Assert.assertNull(result); + } else { + Assert.assertEquals(expectResult.val, result.val); + } } /** * 给定一棵二叉树的头节点head,和另外两个节点a和b,返回a和b的最低公共祖先 */ - private TreeNode lowestAncestor(TreeNode head, TreeNode o1, TreeNode o2) { + protected TreeNode lowestAncestor(TreeNode head, TreeNode a, TreeNode b) { if (head == null) { return null; } return null; } + @AllArgsConstructor private class Info { - } //-------------------------- 对数器 --------------------------// - private TreeNode comparator(TreeNode head, TreeNode o1, TreeNode o2) { + private TreeNode comparator(TreeNode head, TreeNode a, TreeNode b) { if (head == null) { return null; } @@ -66,13 +98,13 @@ private TreeNode comparator(TreeNode head, TreeNode o1, TreeNode o2) { parentMap.put(head, null); fillParentMap(head, parentMap); HashSet o1Set = new HashSet<>(); - TreeNode cur = o1; + TreeNode cur = a; o1Set.add(cur); while (parentMap.get(cur) != null) { cur = parentMap.get(cur); o1Set.add(cur); } - cur = o2; + cur = b; while (!o1Set.contains(cur)) { cur = parentMap.get(cur); } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" index e4dc980a..3307838d 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" @@ -45,7 +45,25 @@ public void testCase() { Assert.assertEquals(result, maxHappy1(boss)); } - private TreeNode maxHappy(Employee boss) { +/* +派对的最大快乐值 + 员工信息的定义如下: +class Employee { + public int happy; // 这名员工可以带来的快乐值 + List subordinates; // 这名员工有哪些直接下级 +} +公司的每个员工都符合 Employee 类的描述。整个公司的人员结构可以看作是一棵标准的、 没有环的多叉树 +树的头节点是公司唯一的老板,除老板之外的每个员工都有唯一的直接上级 +叶节点是没有任何下属的基层员工(subordinates列表为空),除基层员工外每个员工都有一个或多个直接下级 +这个公司现在要办party,你可以决定哪些员工来,哪些员工不来,规则: +1.如果某个员工来了,那么这个员工的所有直接下级都不能来 +2.派对的整体快乐值是所有到场员工快乐值的累加 +3.你的目标是让派对的整体快乐值尽量大 +给定一棵多叉树的头节点boss,请返回派对的最大快乐值。 + +给定一个由字符串组成的数组strs,必须把所有的字符串拼接起来,返回所有可能的拼接结果中字典序最小的结果 +*/ + protected TreeNode maxHappy(Employee boss) { return null; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" index 89933904..10b320a1 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" @@ -10,7 +10,7 @@ - [Code01_先序、中序、后序遍历-递归](./c0203_树/Code01_RecursiveTraversalBT.java) - [Code02_先序、中序、后序遍历-非递归](./c0203_树/Code02_UnRecursiveTraversalBT.java) - [Code03_二叉树的按层遍历](./c0203_树/Code03_LevelTraversalBT.java) - - [Code04_二叉树的序列化和反序列化](./c0203_树/Code04_SerializeAndReconstructTree.java) + - [Code04_二叉树的序列化和反序列化](../../../java/common/util/binaryTree/SerializeAndReConstructTree.java) - [Code05_N叉树如何通过二叉树来序列化、并完成反序列化](./c0203_树/Code05_EncodeNaryTreeToBinaryTree.java) - [Code06_求二叉树的最大宽度](./c0203_树/Code06_TreeMaxWidth.java) From 20f702a366fdcc7789a2ad2eca2cfc6f66b077ed Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 2 Nov 2022 08:29:46 +0800 Subject: [PATCH 22/36] =?UTF-8?q?feat=20=E8=B4=AA=E5=BF=83=E7=AE=97?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/java/common/util/SysRandom.java | 8 ++ .../Code04_3_SmallSum.java" | 2 +- .../Code04_4_ReversePair.java" | 2 +- .../Code04_5_BiggerThanRightTwice.java" | 2 +- .../Code06_2_SortArrayDistanceLessK.java" | 2 +- .../Code06_3_CoverMax.java" | 2 +- .../Code03_LinkedListMid.java" | 2 +- .../Code06_TreeMaxWidth.java" | 2 +- .../Code01_IsBalanced.java" | 2 +- .../Code02_IsBST.java" | 2 +- .../Code03_MaxDistance.java" | 2 +- .../Code05_MaxSubBSTSize.java" | 2 +- .../Code06_IsCBT.java" | 2 +- .../Code07_MaxSubBSTHead.java" | 2 +- .../Code08_lowestAncestor.java" | 2 +- .../Code09_MaxHappy.java" | 2 +- .../Code01_Light.java" | 79 ++++++++++++++ .../Code02_LessMoneySplitGold.java" | 70 ++++++++++++ .../Code03_BestArrange.java" | 100 ++++++++++++++++++ .../Code04_IPO.java" | 39 +++++++ ...52\345\277\203\347\256\227\346\263\225.md" | 30 ++++++ 21 files changed, 341 insertions(+), 15 deletions(-) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code04_IPO.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c03xx_\350\264\252\345\277\203\347\256\227\346\263\225.md" diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index 628d9065..0a399d30 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -83,4 +83,12 @@ public static int[] randomArrNaturalNum(int arrLength) { } return a; } + + public static int[] randomArrNaturalNum(int arrLength, int maxValue) { + int[] a = new int[arrLength]; + for (int i = 0; i < a.length; i++) { + a[i] = randomInt(0, maxValue); + } + return a; + } } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" index d80936b2..4d611000 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" @@ -95,7 +95,7 @@ private int merge(int[] arr, int left, int mid, int right) { return smallSum; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int comparator(int[] arr) { if (arr == null || arr.length < 2) { return 0; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" index 8928c27a..33ec6ee4 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" @@ -88,7 +88,7 @@ private int merge(int[] arr, int left, int mid, int right) { return reversePairCount; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int comparator(int[] arr) { int ans = 0; for (int i = 0; i < arr.length; i++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" index 86c6c692..2d01014a 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" @@ -97,7 +97,7 @@ private int merge(int[] arr, int left, int mid, int right) { return res; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int comparator(int[] arr) { int ans = 0; for (int i = 0; i < arr.length; i++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" index c5b98d0a..460c6a12 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" @@ -68,7 +68,7 @@ private void sortArrayDistanceLessK(int[] arr, int k) { } } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private static int[] randomArrayNoMoveMoreK(int maxSize, int maxValue, int K) { int[] arr = new int[(int) ((maxSize + 1) * Math.random())]; for (int i = 0; i < arr.length; i++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" index b76ce8c5..4697a3cc 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" @@ -74,7 +74,7 @@ private int maxCover(int[][] lines) { return ans; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int comparator(int[][] lines) { int min = Integer.MAX_VALUE; int max = Integer.MIN_VALUE; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" index 88403148..5aede4e6 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" @@ -112,7 +112,7 @@ public static ListNode midOrDownMidPreLinkedNode(ListNode head) { return slow; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// public static ListNode right1(ListNode head) { if (head == null) { return null; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" index 5263caf1..0b6cfd5a 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" @@ -47,7 +47,7 @@ private int maxWidth(TreeNode head) { return 0; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int comparator(TreeNode head) { if (head == null) { return 0; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" index 915184ba..ba59eb24 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" @@ -62,7 +62,7 @@ private class Info { public boolean isBalance; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private boolean comparator(TreeNode head) { boolean[] ans = new boolean[1]; ans[0] = true; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" index 229146f4..2fb3991c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" @@ -85,7 +85,7 @@ private class Info { public boolean isBST; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private boolean comparator(TreeNode head) { if (head == null) { return true; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" index 053d462e..ddc05418 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" @@ -68,7 +68,7 @@ private class Info { public int maxDistance; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int comparator(TreeNode head) { if (head == null) { return 0; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" index ff00c0d9..da376592 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" @@ -52,7 +52,7 @@ protected int maxSubBSTSize(TreeNode head) { private class Info { } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int maxSubBSTSize1(TreeNode head) { if (head == null) { return 0; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" index 48ccf722..ff42323b 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" @@ -82,7 +82,7 @@ private class Info { public int height; } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private boolean comparator(TreeNode head) { if (head == null) { return true; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" index 3d6d366a..e6a840dc 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" @@ -54,7 +54,7 @@ private class Info { } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private TreeNode maxSubBSTHead1(TreeNode head) { if (head == null) { return null; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" index 258f6b4b..cf5de95d 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" @@ -88,7 +88,7 @@ private class Info { } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private TreeNode comparator(TreeNode head, TreeNode a, TreeNode b) { if (head == null) { return null; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" index 3307838d..81982b2c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" @@ -72,7 +72,7 @@ private class Info { } - //-------------------------- 对数器 --------------------------// + //-------------------------- 比较器 --------------------------// private int maxHappy1(Employee boss) { if (boss == null) { return 0; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" new file mode 100644 index 00000000..f411424e --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" @@ -0,0 +1,79 @@ +package algorithmzuo.b_体系学习班.c0300_贪心; + +import common.CommonConstants; +import common.util.SysRandom; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashSet; + +/** + * Created by nibnait on 2022/11/02 + */ +public class Code01_Light { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int len = SysRandom.randomInt(0, 50); + String road = randomString(len); + + int result = minLight(road); + Assert.assertEquals(comparator(road), result); + } + + /** + * 最少放几盏灯 + */ + private int minLight(String road) { + return 0; + } + + //-------------------------- 比较器 --------------------------// + private String randomString(int len) { + char[] res = new char[(int) (Math.random() * len) + 1]; + for (int i = 0; i < res.length; i++) { + res[i] = Math.random() < 0.5 ? 'X' : '.'; + } + return String.valueOf(res); + } + + private int comparator(String road) { + if (road == null || road.length() == 0) { + return 0; + } + return process(road.toCharArray(), 0, new HashSet<>()); + } + + // str[index....]位置,自由选择放灯还是不放灯 + // str[0..index-1]位置呢?已经做完决定了,那些放了灯的位置,存在lights里 + // 要求选出能照亮所有.的方案,并且在这些有效的方案中,返回最少需要几个灯 + private int process(char[] str, int index, HashSet lights) { + if (index == str.length) { // 结束的时候 + for (int i = 0; i < str.length; i++) { + if (str[i] != 'X') { // 当前位置是点的话 + if (!lights.contains(i - 1) && !lights.contains(i) && !lights.contains(i + 1)) { + return Integer.MAX_VALUE; + } + } + } + return lights.size(); + } else { // str还没结束 + // i X . + int no = process(str, index + 1, lights); + int yes = Integer.MAX_VALUE; + if (str[index] == '.') { + lights.add(index); + yes = process(str, index + 1, lights); + lights.remove(index); + } + return Math.min(no, yes); + } + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" new file mode 100644 index 00000000..e6ee6b5a --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" @@ -0,0 +1,70 @@ +package algorithmzuo.b_体系学习班.c0300_贪心; + +import common.CommonConstants; +import common.util.SysRandom; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/02 + */ +public class Code02_LessMoneySplitGold { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int arrLen = SysRandom.random(20); + int[] arr = SysRandom.randomArrNaturalNum(arrLen, 1000); + + int result = lessMoney(arr); + Assert.assertEquals(comparator(arr), result); + } + + /** + * 花最少的钱 去分割金条 + */ + private int lessMoney(int[] arr) { + return 0; + } + + //-------------------------- 比较器 --------------------------// + public static int comparator(int[] arr) { + if (arr == null || arr.length == 0) { + return 0; + } + return process(arr, 0); + } + + // 等待合并的数都在arr里,pre之前的合并行为产生了多少总代价 + // arr中只剩一个数字的时候,停止合并,返回最小的总代价 + public static int process(int[] arr, int pre) { + if (arr.length == 1) { + return pre; + } + int ans = Integer.MAX_VALUE; + for (int i = 0; i < arr.length; i++) { + for (int j = i + 1; j < arr.length; j++) { + ans = Math.min(ans, process(copyAndMergeTwo(arr, i, j), pre + arr[i] + arr[j])); + } + } + return ans; + } + + public static int[] copyAndMergeTwo(int[] arr, int i, int j) { + int[] ans = new int[arr.length - 1]; + int ansi = 0; + for (int arri = 0; arri < arr.length; arri++) { + if (arri != i && arri != j) { + ans[ansi++] = arr[arri]; + } + } + ans[ansi] = arr[i] + arr[j]; + return ans; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" new file mode 100644 index 00000000..71dff93c --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" @@ -0,0 +1,100 @@ +package algorithmzuo.b_体系学习班.c0300_贪心; + +import common.CommonConstants; +import common.util.SysRandom; +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/02 + */ +public class Code03_BestArrange { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int programSize = SysRandom.randomInt(5, 20); + int timeMax = SysRandom.randomInt(10, 30); + Program[] programs = generatePrograms(programSize, timeMax); + + int result = bestArrange(programs); + Assert.assertEquals(comparator(programs), result); + } + + @AllArgsConstructor + private static class Program { + public int start; + public int end; + } + + /** + * 最多可以安排几场会议? + */ + private int bestArrange(Program[] programs) { + return 0; + } + + //-------------------------- 比较器 --------------------------// + public static Program[] generatePrograms(int programSize, int timeMax) { + Program[] ans = new Program[(int) (Math.random() * (programSize + 1))]; + for (int i = 0; i < ans.length; i++) { + int r1 = (int) (Math.random() * (timeMax + 1)); + int r2 = (int) (Math.random() * (timeMax + 1)); + if (r1 == r2) { + ans[i] = new Program(r1, r1 + 1); + } else { + ans[i] = new Program(Math.min(r1, r2), Math.max(r1, r2)); + } + } + return ans; + } + + // 暴力!所有情况都尝试! + public static int comparator(Program[] programs) { + if (programs == null || programs.length == 0) { + return 0; + } + return process(programs, 0, 0); + } + + // 还剩下的会议都放在programs里 + // done之前已经安排了多少会议的数量 + // timeLine目前来到的时间点是什么 + + // 目前来到timeLine的时间点,已经安排了done多的会议,剩下的会议programs可以自由安排 + // 返回能安排的最多会议数量 + public static int process(Program[] programs, int done, int timeLine) { + if (programs.length == 0) { + return done; + } + // 还剩下会议 + int max = done; + // 当前安排的会议是什么会,每一个都枚举 + for (int i = 0; i < programs.length; i++) { + if (programs[i].start >= timeLine) { + Program[] next = copyButExcept(programs, i); + max = Math.max(max, process(next, done + 1, programs[i].end)); + } + } + return max; + } + + public static Program[] copyButExcept(Program[] programs, int i) { + Program[] ans = new Program[programs.length - 1]; + int index = 0; + for (int k = 0; k < programs.length; k++) { + if (k != i) { + ans[index++] = programs[k]; + } + } + return ans; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code04_IPO.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code04_IPO.java" new file mode 100644 index 00000000..497497a1 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code04_IPO.java" @@ -0,0 +1,39 @@ +package algorithmzuo.b_体系学习班.c0300_贪心; + +import lombok.AllArgsConstructor; +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/02 + */ +public class Code04_IPO { + + @Test + public void test() { + int K = 3; + int W = 3; + int[] profits = new int[]{2,3,5,5,453}; + int[] costs = new int[]{3,1,2,6,23}; + int result = findMaximizedCapital(K, W, profits, costs); + Assert.assertEquals(16, result); + + } + + /** + * @param K 最多能做 K 个项目 + * @param W 启动资金 + * @param profits 每i个项目的利润 + * @param costs 第i个项目的花费 + * @return 最后获得的最大钱数 + */ + private int findMaximizedCapital(int K, int W, int[] profits, int[] costs) { + return 0; + } + + @AllArgsConstructor + private static class Project { + public int profit; + public int cost; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c03xx_\350\264\252\345\277\203\347\256\227\346\263\225.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c03xx_\350\264\252\345\277\203\347\256\227\346\263\225.md" new file mode 100644 index 00000000..dff66fa7 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c03xx_\350\264\252\345\277\203\347\256\227\346\263\225.md" @@ -0,0 +1,30 @@ +## 贪心 +自然智慧 想出的局部最优解 -> 全局最优解 +不断试错,没有证明。。 + + - [Code01_Light](./c0300_贪心/Code01_Light.java) +给定一个字符串str,只由'X'和'.'两种字符构成 +'X'表示墙,不能放灯,也不需要点亮;'.'表示居民点,可以放灯,需要点亮 +如果灯放在i位置,可以让i-1,i和i+1三个位置被点亮 +返回如果点亮str中所有需要点亮的位置,至少需要几盏灯 + + - [Code02_LessMoneySplitGold](./c0300_贪心/Code02_LessMoneySplitGold.java) +一块金条切成两半,是需要花费和长度数值一样的铜板 +比如长度为20的金条,不管怎么切都要花费20个铜板,一群人想整分整块金条,怎么分最省铜板? +例如,给定数组{10,20,30},代表一共三个人,整块金条长度为60,金条要分成10,20,30三个部分。 +如果先把长度60的金条分成10和50,花费60;再把长度50的金条分成20和30,花费50;一共花费110铜板 +但如果先把长度60的金条分成30和30,花费60;再把长度30金条分成10和20,花费30;一共花费90铜板 +输入一个数组,返回分割的最小代价 + + - [Code03_BestArrange](./c0300_贪心/Code03_BestArrange.java) +一些项目要占用一个会议室宣讲,会议室不能同时容纳两个项目的宣讲,给你每一个项目开始的时间和结束的时间 +你来安排宣讲的日程,要求会议室进行的宣讲的场次最多,返回最多的宣讲场次 + + - [Code04_IPO](./c0300_贪心/Code04_IPO.java) +输入正数数组costs、正数数组profits、正数K和正数M +costs[i]表示i号项目的花费 +profits[i]表示i号项目在扣除花费之后还能挣到的钱(利润) +K表示你只能串行的最多做k个项目 +M表示你初始的资金 +说明:每做完一个项目,马上获得的收益,可以支持你去做下一个项目,不能并行的做项目。 +输出:最后获得的最大钱数 From 9281f332d77fd96ede5af2cf8002456fe997289d Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 2 Nov 2022 09:28:26 +0800 Subject: [PATCH 23/36] =?UTF-8?q?feat=20=E5=B9=B6=E6=9F=A5=E9=9B=86?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\346\234\213\345\217\213\345\234\210.java" | 1 - src/main/java/common/util/CopyUtil.java | 25 +++ src/main/java/common/util/SysRandom.java | 13 ++ src/main/java/data_struct/Node.java | 16 ++ .../ds1_\345\240\206/HeapGreater.java" | 51 ++--- .../MyUnionFind.java" | 27 +++ .../UnionFind.java" | 119 +++++++++++ src/main/test/UnitTestDemo.java | 9 + ...00\347\232\204\347\256\227\346\263\225.md" | 2 +- .../Code01_FriendCircles.java" | 53 +++++ .../Code02_NumberOfIslands.java" | 198 ++++++++++++++++++ .../Code03_NumberOfIslandsII.java" | 11 + ...x_\345\271\266\346\237\245\351\233\206.md" | 10 + 13 files changed, 504 insertions(+), 31 deletions(-) create mode 100644 src/main/java/common/util/CopyUtil.java create mode 100644 src/main/java/data_struct/Node.java create mode 100644 "src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/MyUnionFind.java" create mode 100644 "src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/UnionFind.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code03_NumberOfIslandsII.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" "b/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" index b188b1cd..93385f27 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" @@ -4,7 +4,6 @@ import org.junit.Test; import java.util.LinkedList; -import java.util.Queue; /* 班上有 N 名学生。其中有些人是朋友,有些则不是。他们的友谊具有是传递性。如果已知 A 是 B 的朋友,B 是 C 的朋友,那么我们可以认为 A 也是 C 的朋友。所谓的朋友圈,是指所有朋友的集合。 diff --git a/src/main/java/common/util/CopyUtil.java b/src/main/java/common/util/CopyUtil.java new file mode 100644 index 00000000..d18051b6 --- /dev/null +++ b/src/main/java/common/util/CopyUtil.java @@ -0,0 +1,25 @@ +package common.util; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/11/03 + */ +public class CopyUtil { + + public static int[] copy(int[] arr) { + return Arrays.copyOf(arr, arr.length); + } + + public static char[][] copy(char[][] board) { + int row = board.length; + int col = board[0].length; + char[][] ans = new char[row][col]; + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { + ans[i][j] = board[i][j]; + } + } + return ans; + } +} diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index 0a399d30..9abe44d9 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -91,4 +91,17 @@ public static int[] randomArrNaturalNum(int arrLength, int maxValue) { } return a; } + + /** + * 返回一个 0 1 矩阵 + */ + public static char[][] randomMatrix(int row, int col) { + char[][] board = new char[row][col]; + for (int i = 0; i < row; i++) { + for (int j = 0; j < col; j++) { + board[i][j] = Math.random() < 0.5 ? '1' : '0'; + } + } + return board; + } } diff --git a/src/main/java/data_struct/Node.java b/src/main/java/data_struct/Node.java new file mode 100644 index 00000000..f401816c --- /dev/null +++ b/src/main/java/data_struct/Node.java @@ -0,0 +1,16 @@ +package data_struct; + +/** + * Created by nibnait on 2022/11/02 + */ +public class Node { + public T value; + + public Node(T v) { + value = v; + } + + public static Node v(T v) { + return new Node(v); + } +} diff --git "a/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" index 1a13fb64..854ba63e 100644 --- "a/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" @@ -3,6 +3,7 @@ import common.model.Person; import common.util.SysOut; import common.util.SysRandom; +import data_struct.Node; import org.junit.Test; import java.util.ArrayList; @@ -23,7 +24,7 @@ public void testCase() { int limit = 10; MaxHeapGreater maxHeap = new MaxHeapGreater(new MyComparator()); for (int i : arr) { - maxHeap.push(new Inner(Person.buildByAge(i))); + maxHeap.push(new Node(Person.buildByAge(i))); } for (int i = 0; i < limit; i++) { Person p = (Person) maxHeap.pop().value; @@ -31,32 +32,24 @@ public void testCase() { } } - private class MyComparator implements Comparator { + private class MyComparator implements Comparator { @Override - public int compare(Inner o1, Inner o2) { + public int compare(Node o1, Node o2) { Person p1 = (Person) o1.value; Person p2 = (Person) o2.value; return p1.getAge() - p2.getAge(); } } - public class Inner { - public T value; + public class MaxHeapGreater implements MyHeap { - public Inner(T v) { - value = v; - } - } - - public class MaxHeapGreater implements MyHeap { - - private ArrayList heap; - private HashMap indexMap; + private ArrayList heap; + private HashMap indexMap; private int heapSize; - private Comparator comparator; + private Comparator comparator; - public MaxHeapGreater(Comparator comparator) { + public MaxHeapGreater(Comparator comparator) { this.heap = new ArrayList<>(); this.indexMap = new HashMap<>(); this.heapSize = 0; @@ -74,12 +67,12 @@ public boolean isFull() { } @Override - public boolean contains(Inner obj) { + public boolean contains(Node obj) { return indexMap.containsKey(obj); } @Override - public void push(Inner obj) { + public void push(Node obj) { heap.add(obj); heapInsert(heapSize++); @@ -98,8 +91,8 @@ private void heapInsert(int curIndex) { } private void swap(int i, int j) { - Inner o1 = heap.get(i); - Inner o2 = heap.get(j); + Node o1 = heap.get(i); + Node o2 = heap.get(j); heap.set(i, o2); heap.set(j, o1); indexMap.put(o2, i); @@ -107,13 +100,13 @@ private void swap(int i, int j) { } @Override - public Inner peek() { + public Node peek() { return heap.get(0); } @Override - public Inner pop() { - Inner heap0 = heap.get(0); + public Node pop() { + Node heap0 = heap.get(0); swap(0, heapSize - 1); heap.remove(--heapSize); indexMap.remove(heap0); @@ -141,11 +134,11 @@ private void sinkDown(int curIndex) { } @Override - public void remove(Inner obj) { + public void remove(Node obj) { Integer index = indexMap.get(obj); indexMap.remove(obj); - Inner replace = heap.get(heapSize - 1); + Node replace = heap.get(heapSize - 1); heap.remove(--heapSize); if (comparator.compare(obj, replace) == 0) { @@ -159,7 +152,7 @@ public void remove(Inner obj) { } @Override - public void resign(Inner obj) { + public void resign(Node obj) { Integer index = indexMap.get(obj); heapInsert(index); @@ -167,9 +160,9 @@ public void resign(Inner obj) { } @Override - public List getAllElements() { - List allElements = new ArrayList<>(); - for (Inner e : heap) { + public List getAllElements() { + List allElements = new ArrayList<>(); + for (Node e : heap) { allElements.add(e); } return allElements; diff --git "a/src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/MyUnionFind.java" "b/src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/MyUnionFind.java" new file mode 100644 index 00000000..c5836ec9 --- /dev/null +++ "b/src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/MyUnionFind.java" @@ -0,0 +1,27 @@ +package data_struct.ds3_并查集; + +/** + * Created by nibnait on 2022/11/02 + */ +public interface MyUnionFind { + + /** + * 找到 当前节点 的代表节点 + */ + T findAncestor(T cur); + + /** + * 是否在同一个集合内 + */ + boolean isSameSet(T a, T b); + + /** + * 把 a 节点,并入 b 节点所在集合中 + */ + void union(T a, T b); + + /** + * 当前一共有多少个集合 + */ + int size(); +} diff --git "a/src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/UnionFind.java" "b/src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/UnionFind.java" new file mode 100644 index 00000000..1fa0c366 --- /dev/null +++ "b/src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/UnionFind.java" @@ -0,0 +1,119 @@ +package data_struct.ds3_并查集; + +import com.google.common.collect.Lists; +import data_struct.Node; +import org.apache.commons.collections4.CollectionUtils; +import org.junit.Assert; +import org.junit.Test; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; +import java.util.Stack; + +/** + * Created by nibnait on 2022/11/02 + */ +public class UnionFind { + + @Test + public void testCase() { + + Node node1 = Node.v(1); + Node node2 = Node.v(2); + Node node3 = Node.v(3); + Node node4 = Node.v(4); + Node node5 = Node.v(5); + + UnionFindImpl unionFind = new UnionFindImpl(Lists.newArrayList(node1, node2, node3, node4, node5)); + Assert.assertEquals(5, unionFind.size()); + Assert.assertFalse(unionFind.isSameSet(node1, node2)); + Assert.assertEquals(node1, unionFind.findAncestor(node1)); + + unionFind.union(node1, node2); + Assert.assertTrue(unionFind.isSameSet(node1, node2)); + Assert.assertEquals(4, unionFind.size()); + Assert.assertEquals(node1, unionFind.findAncestor(node2)); + + unionFind.union(node3, node4); + Assert.assertEquals(3, unionFind.size()); + Assert.assertEquals(node3, unionFind.findAncestor(node4)); + + unionFind.union(node1, node5); + Assert.assertEquals(2, unionFind.size()); + + unionFind.union(node2, node4); + Assert.assertEquals(node1, unionFind.findAncestor(node4)); + + } + + public class UnionFindImpl implements MyUnionFind { + + // 存放节点对应的直系父亲节点 + private Map fathers; + // 存放 祖先节点 对应的集合的大小。 + private Map sizeMap; + + public UnionFindImpl(List nodes) { + fathers = new HashMap<>(); + sizeMap = new HashMap<>(); + if (CollectionUtils.isEmpty(nodes)) { + return; + } + for (Node node : nodes) { + fathers.put(node, node); + sizeMap.put(node, 1); + } + } + + /** + * 优化点1:为了每次往上找的链 都能更短一点。 + * 可以找完之后把这一串节点全部打平,直接挂在 ancestor 下面 + */ + @Override + public Node findAncestor(Node cur) { + Stack stack = new Stack<>(); + while (cur != fathers.get(cur)) { + stack.push(cur); + cur = fathers.get(cur); + } + + while (!stack.isEmpty()) { + Node node = stack.pop(); + fathers.put(node, cur); + } + return cur; + } + + @Override + public boolean isSameSet(Node a, Node b) { + return findAncestor(a) == findAncestor(b); + } + + /** + * 优化点2:为了链的长度涨的慢一点。 + * 可以小集合的头节点 往大集合上挂。 + */ + @Override + public void union(Node a, Node b) { + Node aHead = findAncestor(a); + Node bHead = findAncestor(b); + if (aHead == bHead) { + return; + } + + Integer aSize = sizeMap.get(aHead); + Integer bSize = sizeMap.get(bHead); + Node big = aSize >= bSize ? aHead : bHead; + Node small = big == aHead ? bHead : aHead; + fathers.put(small, big); + sizeMap.put(big, aSize + bSize); + sizeMap.remove(small); + } + + @Override + public int size() { + return sizeMap.size(); + } + } +} diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java index f2170a29..2af185ad 100644 --- a/src/main/test/UnitTestDemo.java +++ b/src/main/test/UnitTestDemo.java @@ -31,4 +31,13 @@ public void testCase() { } } + @Test + public void test() { + boolean f1 = true; + boolean f2 = false; + + f1 = f1 || f2; + System.out.println(f1); + } + } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" index 27321f08..01468695 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" @@ -8,7 +8,7 @@ Master 公式: - 如果 log(b,a) == d, 复杂度为 O(N^d * logN) ### 堆 和 加强堆 -[堆相关](../../../data_struct/堆) +[堆相关](../../../java/data_struct/ds1_堆) ### 排序算法总结 diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" new file mode 100644 index 00000000..24308b9f --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" @@ -0,0 +1,53 @@ +package algorithmzuo.b_体系学习班.c0400_并查集; + +import org.junit.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/03 + */ +public class Code01_FriendCircles { + + @Test + public void testCase() { + int[][] M = new int[][]{ + {1, 1, 0}, + {1, 1, 0}, + {0, 0, 1} + }; + int circleNum = findCircleNum(M); + Assert.assertEquals(1, circleNum); + + M = new int[][]{ + {1, 1, 0}, + {1, 1, 1}, + {0, 1, 1} + }; + circleNum = findCircleNum(M); + Assert.assertEquals(1, circleNum); + + M = new int[][]{ + {1, 1, 0, 0, 0, 0}, + {1, 1, 0, 0, 0, 0}, + {0, 0, 1, 1, 1, 0}, + {0, 0, 1, 1, 0, 0}, + {0, 0, 1, 0, 1, 0}, + {0, 0, 0, 0, 0, 1} + }; + circleNum = findCircleNum(M); + Assert.assertEquals(1, circleNum); + } + + /** + * https://leetcode.cn/problems/number-of-provinces/ + *

+ * 有 n 个城市,其中一些彼此相连,另一些没有相连。如果城市 a 与城市 b 直接相连,且城市 b 与城市 c 直接相连,那么城市 a 与城市 c 间接相连。 + * 省份 是一组直接或间接相连的城市,组内不含其他没有相连的城市。 + * 给你一个 n x n 的矩阵 isConnected ,其中 isConnected[i][j] = 1 表示第 i 个城市和第 j 个城市直接相连,而 isConnected[i][j] = 0 表示二者不直接相连。 + * 返回矩阵中 省份 的数量。 + */ + protected int findCircleNum(int[][] M) { + return 1; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" new file mode 100644 index 00000000..411c0910 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" @@ -0,0 +1,198 @@ +package algorithmzuo.b_体系学习班.c0400_并查集; + +import common.util.CopyUtil; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.*; + +/** + * Created by nibnait on 2022/11/03 + */ +public class Code02_NumberOfIslands { + + @Test + public void test() { + int row = 0; + int col = 0; + char[][] board1 = null; + char[][] board2 = null; + char[][] board3 = null; + long start = 0; + long end = 0; + + row = 1000; + col = 1000; + board1 = SysRandom.randomMatrix(row, col); + board2 = CopyUtil.copy(board1); + board3 = CopyUtil.copy(board1); + + System.out.println("感染方法、并查集(map实现)、并查集(数组实现)的运行结果和运行时间"); + System.out.println("随机生成的二维矩阵规模 : " + row + " * " + col); + + start = System.currentTimeMillis(); + System.out.println("感染方法的运行结果: " + numIslands3(board1)); + end = System.currentTimeMillis(); + System.out.println("感染方法的运行时间: " + (end - start) + " ms"); + + start = System.currentTimeMillis(); + System.out.println("并查集(map实现)的运行结果: " + numIslands1(board2)); + end = System.currentTimeMillis(); + System.out.println("并查集(map实现)的运行时间: " + (end - start) + " ms"); + + start = System.currentTimeMillis(); + System.out.println("并查集(数组实现)的运行结果: " + numIslands2(board3)); + end = System.currentTimeMillis(); + System.out.println("并查集(数组实现)的运行时间: " + (end - start) + " ms"); + + System.out.println(); + + row = 10000; + col = 10000; + board1 = SysRandom.randomMatrix(row, col); + board3 = CopyUtil.copy(board1); + System.out.println("感染方法、并查集(数组实现)的运行结果和运行时间"); + System.out.println("随机生成的二维矩阵规模 : " + row + " * " + col); + + start = System.currentTimeMillis(); + System.out.println("感染方法的运行结果: " + numIslands3(board1)); + end = System.currentTimeMillis(); + System.out.println("感染方法的运行时间: " + (end - start) + " ms"); + + start = System.currentTimeMillis(); + System.out.println("并查集(数组实现)的运行结果: " + numIslands2(board3)); + end = System.currentTimeMillis(); + System.out.println("并查集(数组实现)的运行时间: " + (end - start) + " ms"); + + } + + /** + * https://leetcode.cn/problems/number-of-islands/ + * 给你一个由 '1'(陆地)和 '0'(水)组成的的二维网格,请你计算网格中岛屿的数量。 + * 岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。 + * 此外,你可以假设该网格的四条边均被水包围。 + */ + protected int numIslands1(char[][] board) { + int rows = board.length; + int cols = board[0].length; + Dot[][] dots = new Dot[rows][cols]; + List dotList = new ArrayList<>(); + for (int i = 0; i < rows; i++) { + for (int j = 0; j < cols; j++) { + dots[i][j] = new Dot(); + dotList.add(dots[i][j]); + } + } + + UnionFind1 unionFind = new UnionFind1(dotList); + + // 第1列 + for (int i = 1; i < rows; i++) { + if (board[i - 1][0] == '1' && board[i][0] == '1') { + unionFind.union(dots[i - 1][0], dots[i][0]); + } + } + + // 第1排 + for (int i = 1; i < cols; i++) { + if (board[0][i - 1] == '1' && board[0][i] == '1') { + unionFind.union(dots[0][i - 1], dots[0][i]); + } + } + + // (1, 1) 开始,和它的左边+上边 union + for (int i = 1; i < rows; i++) { + for (int j = 1; j < cols; j++) { + if (board[i][j] == '1' && board[i - 1][j] == '1') { + unionFind.union(dots[i][j], dots[i - 1][j]); + } + if (board[i][j] == '1' && board[i][j - 1] == '1') { + unionFind.union(dots[i][j], dots[i][j - 1]); + } + } + } + + return unionFind.size(); + } + + private class Dot { + } + + private class UnionFind1 { + private Map fathers; + private Map sizeMap; + + public UnionFind1(List dotList) { + fathers = new HashMap<>(); + sizeMap = new HashMap<>(); + for (Dot dot : dotList) { + fathers.put(dot, dot); + sizeMap.put(dot, 1); + } + } + + public Dot findAncestor(Dot dot) { + Stack stack = new Stack<>(); + while (dot != fathers.get(dot)) { + stack.push(dot); + dot = fathers.get(dot); + } + while (!stack.isEmpty()) { + Dot d = stack.pop(); + fathers.put(d, dot); + } + return dot; + } + + public void union(Dot d1, Dot d2) { + Dot d1Head = findAncestor(d1); + Dot d2Head = findAncestor(d2); + if (d1Head == d2Head) { + return; + } + + Integer d1Size = sizeMap.get(d1Head); + Integer d2Size = sizeMap.get(d2Head); + Dot big = d1Size > d2Size ? d1Head : d2Head; + Dot small = big == d1Head ? d2Head : d1Head; + fathers.put(small, big); + sizeMap.put(big, d1Size + d2Size); + sizeMap.remove(small); + } + + public int size() { + return sizeMap.size(); + } + + } + + protected int numIslands2(char[][] board) { + return 1; + } + + protected int numIslands3(char[][] board) { + int isLands = 0; + for (int i = 0; i < board.length; i++) { + for (int j = 0; j < board[0].length; j++) { + if (board[i][j] == '1') { + isLands++; + infect(board, i, j); + } + } + } + return isLands; + } + + private void infect(char[][] board, int i, int j) { + if (i < 0 || i >= board.length || j < 0 || j >= board[0].length || board[i][j] != '1') { + return; + } + + board[i][j] = '2'; + infect(board, i - 1, j); + infect(board, i, j - 1); + infect(board, i + 1, j); + infect(board, i, j + 1); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code03_NumberOfIslandsII.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code03_NumberOfIslandsII.java" new file mode 100644 index 00000000..1f7ff534 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code03_NumberOfIslandsII.java" @@ -0,0 +1,11 @@ +package algorithmzuo.b_体系学习班.c0400_并查集; + +/** + * Created by nibnait on 2022/11/03 + */ +public class Code03_NumberOfIslandsII { + + /** + * https://leetcode.com/problems/number-of-islands-ii/ + */ +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" new file mode 100644 index 00000000..edebd134 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" @@ -0,0 +1,10 @@ +## 并查集 +[并查集 数据结构](../../../java/data_struct/ds3_并查集) + + +一群朋友中,有几个不相交的朋友圈 +Leetcode题目:https://leetcode.com/problems/friend-circles/ + +岛问题(递归解法 + 并查集解法 + 并行解法) +给定一个二维数组matrix,里面的值不是1就是0,上、下、左、右相邻的1认为是一片岛,返回matrix中岛的数量 + From 0a89c077ee2db8a4ac6a0860578c505ef79f8ecd Mon Sep 17 00:00:00 2001 From: tianbin Date: Sun, 6 Nov 2022 23:18:03 +0800 Subject: [PATCH 24/36] =?UTF-8?q?feat=20=E5=9B=BE?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../List\347\261\273.java" | 33 ++++ .../data_struct/ds1_\345\240\206/Heap.java" | 4 +- .../ds1_\345\240\206/HeapGreater.java" | 6 +- .../data_struct/ds4_\345\233\276/Edge.java" | 19 ++ .../data_struct/ds4_\345\233\276/Graph.java" | 68 ++------ .../ds4_\345\233\276/GraphGenerator.java" | 42 +++++ .../data_struct/ds4_\345\233\276/Node.java" | 30 ++++ .../ds4_\345\233\276/adjoin_map/BFS.java" | 2 +- .../ds4_\345\233\276/adjoin_map/DFS.java" | 2 +- .../ds4_\345\233\276/adjoin_map/Graph.java" | 67 +++++++ .../Code04_1_MergeSort_Recursion.java" | 2 +- .../Code05_1_PartitionAndQuickSort.java" | 6 +- ...5_2_QuickSortRecursionAndUnrecursion.java" | 4 +- .../Code06_1_HeapSort.java" | 8 +- .../Code01_IsBalanced.java" | 2 +- .../Code02_IsBST.java" | 2 +- .../Code03_MaxDistance.java" | 2 +- .../Code04_IsFull.java" | 4 +- .../Code05_MaxSubBSTSize.java" | 2 +- .../Code06_IsCBT.java" | 2 +- .../Code08_lowestAncestor.java" | 2 +- .../Code09_MaxHappy.java" | 2 +- .../Code01_FriendCircles.java" | 2 +- .../Code02_NumberOfIslands.java" | 6 +- ...x_\345\271\266\346\237\245\351\233\206.md" | 6 +- .../c0500_\345\233\276.md" | 46 +++++ .../c0500_\345\233\276/Code01_BFS.java" | 43 +++++ .../c0500_\345\233\276/Code02_DFS.java" | 45 +++++ .../Code03_1_TopologySort.java" | 46 +++++ .../Code03_2_TopologicalOrderBFS.java" | 64 +++++++ .../Code03_3_TopologicalOrderDFS.java" | 79 +++++++++ .../c0500_\345\233\276/Code04_Kruskal.java" | 97 ++++++++++ .../c0500_\345\233\276/Code05_Prim.java" | 106 +++++++++++ .../Code06_1_Dijkstra.java" | 62 +++++++ .../Code06_2_Dijkstra.java" | 133 ++++++++++++++ .../Code07_NetworkDelayTime.java" | 165 ++++++++++++++++++ ...01\347\232\204\351\200\222\345\275\222.md" | 14 ++ .../Code01_Hanoi.java" | 7 + ...50\346\200\201\350\247\204\345\210\222.md" | 17 ++ .../Code01_RobotWalk.java" | 7 + 40 files changed, 1166 insertions(+), 90 deletions(-) create mode 100644 "src/main/java/data_struct/ds4_\345\233\276/Edge.java" create mode 100644 "src/main/java/data_struct/ds4_\345\233\276/GraphGenerator.java" create mode 100644 "src/main/java/data_struct/ds4_\345\233\276/Node.java" rename "src/main/java/data_struct/ds4_\345\233\276/BFS.java" => "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/BFS.java" (98%) rename "src/main/java/data_struct/ds4_\345\233\276/DFS.java" => "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/DFS.java" (98%) create mode 100644 "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/Graph.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276.md" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code01_BFS.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code02_DFS.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_1_TopologySort.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_2_TopologicalOrderBFS.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_3_TopologicalOrderDFS.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code04_Kruskal.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code05_Prim.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_1_Dijkstra.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_2_Dijkstra.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code07_NetworkDelayTime.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" diff --git "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" index 48dc04eb..6efd9565 100644 --- "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" @@ -1,5 +1,7 @@ package cc.tianbin.java.集合; +import org.junit.Test; + import java.util.*; import java.util.concurrent.BlockingQueue; @@ -23,4 +25,35 @@ public static void main(String[] args) { } + + @Test + public void test01() { + // grow 了几次? + List list = new ArrayList<>(0); + // grow 了几次 +// List list = new ArrayList<>(); + list.add(1); + list.add(2); + list.add(3); + list.add(4); + list.add(5); + list.add(6); + list.add(7); + list.add(8); + list.add(9); + list.add(10); + } + + @Test + public void test02() { + // 代码里的一些固定长度的list,可以用。 + // 无法对都不能对这份儿list进行 add remove 操作,只能修改单个索引下的值 + List list1 = Arrays.asList(); + list1.add(""); + + // 使用场景:一个 if/else 里面需要返回 空list 的时候。 + // 使用它,不需要再进行创建对象 + List list2 = Collections.emptyList(); + list2.add("a"); + } } \ No newline at end of file diff --git "a/src/main/java/data_struct/ds1_\345\240\206/Heap.java" "b/src/main/java/data_struct/ds1_\345\240\206/Heap.java" index c8ab8bf9..8ccf4aae 100644 --- "a/src/main/java/data_struct/ds1_\345\240\206/Heap.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/Heap.java" @@ -91,7 +91,7 @@ public Integer peek() { public Integer pop() { int heap0 = heap[0]; SwapUtil.swap(heap, 0, --heapSize); - sinkDown(0); + heapify(0); return heap0; } @@ -99,7 +99,7 @@ public Integer pop() { * 当前 heap[0] 为原来的 heap[heapSize-1] * 所以要把 heap[0] 往下调一调 */ - private void sinkDown(int curIndex) { + private void heapify(int curIndex) { int leftChildIndex = curIndex * 2 + 1; while (leftChildIndex < heapSize) { int largerChildIndex = leftChildIndex + 1 < heapSize && heap[leftChildIndex] < heap[leftChildIndex + 1] diff --git "a/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" index 854ba63e..3056b238 100644 --- "a/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" @@ -111,11 +111,11 @@ public Node pop() { heap.remove(--heapSize); indexMap.remove(heap0); - sinkDown(0); + heapify(0); return heap0; } - private void sinkDown(int curIndex) { + private void heapify(int curIndex) { int leftChildIndex = curIndex * 2 + 1; while (leftChildIndex < heapSize) { int largerChildIndex = leftChildIndex + 1 < heapSize && comparator.compare(heap.get(leftChildIndex + 1), heap.get(leftChildIndex)) > 0 @@ -156,7 +156,7 @@ public void resign(Node obj) { Integer index = indexMap.get(obj); heapInsert(index); - sinkDown(index); + heapify(index); } @Override diff --git "a/src/main/java/data_struct/ds4_\345\233\276/Edge.java" "b/src/main/java/data_struct/ds4_\345\233\276/Edge.java" new file mode 100644 index 00000000..c4d56cd8 --- /dev/null +++ "b/src/main/java/data_struct/ds4_\345\233\276/Edge.java" @@ -0,0 +1,19 @@ +package data_struct.ds4_图; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Edge { + + public int weight; + + public Node from; + + public Node to; + + public Edge(int weight, Node from, Node to) { + this.weight = weight; + this.from = from; + this.to = to; + } +} diff --git "a/src/main/java/data_struct/ds4_\345\233\276/Graph.java" "b/src/main/java/data_struct/ds4_\345\233\276/Graph.java" index 1eaa488b..00123190 100644 --- "a/src/main/java/data_struct/ds4_\345\233\276/Graph.java" +++ "b/src/main/java/data_struct/ds4_\345\233\276/Graph.java" @@ -1,67 +1,21 @@ package data_struct.ds4_图; -import lombok.Getter; - -import java.io.BufferedInputStream; -import java.io.IOException; -import java.io.InputStream; -import java.util.*; +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; /** - * 图的表示,本书使用邻接表数组(adjoin) + * Created by nibnait on 2022/11/06 */ -@Getter public class Graph { - private int edgeCount; //边的数目 - private Map> adjoinMap; //邻接表(使用Set 为了避免平行边) + public Map nodes; - /** - * 从文件初始化图 - * 文件格式: - * vertexCount 第一个数字:顶点的数目 - * edgeCount 第二个数字:边的数目 - * x y 接下来的没两个点组合成一条边 - * x z - * - * @param filePath - * @throws IOException - */ - public Graph(String filePath) throws IOException { - InputStream inputStream = this.getClass().getResourceAsStream(filePath ); - Scanner scanner = new Scanner(new BufferedInputStream(inputStream)); - this.init(scanner.nextInt()); - scanner.nextLine(); - for (int i = 0; i < this.edgeCount; i++) { - //将每个顶点所对应的边,放入邻接表数组中 - String[] split = scanner.nextLine().split(" "); - String x = split[0]; - String y = split[1]; - addEdge(x, y); - addEdge(y, x); //无向图 - } - } + public Set edges; - private void addEdge(String x, String y) { - Set adjoinVertexSet = adjoinMap.get(x); - if (adjoinVertexSet != null) { - adjoinVertexSet.add(y); - adjoinMap.put(x, adjoinVertexSet); - } else { - adjoinVertexSet = new HashSet<>(); - adjoinVertexSet.add(y); - adjoinMap.put(x, adjoinVertexSet); - } + public Graph() { + nodes = new HashMap<>(); + edges = new HashSet<>(); } - - /** - * 初始化边和顶点,以及邻接Set表 - * - * @param edgeCount - */ - private void init(int edgeCount) { - this.edgeCount = edgeCount; - this.adjoinMap = new HashMap<>(); - } - -} \ No newline at end of file +} diff --git "a/src/main/java/data_struct/ds4_\345\233\276/GraphGenerator.java" "b/src/main/java/data_struct/ds4_\345\233\276/GraphGenerator.java" new file mode 100644 index 00000000..accf2755 --- /dev/null +++ "b/src/main/java/data_struct/ds4_\345\233\276/GraphGenerator.java" @@ -0,0 +1,42 @@ +package data_struct.ds4_图; + +/** + * Created by nibnait on 2022/11/06 + */ +public class GraphGenerator { + + + /** + * matrix 为一个 N*3 的矩阵,表示一个图中的所有边 + * [weight, from节点上的值, to节点上的值] + *

+ * [5, 0, 7] + * [3, 0, 1] + */ + public static Graph createGraph(int[][] matrix) { + Graph graph = new Graph(); + for (int i = 0; i < matrix.length; i++) { + // 拿到每一条边, matrix[i] + int weight = matrix[i][0]; + int from = matrix[i][1]; + int to = matrix[i][2]; + if (!graph.nodes.containsKey(from)) { + graph.nodes.put(from, new Node(from)); + } + if (!graph.nodes.containsKey(to)) { + graph.nodes.put(to, new Node(to)); + } + Node fromNode = graph.nodes.get(from); + Node toNode = graph.nodes.get(to); + Edge newEdge = new Edge(weight, fromNode, toNode); + fromNode.nexts.add(toNode); + fromNode.out++; + toNode.in++; + fromNode.edges.add(newEdge); + graph.edges.add(newEdge); + } + + return graph; + } + +} diff --git "a/src/main/java/data_struct/ds4_\345\233\276/Node.java" "b/src/main/java/data_struct/ds4_\345\233\276/Node.java" new file mode 100644 index 00000000..1b4675f2 --- /dev/null +++ "b/src/main/java/data_struct/ds4_\345\233\276/Node.java" @@ -0,0 +1,30 @@ +package data_struct.ds4_图; + +import java.util.ArrayList; +import java.util.List; + +/** + * 图中的点 + * Created by nibnait on 2022/11/06 + */ +public class Node { + + // 当前点的 值 + public int value; + // 入度 + public int in; + // 出度 + public int out; + // 从当前点出发的 下一个点 + public List nexts; + // 从当前点出发的 边 + public List edges; + + public Node(int value) { + this.value = value; + in = 0; + out = 0; + nexts = new ArrayList<>(); + edges = new ArrayList<>(); + } +} diff --git "a/src/main/java/data_struct/ds4_\345\233\276/BFS.java" "b/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/BFS.java" similarity index 98% rename from "src/main/java/data_struct/ds4_\345\233\276/BFS.java" rename to "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/BFS.java" index 5dc09458..086e1e28 100644 --- "a/src/main/java/data_struct/ds4_\345\233\276/BFS.java" +++ "b/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/BFS.java" @@ -1,4 +1,4 @@ -package data_struct.ds4_图; +package data_struct.ds4_图.adjoin_map; import common.util.SysOut; import junit.framework.TestCase; diff --git "a/src/main/java/data_struct/ds4_\345\233\276/DFS.java" "b/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/DFS.java" similarity index 98% rename from "src/main/java/data_struct/ds4_\345\233\276/DFS.java" rename to "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/DFS.java" index d3d0636e..994d4600 100644 --- "a/src/main/java/data_struct/ds4_\345\233\276/DFS.java" +++ "b/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/DFS.java" @@ -1,4 +1,4 @@ -package data_struct.ds4_图; +package data_struct.ds4_图.adjoin_map; import common.util.SysOut; import junit.framework.TestCase; diff --git "a/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/Graph.java" "b/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/Graph.java" new file mode 100644 index 00000000..2cac3f2e --- /dev/null +++ "b/src/main/java/data_struct/ds4_\345\233\276/adjoin_map/Graph.java" @@ -0,0 +1,67 @@ +package data_struct.ds4_图.adjoin_map; + +import lombok.Getter; + +import java.io.BufferedInputStream; +import java.io.IOException; +import java.io.InputStream; +import java.util.*; + +/** + * 图的表示,本书使用邻接表数组(adjoin) + */ +@Getter +public class Graph { + + private int edgeCount; //边的数目 + private Map> adjoinMap; //邻接表(使用Set 为了避免平行边) + + /** + * 从文件初始化图 + * 文件格式: + * vertexCount 第一个数字:顶点的数目 + * edgeCount 第二个数字:边的数目 + * x y 接下来的没两个点组合成一条边 + * x z + * + * @param filePath + * @throws IOException + */ + public Graph(String filePath) throws IOException { + InputStream inputStream = this.getClass().getResourceAsStream(filePath ); + Scanner scanner = new Scanner(new BufferedInputStream(inputStream)); + this.init(scanner.nextInt()); + scanner.nextLine(); + for (int i = 0; i < this.edgeCount; i++) { + //将每个顶点所对应的边,放入邻接表数组中 + String[] split = scanner.nextLine().split(" "); + String x = split[0]; + String y = split[1]; + addEdge(x, y); + addEdge(y, x); //无向图 + } + } + + private void addEdge(String x, String y) { + Set adjoinVertexSet = adjoinMap.get(x); + if (adjoinVertexSet != null) { + adjoinVertexSet.add(y); + adjoinMap.put(x, adjoinVertexSet); + } else { + adjoinVertexSet = new HashSet<>(); + adjoinVertexSet.add(y); + adjoinMap.put(x, adjoinVertexSet); + } + } + + /** + * 初始化边和顶点,以及邻接Set表 + * + * @param edgeCount + */ + private void init(int edgeCount) { + this.edgeCount = edgeCount; + this.adjoinMap = new HashMap<>(); + } + +} \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" index d933f818..772bbe4f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" @@ -56,7 +56,7 @@ private void process(int[] arr, int left, int right) { merge(arr, left, mid, right); } - protected static void merge(int[] arr, int left, int mid, int right) { + public static void merge(int[] arr, int left, int mid, int right) { int[] help = new int[right - left + 1]; int p1 = left; int p2 = mid + 1; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" index 87f96397..3982a032 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" @@ -41,7 +41,7 @@ public void testCase() { * arr[L...R], 以 arr[R] 为标准将数组划分成 * <= arr[R] || > arr[R] 两部分 */ - protected void quickSort1(int[] arr) { + public void quickSort1(int[] arr) { if (arr == null || arr.length == 1) { return; } @@ -87,7 +87,7 @@ private int netherlandsFlag1(int[] arr, int left, int right) { * arr[L...R], 以 arr[R] 为标准将数组划分为 * < arr[R] || = arr[R] || > arr[R] 三部分 */ - protected void quickSort2(int[] arr) { + public void quickSort2(int[] arr) { if (arr == null || arr.length == 1) { return; } @@ -135,7 +135,7 @@ private int[] netherlandsFlag2(int[] arr, int left, int right) { * 快排3.0 * 在快排2.0的基础上,随机选一个数组中的数,作为标准值。(不再指定 arr[R]) */ - protected void quickSort3(int[] arr) { + public void quickSort3(int[] arr) { if (arr == null || arr.length == 1) { return; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" index a0ea0b10..b161b7b4 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" @@ -39,7 +39,7 @@ public void testCase() { /** * 手写快排3.0 */ - protected void quickSortRecursion(int[] arr) { + public void quickSortRecursion(int[] arr) { if (arr == null || arr.length == 1) { return; } @@ -84,7 +84,7 @@ private int[] partition(int[] arr, int left, int right) { * 快排3.0 非递归 * 用栈实现 */ - protected void quickSortWithStack(int[] arr) { + public void quickSortWithStack(int[] arr) { if (arr == null || arr.length == 1) { return; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" index 3599c011..3727747a 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" @@ -45,20 +45,20 @@ private void heapSort(int[] arr) { // heapInsert(arr, i); // } - // sinkDown 构建一个堆。时间复杂度 O(N) + // heapify 构建一个堆。时间复杂度 O(N) for (int i = arr.length / 2; i >= 0; i--) { - sinkDown(arr, i, arr.length); + heapify(arr, i, arr.length); } int heapSize = arr.length; SwapUtil.swap(arr, 0, --heapSize); while (heapSize > 0) { - sinkDown(arr, 0, heapSize); + heapify(arr, 0, heapSize); SwapUtil.swap(arr, 0, --heapSize); } } - private void sinkDown(int[] arr, int curIndex, int heapSize) { + private void heapify(int[] arr, int curIndex, int heapSize) { int leftChildIndex = curIndex * 2 + 1; while (leftChildIndex < heapSize) { int largerChildIndex = leftChildIndex + 1 < heapSize && arr[leftChildIndex + 1] > arr[leftChildIndex] ? leftChildIndex + 1 : leftChildIndex; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" index ba59eb24..b75dabf3 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" @@ -35,7 +35,7 @@ public void testCase() { * 判断二叉树是不是平衡二叉树 * 即:任何一棵子树的 | 左高度 - 右高度 | <= 1 */ - protected boolean isBalanced(TreeNode head) { + public boolean isBalanced(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" index 2fb3991c..5febc383 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" @@ -40,7 +40,7 @@ public void testCase() { * 判断二叉树是不是搜索二叉树(整棵树无重复节点) * 即:任何一棵子树。都是搜索二叉树 */ - protected boolean isBST(TreeNode head) { + public boolean isBST(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" index ddc05418..d1b14e4a 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" @@ -41,7 +41,7 @@ public void testCase() { /** * 给定一棵二叉树的头节点head,任何两个节点之间都存在距离,返回整棵二叉树的最大距离 */ - protected int maxDistance(TreeNode head) { + public int maxDistance(TreeNode head) { if (head == null) { return 0; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" index 2efab373..32869e07 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" @@ -37,7 +37,7 @@ public void testCase() { /** * 判断二叉树是不是满二叉树 */ - protected boolean isFull1(TreeNode head) { + public boolean isFull1(TreeNode head) { if (head == null) { return true; } @@ -67,7 +67,7 @@ private class Info1 { /** * 法2: 只有满二叉树满足 : 2 ^ h - 1 == n */ - protected boolean isFull2(TreeNode head) { + public boolean isFull2(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" index da376592..badd8cce 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" @@ -41,7 +41,7 @@ public void testCase() { /** * 给定一棵二叉树的头节点head,返回这颗二叉树中最大的二叉搜索子树的大小 */ - protected int maxSubBSTSize(TreeNode head) { + public int maxSubBSTSize(TreeNode head) { if (head == null) { return 0; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" index ff42323b..320e1e58 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" @@ -38,7 +38,7 @@ public void testCase() { /** * 判断二叉树是不是完全二叉树(正在变成满二叉树的过程中) */ - protected boolean isCBT(TreeNode head) { + public boolean isCBT(TreeNode head) { if (head == null) { return true; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" index cf5de95d..06a4b00c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" @@ -75,7 +75,7 @@ public void testSpecialCase() { /** * 给定一棵二叉树的头节点head,和另外两个节点a和b,返回a和b的最低公共祖先 */ - protected TreeNode lowestAncestor(TreeNode head, TreeNode a, TreeNode b) { + public TreeNode lowestAncestor(TreeNode head, TreeNode a, TreeNode b) { if (head == null) { return null; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" index 81982b2c..9def25b0 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" @@ -63,7 +63,7 @@ class Employee { 给定一个由字符串组成的数组strs,必须把所有的字符串拼接起来,返回所有可能的拼接结果中字典序最小的结果 */ - protected TreeNode maxHappy(Employee boss) { + public TreeNode maxHappy(Employee boss) { return null; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" index 24308b9f..4a44a99f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" @@ -46,7 +46,7 @@ public void testCase() { * 给你一个 n x n 的矩阵 isConnected ,其中 isConnected[i][j] = 1 表示第 i 个城市和第 j 个城市直接相连,而 isConnected[i][j] = 0 表示二者不直接相连。 * 返回矩阵中 省份 的数量。 */ - protected int findCircleNum(int[][] M) { + public int findCircleNum(int[][] M) { return 1; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" index 411c0910..09e1ae66 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" @@ -72,7 +72,7 @@ public void test() { * 岛屿总是被水包围,并且每座岛屿只能由水平方向和/或竖直方向上相邻的陆地连接形成。 * 此外,你可以假设该网格的四条边均被水包围。 */ - protected int numIslands1(char[][] board) { + public int numIslands1(char[][] board) { int rows = board.length; int cols = board[0].length; Dot[][] dots = new Dot[rows][cols]; @@ -166,11 +166,11 @@ public int size() { } - protected int numIslands2(char[][] board) { + public int numIslands2(char[][] board) { return 1; } - protected int numIslands3(char[][] board) { + public int numIslands3(char[][] board) { int isLands = 0; for (int i = 0; i < board.length; i++) { for (int j = 0; j < board[0].length; j++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" index edebd134..3dec4ba1 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" @@ -2,9 +2,9 @@ [并查集 数据结构](../../../java/data_struct/ds3_并查集) -一群朋友中,有几个不相交的朋友圈 -Leetcode题目:https://leetcode.com/problems/friend-circles/ +一群朋友中,有几个不相交的朋友圈 +Leetcode题目: -岛问题(递归解法 + 并查集解法 + 并行解法) +岛问题(递归解法 + 并查集解法 + 并行解法) 给定一个二维数组matrix,里面的值不是1就是0,上、下、左、右相邻的1认为是一片岛,返回matrix中岛的数量 diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276.md" new file mode 100644 index 00000000..6e6fee4d --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276.md" @@ -0,0 +1,46 @@ +## 图及其与图相关的算法 + +### [图的数据结构抽象](../../../java/data_struct/ds4_图/Graph.java) +不管题目里的图是怎么表示的,都先把它转成自己的图结构。 +[GraphGenerator](../../../java/data_struct/ds4_图/GraphGenerator.java) + +### BFS +[Code01_BFS](./c0500_图/Code01_BFS.java) + +### DFS +[Code02_DFS](./c0500_图/Code02_DFS.java) + +### 拓扑排序(有向无环图) + + - [Code03_1_TopologySort](./c0500_图/Code03_1_TopologySort.java) + - [Code03_2_TopologicalOrderBFS](./c0500_图/Code03_2_TopologicalOrderBFS.java) + - [Code03_3_TopologicalOrderDFS](./c0500_图/Code03_3_TopologicalOrderDFS.java) + +### 最小生成树算法之Kruskal +[Code04_Kruskal](./c0500_图/Code04_Kruskal.java) + + 用`并查集`实现Kruskal算法 + 1)总是从权值最小的边开始考虑,依次考察权值依次变大的边 + 2)当前的边要么进入最小生成树的集合,要么丢弃 + 3)如果当前的边进入最小生成树的集合中不会形成环,就要当前边 + 4)如果当前的边进入最小生成树的集合中会形成环,就不要当前边 + 5)考察完所有边之后,最小生成树的集合也得到了 + +### 最小生成树算法之Prim +[Code05_Prim](./c0500_图/Code05_Prim.java) + + 用`堆`实现Prim算法 + 1)可以从任意节点出发来寻找最小生成树 + 2)某个点加入到被选取的点中后,解锁这个点出发的所有新的边 + 3)在所有解锁的边中选最小的边,然后看看这个边会不会形成环 + 4)如果会,不要当前边,继续考察剩下解锁的边中最小的边,重复3) + 5)如果不会,要当前边,将该边的指向点加入到被选取的点中,重复2) + 6)当所有点都被选取,最小生成树就得到了 + +### Dijkstra算法(有向无负权重的图) + - [Code06_1_Dijkstra](./c0500_图/Code06_1_Dijkstra.java) + - 加强堆实现Dijkstra算法 [Code06_2_Dijkstra](./c0500_图/Code06_2_Dijkstra.java) + +### 网络延迟时间 + +[Code07_NetworkDelayTime](./c0500_图/Code07_NetworkDelayTime.java) \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code01_BFS.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code01_BFS.java" new file mode 100644 index 00000000..316e2563 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code01_BFS.java" @@ -0,0 +1,43 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Node; +import org.junit.Test; + +import java.util.*; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code01_BFS { + + @Test + public void test() { + + } + + public List bfs(Node start) { + List travelArr = new ArrayList<>(); + if (start == null) { + return travelArr; + } + + Queue queue = new LinkedList(); + Set set = new HashSet<>(); + queue.add(start); + set.add(start); + while (!queue.isEmpty()) { + Node cur = queue.poll(); + travelArr.add(cur); + + for (Node next : cur.nexts) { + if (!set.contains(next)) { + queue.add(next); + set.add(next); + } + } + } + + return travelArr; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code02_DFS.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code02_DFS.java" new file mode 100644 index 00000000..a8c1d896 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code02_DFS.java" @@ -0,0 +1,45 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Node; +import org.junit.Test; + +import java.util.*; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code02_DFS { + + @Test + public void test() { + + } + + public List dfs(Node start) { + List travelArr = new ArrayList<>(); + if (start == null) { + return travelArr; + } + + Stack stack = new Stack(); + Set set = new HashSet<>(); + stack.push(start); + set.add(start); + travelArr.add(start); + while (!stack.isEmpty()) { + Node cur = stack.pop(); + for (Node next : cur.nexts) { + if (!set.contains(next)) { + stack.push(cur); + stack.push(next); + set.add(next); + travelArr.add(next); + break; + } + } + } + + return travelArr; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_1_TopologySort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_1_TopologySort.java" new file mode 100644 index 00000000..421db9fb --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_1_TopologySort.java" @@ -0,0 +1,46 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Graph; +import data_struct.ds4_图.Node; + +import java.util.*; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code03_1_TopologySort { + + /** + * 有向无环图 + */ + public List topSort(Graph graph) { + + // 每个节点的剩余入度 + Map inDegreeMap = new HashMap<>(); + // 没有入度的节点 + Queue zeroInDegreeQueue = new LinkedList<>(); + + for (Node node : graph.nodes.values()) { + inDegreeMap.put(node, node.in); + if (node.in == 0) { + zeroInDegreeQueue.add(node); + } + } + + List result = new ArrayList<>(); + while (!zeroInDegreeQueue.isEmpty()) { + Node cur = zeroInDegreeQueue.poll(); + result.add(cur); + for (Node next : cur.nexts) { + inDegreeMap.put(next, inDegreeMap.get(next) - 1); + if (inDegreeMap.get(next) == 0) { + zeroInDegreeQueue.add(next); + } + } + } + + return result; + } + + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_2_TopologicalOrderBFS.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_2_TopologicalOrderBFS.java" new file mode 100644 index 00000000..0c0d89e6 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_2_TopologicalOrderBFS.java" @@ -0,0 +1,64 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import org.junit.Test; + +import java.util.*; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code03_2_TopologicalOrderBFS { + + public static class DirectedGraphNode { + public int label; + public ArrayList neighbors; + + public DirectedGraphNode(int x) { + label = x; + neighbors = new ArrayList(); + } + } + + @Test + public void test() { + + } + + /** + * https://www.lintcode.com/problem/topological-sorting + */ + public ArrayList topSort(ArrayList graph) { + HashMap inDegreeMap = new HashMap<>(); + for (DirectedGraphNode node : graph) { + inDegreeMap.put(node, 0); + } + for (DirectedGraphNode node : graph) { + for (DirectedGraphNode next : node.neighbors) { + inDegreeMap.put(next, inDegreeMap.get(next) + 1); + } + } + + Queue zeroInDegreeQueue = new LinkedList<>(); + for (DirectedGraphNode node : inDegreeMap.keySet()) { + if (inDegreeMap.get(node) == 0) { + zeroInDegreeQueue.add(node); + } + } + + ArrayList result = new ArrayList<>(); + while (!zeroInDegreeQueue.isEmpty()) { + DirectedGraphNode node = zeroInDegreeQueue.poll(); + result.add(node); + for (DirectedGraphNode next : node.neighbors) { + inDegreeMap.put(next, inDegreeMap.get(next) - 1); + if (inDegreeMap.get(next) == 0) { + zeroInDegreeQueue.add(next); + } + } + } + + return result; + } + + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_3_TopologicalOrderDFS.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_3_TopologicalOrderDFS.java" new file mode 100644 index 00000000..57cec6fc --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_3_TopologicalOrderDFS.java" @@ -0,0 +1,79 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import org.junit.Test; + +import java.util.*; +import java.util.stream.Collectors; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code03_3_TopologicalOrderDFS { + + + public static class DirectedGraphNode { + public int label; + public ArrayList neighbors; + + public DirectedGraphNode(int x) { + label = x; + neighbors = new ArrayList(); + } + } + + @Test + public void test() { + + } + + /** + * https://www.lintcode.com/problem/topological-sorting + */ + private class Record { + public DirectedGraphNode node; + public int deep; + + public Record(DirectedGraphNode node, int deep) { + this.node = node; + this.deep = deep; + } + } + + private class MyComparator implements Comparator { + @Override + public int compare(Record o1, Record o2) { + return o2.deep - o1.deep; + } + } + + /** + * 当前节点的深度越深,它的拓扑排序就越在前面 + */ + public ArrayList topSort(ArrayList graph) { + Map order = new HashMap<>(); + for (DirectedGraphNode node : graph) { + process(node, order); + } + + return order.values().stream() + .sorted(new MyComparator()) + .map(record -> record.node) + .collect(Collectors.toCollection(ArrayList::new)); + } + + private Record process(DirectedGraphNode node, Map order) { + if (order.containsKey(node)) { + return order.get(node); + } + + int deep = 0; + for (DirectedGraphNode next : node.neighbors) { + deep = Math.max(deep, process(next, order).deep); + } + + Record record = new Record(node, deep + 1); + order.put(node, record); + return record; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code04_Kruskal.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code04_Kruskal.java" new file mode 100644 index 00000000..05afb5b4 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code04_Kruskal.java" @@ -0,0 +1,97 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Node; +import data_struct.ds4_图.Edge; +import data_struct.ds4_图.Graph; +import org.junit.Test; + +import java.util.*; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code04_Kruskal { + + @Test + public void test() { + + } + + /** + * 用并查集 + * 生成一个边的权重代价最小的(将原图的所有多余的边去掉的)图 + */ + public Set KruskalMST(Graph graph) { + UnionFind unionFind = new UnionFind(graph.nodes.values()); + PriorityQueue heap = new PriorityQueue<>(new MyComparator()); + for (Edge edge : graph.edges) { + heap.add(edge); + } + + Set result = new HashSet<>(); + while (!heap.isEmpty()) { + Edge edge = heap.poll(); + if (!unionFind.isSameSet(edge.from, edge.to)) { + unionFind.union(edge.from, edge.to); + result.add(edge); + } + } + return result; + } + + private class MyComparator implements Comparator { + @Override + public int compare(Edge o1, Edge o2) { + return o1.weight - o2.weight; + } + } + + private class UnionFind { + private Map fatherMap; + private Map sizeMap; + + public UnionFind(Collection nodes) { + fatherMap = new HashMap<>(); + sizeMap = new HashMap<>(); + + for (Node node : nodes) { + fatherMap.put(node, node); + sizeMap.put(node, 1); + } + } + + public Node findAncestor(Node node) { + Stack stack = new Stack<>(); + while(node != fatherMap.get(node)) { + stack.push(node); + node = fatherMap.get(node); + } + while (!stack.isEmpty()) { + Node pop = stack.pop(); + fatherMap.put(pop, node); + } + return node; + } + + public boolean isSameSet(Node o1, Node o2) { + return findAncestor(o1) == findAncestor(o2); + } + + public void union(Node o1, Node o2) { + Node head1 = findAncestor(o1); + Node head2 = findAncestor(o2); + if (head1 == head2) { + return; + } + Integer size1 = sizeMap.get(o1); + Integer size2 = sizeMap.get(o2); + Node big = size1 > size2 ? head1 : head2; + Node small = big == head1 ? head2 : head1; + fatherMap.put(small, big); + sizeMap.put(big, size1 + size2); + sizeMap.remove(small); + } + + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code05_Prim.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code05_Prim.java" new file mode 100644 index 00000000..b19518ad --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code05_Prim.java" @@ -0,0 +1,106 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Edge; +import data_struct.ds4_图.Graph; +import data_struct.ds4_图.Node; +import org.junit.Test; + +import java.util.Comparator; +import java.util.HashSet; +import java.util.PriorityQueue; +import java.util.Set; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code05_Prim { + + @Test + public void test() { + + } + + /** + * 用小根堆 + * 生成一个边的权重代价最小的(将原图的所有多余的边去掉的)图 + * + * 从任意点开始,依次解锁从当前点出发的所有边(按边的权重排序), + */ + public Set primMST(Graph graph) { + PriorityQueue heap = new PriorityQueue<>(new MyComparator()); + Set nodeSet = new HashSet<>(); + Set result = new HashSet<>(); + for (Node node : graph.nodes.values()) { + if (nodeSet.contains(node)) { + continue; + } + nodeSet.add(node); + + for (Edge edge : node.edges) { + heap.add(edge); + } + + while (!heap.isEmpty()) { + Edge edge = heap.poll(); + Node toNode = edge.to; + if (nodeSet.contains(toNode)) { + continue; + } + nodeSet.add(toNode); + result.add(edge); + for (Edge nextEdge : toNode.edges) { + heap.add(nextEdge); + } + } + } + return result; + } + + private class MyComparator implements Comparator { + @Override + public int compare(Edge o1, Edge o2) { + return o1.weight - o2.weight; + } + } + + /** + * graph[i][j] 表示 i点 到 j点的距离,如果是 Integer.MAX_VALUE 则代表无路 + * @param graph 一个连通图 + * @return 最小连通图的路径之和 + */ + public int prim(int[][] graph) { + int size = graph.length; + int[] distance = new int[size]; + boolean[] visit = new boolean[size]; + visit[0] = true; + for (int i = 0; i < size; i++) { + distance[i] = graph[0][i]; + } + + int sum = 0; + for (int i = 1; i < size; i++) { + int minPath = Integer.MAX_VALUE; + int minIndex = -1; + for (int j = 0; j < size; j++) { + if (!visit[j] && distance[j] < minPath) { + minPath = distance[j]; + minIndex = j; + } + } + + if (minIndex == -1) { + return sum; + } + + visit[minIndex] = true; + sum += minPath; + + for (int j = 0; j < size; j++) { + if (!visit[j] && distance[j] > graph[minIndex][j]) { + distance[j] = graph[minIndex][j]; + } + } + } + return sum; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_1_Dijkstra.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_1_Dijkstra.java" new file mode 100644 index 00000000..31197c24 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_1_Dijkstra.java" @@ -0,0 +1,62 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Edge; +import data_struct.ds4_图.Node; +import org.junit.Test; + +import java.util.HashMap; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code06_1_Dijkstra { + + @Test + public void test() { + + } + + /** + * Dijkstra + * 给你一个出发点,返回从出发点 到图中所有能到达的点的最短距离 的一个map表 + */ + public Map dijkstra(Node from) { + Map distanceMap = new HashMap<>(); + distanceMap.put(from, 0); + Set selectedNodes = new HashSet<>(); + Node minNode = getMinDistanceAndUnSelectedNode(distanceMap, selectedNodes); + while (minNode != null) { + Integer distance = distanceMap.get(minNode); + for (Edge edge : minNode.edges) { + Node toNode = edge.to; + if (!distanceMap.containsKey(toNode)) { + distanceMap.put(toNode, distance + edge.weight); + } else { + distanceMap.put(toNode, Math.max(distanceMap.get(toNode), distance + edge.weight)); + } + } + selectedNodes.add(minNode); + minNode = getMinDistanceAndUnSelectedNode(distanceMap, selectedNodes); + } + return distanceMap; + } + + private Node getMinDistanceAndUnSelectedNode(Map distanceMap, Set selectedNodes) { + Node minNode = null; + int minDistance = Integer.MAX_VALUE; + for (Map.Entry entry : distanceMap.entrySet()) { + Node node = entry.getKey(); + Integer distance = entry.getValue(); + if (!selectedNodes.contains(node) && distance < minDistance) { + minNode = node; + minDistance = distance; + } + } + + return minNode; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_2_Dijkstra.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_2_Dijkstra.java" new file mode 100644 index 00000000..9e73ec31 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_2_Dijkstra.java" @@ -0,0 +1,133 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import data_struct.ds4_图.Edge; +import data_struct.ds4_图.Node; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code06_2_Dijkstra { + + + @Test + public void test() { + + } + + private class NodeRecord { + public Node node; + public int distance; + + public NodeRecord(Node node, int distance) { + this.node = node; + this.distance = distance; + } + } + + /** + * 用 加强堆 实现 Dijkstra + */ + public Map dijkstra(Node from, int size) { + NodeHeap nodeHeap = new NodeHeap(size); + nodeHeap.addOrUpdateOrIgnore(from, 0); + HashMap result = new HashMap<>(); + while (!nodeHeap.isEmpty()) { + NodeRecord record = nodeHeap.pop(); + Node cur = record.node; + int distance = record.distance; + for (Edge edge : cur.edges) { + nodeHeap.addOrUpdateOrIgnore(edge.to, edge.weight + distance); + } + result.put(cur, distance); + } + return result; + } + + private class NodeHeap { + private Node[] nodes; + private Map heapIndexMap; + private Map distanceMap; + private int size; + + public NodeHeap(int size) { + nodes = new Node[size]; + heapIndexMap = new HashMap<>(); + distanceMap = new HashMap<>(); + size = 0; + } + + public boolean isEmpty() { + return size == 0; + } + + public void addOrUpdateOrIgnore(Node node, int distance) { + if (inHeap(node)) { + // update + distanceMap.put(node, Math.min(distanceMap.get(node), distance)); + insertHeapify(node, heapIndexMap.get(node)); + } + if (!isEntered(node)) { + // add + nodes[size] = node; + heapIndexMap.put(node, size); + distanceMap.put(node, distance); + insertHeapify(node, size++); + } + } + + private void insertHeapify(Node node, Integer index) { + int fatherIndex = (index - 1) / 2; + while (distanceMap.get(nodes[index]) < distanceMap.get(nodes[fatherIndex])) { + swap(index, fatherIndex); + index = fatherIndex; + } + } + + public NodeRecord pop() { + NodeRecord nodeRecord = new NodeRecord(nodes[0], distanceMap.get(nodes[0])); + swap(0, size - 1); + heapIndexMap.put(nodes[size - 1], -1); + distanceMap.remove(nodes[size - 1]); + nodes[size - 1] = null; + heapify(0, --size); + return nodeRecord; + } + + private void heapify(int index, int size) { + int leftChild = index * 2 + 1; + while (leftChild < size) { + int smallest = leftChild + 1 < size && distanceMap.get(nodes[leftChild + 1]) < distanceMap.get(nodes[leftChild]) + ? leftChild + 1 + : leftChild; + smallest = distanceMap.get(nodes[smallest]) < distanceMap.get(nodes[index]) + ? smallest + : index; + swap(smallest, index); + index = smallest; + leftChild = index * 2 + 1; + } + } + + private void swap(Integer index1, int index2) { + heapIndexMap.put(nodes[index1], index2); + heapIndexMap.put(nodes[index2], index1); + Node tmp = nodes[index1]; + nodes[index1] = nodes[index2]; + nodes[index2] = tmp; + } + + private boolean inHeap(Node node) { + return isEntered(node) && heapIndexMap.get(node) != -1; + } + + private boolean isEntered(Node node) { + return heapIndexMap.containsKey(node); + } + + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code07_NetworkDelayTime.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code07_NetworkDelayTime.java" new file mode 100644 index 00000000..6cfe2a9f --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code07_NetworkDelayTime.java" @@ -0,0 +1,165 @@ +package algorithmzuo.b_体系学习班.c0500_图; + +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.PriorityQueue; + +/** + * Created by nibnait on 2022/11/08 + */ +public class Code07_NetworkDelayTime { + + @Test + public void test() { + + } + + /** + * https://leetcode.com/problems/network-delay-time/ + * 有 n 个网络节点,标记为 1 到 n。 + * 给你一个列表 times,表示信号经过 有向 边的传递时间。 times[i] = (ui, vi, wi),其中 ui 是源节点,vi 是目标节点, wi 是一个信号从源节点传递到目标节点的时间。 + * 现在,从某个节点 K 发出一个信号。需要多久才能使所有节点都收到信号?如果不能使所有节点收到信号,返回 -1 。 + */ + // 方法一 : 普通堆 + 屏蔽已经计算过的点 + public static int networkDelayTime1(int[][] times, int n, int k) { + ArrayList> nexts = new ArrayList<>(); + for (int i = 0; i <= n; i++) { + nexts.add(new ArrayList<>()); + } + for (int[] delay : times) { + nexts.get(delay[0]).add(new int[] { delay[1], delay[2] }); + } + PriorityQueue heap = new PriorityQueue<>((a, b) -> a[1] - b[1]); + heap.add(new int[] { k, 0 }); + boolean[] used = new boolean[n + 1]; + int num = 0; + int max = 0; + while (!heap.isEmpty() && num < n) { + int[] record = heap.poll(); + int cur = record[0]; + int delay = record[1]; + if (used[cur]) { + continue; + } + used[cur] = true; + num++; + max = Math.max(max, delay); + for (int[] next : nexts.get(cur)) { + heap.add(new int[] { next[0], delay + next[1] }); + } + } + return num < n ? -1 : max; + } + + // 方法二 : 加强堆的解法 + public static int networkDelayTime2(int[][] times, int n, int k) { + ArrayList> nexts = new ArrayList<>(); + for (int i = 0; i <= n; i++) { + nexts.add(new ArrayList<>()); + } + for (int[] delay : times) { + nexts.get(delay[0]).add(new int[] { delay[1], delay[2] }); + } + Heap heap = new Heap(n); + heap.add(k, 0); + int num = 0; + int max = 0; + while (!heap.isEmpty()) { + int[] record = heap.poll(); + int cur = record[0]; + int delay = record[1]; + num++; + max = Math.max(max, delay); + for (int[] next : nexts.get(cur)) { + heap.add(next[0], delay + next[1]); + } + } + return num < n ? -1 : max; + } + + // 加强堆 + public static class Heap { + public boolean[] used; + public int[][] heap; + public int[] hIndex; + public int size; + + public Heap(int n) { + used = new boolean[n + 1]; + heap = new int[n + 1][2]; + hIndex = new int[n + 1]; + Arrays.fill(hIndex, -1); + size = 0; + } + + public void add(int cur, int delay) { + if (used[cur]) { + return; + } + if (hIndex[cur] == -1) { + heap[size][0] = cur; + heap[size][1] = delay; + hIndex[cur] = size; + heapInsert(size++); + } else { + int hi = hIndex[cur]; + if (delay <= heap[hi][1]) { + heap[hi][1] = delay; + heapInsert(hi); + } + } + } + + public int[] poll() { + int[] ans = heap[0]; + swap(0, --size); + heapify(0); + used[ans[0]] = true; + hIndex[ans[0]] = -1; + return ans; + } + + public boolean isEmpty() { + return size == 0; + } + + private void heapInsert(int i) { + int parent = (i - 1) / 2; + while (heap[i][1] < heap[parent][1]) { + swap(i, parent); + i = parent; + parent = (i - 1) / 2; + } + } + + private void heapify(int i) { + int l = (i * 2) + 1; + while (l < size) { + int smallest = l + 1 < size && heap[l + 1][1] < heap[l][1] ? (l + 1) : l; + smallest = heap[smallest][1] < heap[i][1] ? smallest : i; + if (smallest == i) { + break; + } + swap(smallest, i); + i = smallest; + l = (i * 2) + 1; + } + } + + private void swap(int i, int j) { + int[] o1 = heap[i]; + int[] o2 = heap[j]; + int o1hi = hIndex[o1[0]]; + int o2hi = hIndex[o2[0]]; + heap[i] = o2; + heap[j] = o1; + hIndex[o1[0]] = o2hi; + hIndex[o2[0]] = o1hi; + } + + } + + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" new file mode 100644 index 00000000..68bcab87 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" @@ -0,0 +1,14 @@ +## 常见的递归 + +打印n层汉诺塔从最左边移动到最右边的全部过程(递归+非递归实现) + +打印一个字符串的全部子序列 + +打印一个字符串的全部子序列,要求不要出现重复字面值的子序列 + +打印一个字符串的全部排列 + +打印一个字符串的全部排列,要求不要出现重复的排列 + +给定一个栈,请逆序这个栈,不能申请额外的数据结构,只能使用递归函数 + diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" new file mode 100644 index 00000000..f92b4760 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" @@ -0,0 +1,7 @@ +package algorithmzuo.b_体系学习班.c0600_常见的递归; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code01_Hanoi { +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" new file mode 100644 index 00000000..2cd1ec21 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" @@ -0,0 +1,17 @@ + +假设有排成一行的N个位置记为1~N,N一定大于或等于2 +开始时机器人在其中的M位置上(M一定是1~N中的一个) +如果机器人来到1位置,那么下一步只能往右来到2位置; +如果机器人来到N位置,那么下一步只能往左来到N-1位置; +如果机器人来到中间位置,那么下一步可以往左走或者往右走; +规定机器人必须走K步,最终能来到P位置(P也是1~N中的一个)的方法有多少种 +给定四个参数 N、M、K、P,返回方法数 + + + +给定一个整型数组arr,代表数值不同的纸牌排成一条线 +玩家A和玩家B依次拿走每张纸牌 +规定玩家A先拿,玩家B后拿 +但是每个玩家每次只能拿走最左或最右的纸牌 +玩家A和玩家B都绝顶聪明 +请返回最后获胜者的分数 \ No newline at end of file diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" new file mode 100644 index 00000000..1a1b612d --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" @@ -0,0 +1,7 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +/** + * Created by nibnait on 2022/11/06 + */ +public class Code01_RobotWalk { +} From d257c8c9df065a70eb794c24ed050e1dc26e3f56 Mon Sep 17 00:00:00 2001 From: tianbin Date: Sat, 12 Nov 2022 15:30:48 +0800 Subject: [PATCH 25/36] =?UTF-8?q?feat=20=E5=B8=B8=E8=A7=81=E7=9A=84?= =?UTF-8?q?=E9=80=92=E5=BD=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../b_2nd_Season/be160817/src/Hanoi.java | 8 +- .../bg160831/src/BSTtoDoubleLinkedList.java | 16 +- .../java/\345\271\266\345\217\221/Main.java" | 10 ++ .../Map\347\261\273.java" | 161 ++++++++++++++++++ .../Set\347\261\273.java" | 31 ++++ src/main/java/common/util/SysOut.java | 21 +++ .../Code02_LessMoneySplitGold.java" | 6 +- .../Code03_BestArrange.java" | 8 +- ...01\347\232\204\351\200\222\345\275\222.md" | 15 +- .../Code01_Hanoi.java" | 109 ++++++++++++ .../Code02_PrintAllSubSequences.java" | 80 +++++++++ .../Code03_PrintAllPermutations.java" | 100 +++++++++++ .../Code04_ReverseStackUsingRecursive.java" | 56 ++++++ .../\351\233\206\345\220\210/MapTest.java" | 5 +- .../\351\233\206\345\220\210/SetTest.java" | 5 +- 15 files changed, 600 insertions(+), 31 deletions(-) create mode 100644 "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Set\347\261\273.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code02_PrintAllSubSequences.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java index 9a1be53e..9e6368d8 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java +++ b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java @@ -4,14 +4,14 @@ public class Hanoi { - public static int hanoiProblem1(int num, String left, String mid, String right) { + private static int hanoiProblem1(int num, String left, String mid, String right) { if (num < 1) { return 0; } return process(num, left, mid, right, left, right); } - public static int process(int num, String left, String mid, String right, String from, String to) { + private static int process(int num, String left, String mid, String right, String from, String to) { if (num == 1) { //只剩1个盘了 if (from.equals(mid) || to.equals(mid)) { System.out.println("Move 1 from " + from + " to " + to); @@ -45,7 +45,7 @@ public static enum Action { No, LToM, MToL, MToR, RToM } - public static int hanoiProblem2(int num, String left, String mid, String right) { + private static int hanoiProblem2(int num, String left, String mid, String right) { Stack lS = new Stack(); Stack mS = new Stack(); Stack rS = new Stack(); @@ -78,7 +78,7 @@ public static int hanoiProblem2(int num, String left, String mid, String right) * @param to * @return */ - public static int fStackTotStack(Action[] record, Action preNoAct, Action nowAct, Stack fStack, + private static int fStackTotStack(Action[] record, Action preNoAct, Action nowAct, Stack fStack, Stack tStack, String from, String to) { if (record[0] == preNoAct || fStack.peek() >= tStack.peek()) { return 0; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java index 795c8955..55b936de 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java +++ b/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java @@ -5,7 +5,7 @@ public class BSTtoDoubleLinkedList { - public static class Node { + private static class Node { public int value; public Node left; public Node right; @@ -15,7 +15,7 @@ public Node(int data) { } } - public static Node convert1(Node head) { + private static Node convert1(Node head) { Queue queue = new LinkedList(); inOrderToQueue(head, queue); if (queue.isEmpty()) { @@ -35,7 +35,7 @@ public static Node convert1(Node head) { return head; } - public static void inOrderToQueue(Node head, Queue queue) { + private static void inOrderToQueue(Node head, Queue queue) { if (head == null) { return; } @@ -44,7 +44,7 @@ public static void inOrderToQueue(Node head, Queue queue) { inOrderToQueue(head.right, queue); } - public static Node convert2(Node head) { + private static Node convert2(Node head) { if (head == null) { return null; } @@ -54,7 +54,7 @@ public static Node convert2(Node head) { return head; } - public static Node process(Node head) { + private static Node process(Node head) { if (head == null) { return null; } @@ -85,7 +85,7 @@ public static Node process(Node head) { } } - public static void printBSTInOrder(Node head) { + private static void printBSTInOrder(Node head) { System.out.print("BST in-order: "); if (head != null) { inOrderPrint(head); @@ -93,7 +93,7 @@ public static void printBSTInOrder(Node head) { System.out.println(); } - public static void inOrderPrint(Node head) { + private static void inOrderPrint(Node head) { if (head == null) { return; } @@ -102,7 +102,7 @@ public static void inOrderPrint(Node head) { inOrderPrint(head.right); } - public static void printDoubleLinkedList(Node head) { + private static void printDoubleLinkedList(Node head) { System.out.print("Double Linked List: "); Node end = null; while (head != null) { diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" index 5145f3be..412ad304 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" @@ -1,5 +1,7 @@ package cc.tianbin.java.并发; +import org.junit.Test; + import java.util.concurrent.*; import java.util.concurrent.atomic.AtomicReferenceFieldUpdater; import java.util.concurrent.locks.*; @@ -39,4 +41,12 @@ public static void main(String[] args) { } + + @Test + public void testReentrantLook() throws InterruptedException { + ReentrantLock lock = new ReentrantLock(); + lock.lock(); + lock.tryLock(); + lock.tryLock(0, null); + } } diff --git "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" index 028db407..50b8d017 100644 --- "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" @@ -1,5 +1,7 @@ package cc.tianbin.java.集合; +import org.junit.Test; + import java.util.*; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentSkipListMap; @@ -26,5 +28,164 @@ public static void main(String[] args) { ConcurrentSkipListMap concurrentSkipListMap; } + @Test + public void test01() { + // ParameterizedType + + } + +/* putVal + ** + * Implements Map.put and related methods. + * + * @param hash hash for key + * @param key the key + * @param value the value to put + * @param onlyIfAbsent if true, don't change existing value + * @param evict if false, the table is in creation mode. + * @return previous value, or null if none + * + final V putVal(int hash, K key, V value, boolean onlyIfAbsent, + boolean evict) { + HashMap.Node[] tab; HashMap.Node p; int n, i; + if ((tab = table) == null || (n = tab.length) == 0) + n = (tab = resize()).length; + if ((p = tab[i = (n - 1) & hash]) == null) + tab[i] = newNode(hash, key, value, null); + else { + HashMap.Node e; K k; + if (p.hash == hash && + ((k = p.key) == key || (key != null && key.equals(k)))) + e = p; + else if (p instanceof HashMap.TreeNode) + e = ((HashMap.TreeNode)p).putTreeVal(this, tab, hash, key, value); + else { + for (int binCount = 0; ; ++binCount) { + if ((e = p.next) == null) { + p.next = newNode(hash, key, value, null); + if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st + treeifyBin(tab, hash); + break; + } + if (e.hash == hash && + ((k = e.key) == key || (key != null && key.equals(k)))) + break; + p = e; + } + } + if (e != null) { // existing mapping for key + V oldValue = e.value; + if (!onlyIfAbsent || oldValue == null) + e.value = value; + afterNodeAccess(e); + return oldValue; + } + } + ++modCount; + if (++size > threshold) + resize(); + afterNodeInsertion(evict); + return null; + } + //如果一个hashmap.里边有1g00个元素。 + //我们可以通过ut方法的返回值,进行一个是否有数值覆盖的判断、 + //如果有的业务逻辑从上层业务需求上,就可以肯定歌ey绝对是唯一的。那么这个时候,如果我们使跳ashmap + //进行数据的维护添加的话,好的代码需要使用到这个特性来保证我们的业务的伽y确实是唯一的 + //如果发现我们的put方法的返回值有值的话。擦,那说明业务伽y不唯一了,可以根据业务需求,直接抛出异常 + //通过代码,进行二次的校验。 + + //这时候己经写入了。那么我想问下一下,我们的的返回值是什么? + //返回值是oldvalue。请问返回值丢失了吗? + //没有丢失啊,你可以再set回去啊,或者直接把这个事情当成了纯异常,再次从新oad数据 +*/ + +/* resize + ** + * Initializes or doubles table size. If null, allocates in + * accord with initial capacity target held in field threshold. + * Otherwise, because we are using power-of-two expansion, the + * elements from each bin must either stay at same index, or move + * with a power of two offset in the new table. + * + * @return the table + * + final HashMap.Node[] resize() { + // old 16 + HashMap.Node[] oldTab = table; + // 16 + int oldCap = (oldTab == null) ? 0 : oldTab.length; + // 12 + int oldThr = threshold; + int newCap, newThr = 0; + if (oldCap > 0) { + if (oldCap >= MAXIMUM_CAPACITY) { + // 放弃扩容 + threshold = Integer.MAX_VALUE; + return oldTab; + } + else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY && + oldCap >= DEFAULT_INITIAL_CAPACITY) + newThr = oldThr << 1; // double threshold + } + else if (oldThr > 0) // initial capacity was placed in threshold + newCap = oldThr; + else { // zero initial threshold signifies using defaults + newCap = DEFAULT_INITIAL_CAPACITY; + newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); + } + if (newThr == 0) { + float ft = (float)newCap * loadFactor; + newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? + (int)ft : Integer.MAX_VALUE); + } + threshold = newThr; + @SuppressWarnings({"rawtypes","unchecked"}) + HashMap.Node[] newTab = (HashMap.Node[])new HashMap.Node[newCap]; + table = newTab; + if (oldTab != null) { + for (int j = 0; j < oldCap; ++j) { + HashMap.Node e; + if ((e = oldTab[j]) != null) { + oldTab[j] = null; + if (e.next == null) + newTab[e.hash & (newCap - 1)] = e; + else if (e instanceof HashMap.TreeNode) + ((HashMap.TreeNode)e).split(this, newTab, j, oldCap); + else { // preserve order + HashMap.Node loHead = null, loTail = null; + HashMap.Node hiHead = null, hiTail = null; + HashMap.Node next; + do { + next = e.next; + if ((e.hash & oldCap) == 0) { + if (loTail == null) + loHead = e; + else + loTail.next = e; + loTail = e; + } + else { + if (hiTail == null) + hiHead = e; + else + hiTail.next = e; + hiTail = e; + } + } while ((e = next) != null); + if (loTail != null) { + loTail.next = null; + newTab[j] = loHead; + } + if (hiTail != null) { + hiTail.next = null; + newTab[j + oldCap] = hiHead; + } + } + } + } + } + return newTab; + } + */ } \ No newline at end of file diff --git "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Set\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Set\347\261\273.java" new file mode 100644 index 00000000..ac920c56 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Set\347\261\273.java" @@ -0,0 +1,31 @@ +package cc.tianbin.java.集合; + +import io.github.nibnait.common.utils.DataUtils; +import org.junit.Test; + +import java.util.HashSet; +import java.util.Set; + +/** + * Created by nibnait on 2022/11/10 + */ +public class Set类 { + + @Test + public void test() { + Set set = new HashSet(); + set.add(1); + set.add(222); + set.add(3333); + set.add(4444); + set.add(5555); + set.add(6666); + set.add(7777); + set.add(888); + System.out.println("\n" + DataUtils.toJsonStringArray(set) + "\n"); + + + + } + +} diff --git a/src/main/java/common/util/SysOut.java b/src/main/java/common/util/SysOut.java index f49a296d..7d4c998c 100644 --- a/src/main/java/common/util/SysOut.java +++ b/src/main/java/common/util/SysOut.java @@ -3,7 +3,9 @@ import common.datastruct.BinaryTreeNode; import common.datastruct.ListNode; import io.github.nibnait.common.exception.ClientViewException; +import io.github.nibnait.common.utils.DataUtils; +import java.util.List; import java.util.Stack; /** @@ -23,6 +25,10 @@ public static void println(String format, Object... args) { println(String.format(format, args)); } + public static void printf(String format, Object... args) { + println(DataUtils.format(format, args)); + } + public static void println(Object o) { System.out.println(o); } @@ -65,6 +71,21 @@ public static void printArray(int[][] a) { println("}"); } + public static void printList(List arr) { + for (int i = 0; i < arr.size(); i++) { + if (i == arr.size() - 1) { + print(arr.get(i) + "\n"); + } else { + print(arr.get(i) + ", "); + } + } + } + + public static void printListWrap(List arr) { + for (String s : arr) { + println(s); + } + } public static void printArray(int[] a) { for (int i = 0; i < a.length; i++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" index e6ee6b5a..efcf076b 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" @@ -34,7 +34,7 @@ private int lessMoney(int[] arr) { } //-------------------------- 比较器 --------------------------// - public static int comparator(int[] arr) { + private int comparator(int[] arr) { if (arr == null || arr.length == 0) { return 0; } @@ -43,7 +43,7 @@ public static int comparator(int[] arr) { // 等待合并的数都在arr里,pre之前的合并行为产生了多少总代价 // arr中只剩一个数字的时候,停止合并,返回最小的总代价 - public static int process(int[] arr, int pre) { + private int process(int[] arr, int pre) { if (arr.length == 1) { return pre; } @@ -56,7 +56,7 @@ public static int process(int[] arr, int pre) { return ans; } - public static int[] copyAndMergeTwo(int[] arr, int i, int j) { + private int[] copyAndMergeTwo(int[] arr, int i, int j) { int[] ans = new int[arr.length - 1]; int ansi = 0; for (int arri = 0; arri < arr.length; arri++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" index 71dff93c..b26e6795 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" @@ -42,7 +42,7 @@ private int bestArrange(Program[] programs) { } //-------------------------- 比较器 --------------------------// - public static Program[] generatePrograms(int programSize, int timeMax) { + private Program[] generatePrograms(int programSize, int timeMax) { Program[] ans = new Program[(int) (Math.random() * (programSize + 1))]; for (int i = 0; i < ans.length; i++) { int r1 = (int) (Math.random() * (timeMax + 1)); @@ -57,7 +57,7 @@ public static Program[] generatePrograms(int programSize, int timeMax) { } // 暴力!所有情况都尝试! - public static int comparator(Program[] programs) { + private int comparator(Program[] programs) { if (programs == null || programs.length == 0) { return 0; } @@ -70,7 +70,7 @@ public static int comparator(Program[] programs) { // 目前来到timeLine的时间点,已经安排了done多的会议,剩下的会议programs可以自由安排 // 返回能安排的最多会议数量 - public static int process(Program[] programs, int done, int timeLine) { + private int process(Program[] programs, int done, int timeLine) { if (programs.length == 0) { return done; } @@ -86,7 +86,7 @@ public static int process(Program[] programs, int done, int timeLine) { return max; } - public static Program[] copyButExcept(Program[] programs, int i) { + private Program[] copyButExcept(Program[] programs, int i) { Program[] ans = new Program[programs.length - 1]; int index = 0; for (int k = 0; k < programs.length; k++) { diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" index 68bcab87..d3528036 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" @@ -1,14 +1,17 @@ ## 常见的递归 打印n层汉诺塔从最左边移动到最右边的全部过程(递归+非递归实现) +[Code01_Hanoi](./c0600_常见的递归/Code01_Hanoi.java) -打印一个字符串的全部子序列 +打印一个字符串的全部子序列 +打印一个字符串的全部子序列,要求不要出现重复字面值的子序列 +[Code02_PrintAllSubSequences](./c0600_常见的递归/Code02_PrintAllSubSequences.java) -打印一个字符串的全部子序列,要求不要出现重复字面值的子序列 +打印一个字符串的全部排列 +打印一个字符串的全部排列,要求不要出现重复的排列 +[Code03_PrintAllPermutations](./c0600_常见的递归/Code03_PrintAllPermutations.java) -打印一个字符串的全部排列 +给定一个栈,请逆序这个栈,不能申请额外的数据结构,只能使用递归函数 +[Code04_ReverseStackUsingRecursive](./c0600_常见的递归/Code04_ReverseStackUsingRecursive.java) -打印一个字符串的全部排列,要求不要出现重复的排列 - -给定一个栈,请逆序这个栈,不能申请额外的数据结构,只能使用递归函数 diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" index f92b4760..26633072 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" @@ -1,7 +1,116 @@ package algorithmzuo.b_体系学习班.c0600_常见的递归; +import com.google.common.collect.Lists; +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import io.github.nibnait.common.utils.DataUtils; +import io.github.nibnait.common.utils.compare.CompareUtils; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; +import java.util.Stack; + /** * Created by nibnait on 2022/11/06 */ public class Code01_Hanoi { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int n = SysRandom.random(100); + List hanoiRecur = hanoi1(n); + List hanoiNoRecur = hanoi2(n); + + if (!CompareUtils.match(hanoiRecur, hanoiNoRecur)) { + SysOut.printf("n = {}", n); + SysOut.printListWrap(hanoiRecur); + SysOut.printSeparator(); + SysOut.printListWrap(hanoiNoRecur); + } + } + + /** + * 递归 + */ + public List hanoi1(int n) { + if (n <= 0) { + return Lists.newArrayList(); + } + List step = new ArrayList<>(); + process(n, "左", "右", "中", step); + return step; + } + + /** + * 先把 n-1 左 -> 中 + * 再把 n 左 -> 右 + * 再把 n-1 中 -> 右 + */ + private void process(int n, String from, String to, String other, List step) { + if (n == 1) { + step.add(DataUtils.format("Move {} from {} to {}", n, from, to)); + return; + } + + process(n - 1, from, other, to, step); + step.add(DataUtils.format("Move {} from {} to {}", n, from, to)); + process(n - 1, other, to, from, step); + } + + /** + * 非递归 + */ + public List hanoi2(int N) { + List step = new ArrayList<>(); + if (N < 1) { + return step; + } + Stack stack = new Stack<>(); + stack.add(new Record(false, N, "左", "右", "中")); + while (!stack.isEmpty()) { + Record cur = stack.pop(); + if (cur.base == 1) { + step.add("Move 1 from " + cur.from + " to " + cur.to); + if (!stack.isEmpty()) { + stack.peek().finish1 = true; + } + } else { + if (!cur.finish1) { + stack.push(cur); + stack.push(new Record(false, cur.base - 1, cur.from, cur.other, cur.to)); + } else { + step.add("Move " + cur.base + " from " + cur.from + " to " + cur.to); + stack.push(new Record(false, cur.base - 1, cur.other, cur.to, cur.from)); + } + } + } + + return step; + } + + private class Record { + public boolean finish1; + public int base; + public String from; + public String to; + public String other; + + public Record(boolean f1, int b, String f, String t, String o) { + finish1 = false; + base = b; + from = f; + to = t; + other = o; + } + } + } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code02_PrintAllSubSequences.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code02_PrintAllSubSequences.java" new file mode 100644 index 00000000..1496ced3 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code02_PrintAllSubSequences.java" @@ -0,0 +1,80 @@ +package algorithmzuo.b_体系学习班.c0600_常见的递归; + +import com.google.common.collect.Lists; +import common.util.SysOut; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +/** + * Created by nibnait on 2022/11/08 + */ +public class Code02_PrintAllSubSequences { + + @Test + public void test() { + String test = "acccc"; + List ans1 = subs(test); + SysOut.printListWrap(ans1); + SysOut.printSeparator(); + + List ans2 = subsNoRepeat(test); + SysOut.printListWrap(ans2); + } + + + /** + * 全部子序列 + */ + public List subs(String s) { + char[] str = s.toCharArray(); + String path = ""; + List ans = new ArrayList<>(); + processSubs(str, ans, 0, path); + return ans; + } + + /** + * + * @param str 固定的入参字符串 + * @param ans 把所有生成的子序列,放到 ans 中 + * @param index 当前来到 index 位置 + * @param path 已经确定的生成的字符串 + */ + private void processSubs(char[] str, List ans, int index, String path) { + if (index == str.length) { + ans.add(path); + return; + } + + // 要当前位置的字符串 + processSubs(str, ans, index + 1, path + str[index]); + // 不要当前位置的字符串 + processSubs(str, ans, index + 1, path); + } + + /** + * 全部无重复值的子序列 + */ + public List subsNoRepeat(String s) { + char[] str = s.toCharArray(); + String path = ""; + Set ans = new HashSet<>(); + processSubsNoRepeat(str, ans, 0, path); + return Lists.newArrayList(ans); + } + + private void processSubsNoRepeat(char[] str, Set ans, int index, String path) { + if (index == str.length) { + ans.add(path); + return; + } + + processSubsNoRepeat(str, ans, index + 1, path); + processSubsNoRepeat(str, ans, index + 1, path + str[index]); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" new file mode 100644 index 00000000..7f24b023 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" @@ -0,0 +1,100 @@ +package algorithmzuo.b_体系学习班.c0600_常见的递归; + +import com.google.common.collect.Lists; +import common.util.SwapUtil; +import common.util.SysOut; +import org.junit.Test; + +import java.util.List; + +/** + * Created by nibnait on 2022/11/08 + */ +public class Code03_PrintAllPermutations { + + @Test + public void test() { + String s = "acc"; + List ans1 = permutation1(s); + SysOut.printListWrap(ans1); + System.out.println("======="); + + List ans2 = permutation2(s); + SysOut.printListWrap(ans2); + System.out.println("======="); + + } + + /** + * 打印一个字符串的全部排列 + */ + protected List permutation1(String s) { + List allPermutation = Lists.newArrayList(); + if (s == null || s.length() == 0) { + return allPermutation; + } + + char[] str = s.toCharArray(); + process1(str, 0, allPermutation); + return allPermutation; + } + + /** + * + * @param str + * @param index + * @param allPermutation + * @return + */ + private void process1(char[] str, int index, List allPermutation) { + if (index == str.length) { + allPermutation.add(String.valueOf(str)); + } else { + for (int i = index; i < str.length; i++) { + SwapUtil.swap(str, index, i); + process1(str, index + 1, allPermutation); + SwapUtil.swap(str, index, i); + } + } + } + + /** + * 全排列,不重复 + */ + protected List permutation2(String s) { + List allPermutation = Lists.newArrayList(); + if (s == null || s.length() == 0) { + return allPermutation; + } + + char[] str = s.toCharArray(); + process2(str, 0, allPermutation); + return allPermutation; + } + + /** + * + * @param str + * @param index + * @param allPermutation + * @return + */ + private void process2(char[] str, int index, List allPermutation) { + if (index == str.length) { + allPermutation.add(String.valueOf(str)); + } else { + boolean[] visited = new boolean[256]; + for (int i = index; i < str.length; i++) { + if (visited[str[i]]) { + continue; + } + visited[str[i]] = true; + // str[i] 这个字符,在出现在了第 x 位置时的所有可能性: + SwapUtil.swap(str, index, i); + process2(str, index + 1, allPermutation); + SwapUtil.swap(str, index, i); + } + } + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" new file mode 100644 index 00000000..afb7f76e --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" @@ -0,0 +1,56 @@ +package algorithmzuo.b_体系学习班.c0600_常见的递归; + +import org.junit.Test; + +import java.util.Stack; + +/** + * Created by nibnait on 2022/11/08 + */ +public class Code04_ReverseStackUsingRecursive { + + @Test + public void test() { + Stack stack = new Stack(); + stack.push(1); + stack.push(2); + stack.push(3); + stack.push(4); + stack.push(5); + reverse(stack); + while (!stack.isEmpty()) { + System.out.println(stack.pop()); + } + + } + + /** + * 使用递归,将栈逆序 + */ + protected void reverse(Stack stack) { + if (stack == null || stack.isEmpty()) { + return; + } + + int last = process(stack); + reverse(stack); + // 把每次的栈底 push 进来 + stack.push(last); + } + + /** + * 每次都返回当前的栈底 + */ + private int process(Stack stack) { + Integer result = stack.pop(); + if (stack.isEmpty()) { + return result; + } + + int last = process(stack); + stack.push(result); + return last; + } + + +} diff --git "a/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" index de586032..ae960e1d 100644 --- "a/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" @@ -7,9 +7,8 @@ import java.util.LinkedHashMap; import java.util.Map; -/* - -Created by nibnait on 2020-01-15 +/** + * Created by nibnait on 2020-01-15 */ public class MapTest { diff --git "a/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" index aac4d5e5..d5e6e559 100644 --- "a/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" +++ "b/src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" @@ -11,9 +11,8 @@ import java.util.stream.Collectors; import java.util.stream.Stream; -/* - -Created by nibnait on 2020-01-14 +/** + * Created by nibnait on 2020-01-14 */ public class SetTest { From 7c979555b9bef49b351ab164eb44e12696848ca5 Mon Sep 17 00:00:00 2001 From: tianbin Date: Sun, 13 Nov 2022 23:43:54 +0800 Subject: [PATCH 26/36] =?UTF-8?q?feat=20=E4=BB=8E=E6=9A=B4=E5=8A=9B?= =?UTF-8?q?=E9=80=92=E5=BD=92=20=E5=88=B0=E5=8A=A8=E6=80=81=E8=A7=84?= =?UTF-8?q?=E5=88=92=E3=80=82=E7=BB=83=EF=BC=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../a_Sorting/a_Selection.java | 2 +- .../a_Sorting/b_Insertion.java | 2 +- .../algorithm_practice/a_Sorting/d_Merge.java | 2 +- src/main/java/common/util/SysRandom.java | 117 ++++++++++-- .../SerializeAndReConstructTreeImpl.java | 4 +- .../data_struct/ds1_\345\240\206/Heap.java" | 2 +- .../ds1_\345\240\206/HeapGreater.java" | 2 +- src/main/test/UnitTestDemo.java | 58 +++++- .../test/algorithm_practice/TempTest.java | 2 +- src/main/test/algorithmzuo/README.md | 2 - .../Code01_SelectionSort.java" | 2 +- .../Code02_BubbleSort.java" | 2 +- .../Code03_InsertionSort.java" | 2 +- .../Code04_1_MergeSort_Recursion.java" | 2 +- .../Code04_2_MergeSort_Non_Recursion.java" | 2 +- .../Code04_3_SmallSum.java" | 2 +- .../Code04_4_ReversePair.java" | 2 +- .../Code04_5_BiggerThanRightTwice.java" | 2 +- .../Code05_1_PartitionAndQuickSort.java" | 2 +- ...5_2_QuickSortRecursionAndUnrecursion.java" | 8 +- .../Code06_1_HeapSort.java" | 2 +- .../Code06_2_SortArrayDistanceLessK.java" | 2 +- .../Code07_CountSort.java" | 2 +- .../Code08_RadixSort.java" | 2 +- .../Code01_BSExist.java" | 2 +- .../Code02_BSNearLeft.java" | 2 +- .../Code03_BSNearRight.java" | 2 +- .../Code03_KM.java" | 12 +- .../Code01_1_ReverseListNode.java" | 2 +- .../Code01_2_ReverseDoubleListNode.java" | 2 +- .../Code02_DeleteGivenValue.java" | 2 +- .../Code06_TreeMaxWidth.java" | 4 +- .../Code01_IsBalanced.java" | 4 +- .../Code02_IsBST.java" | 4 +- .../Code03_MaxDistance.java" | 4 +- .../Code04_IsFull.java" | 4 +- .../Code05_MaxSubBSTSize.java" | 4 +- .../Code06_IsCBT.java" | 4 +- .../Code07_MaxSubBSTHead.java" | 4 +- .../Code08_lowestAncestor.java" | 4 +- .../Code01_Light.java" | 2 +- .../Code02_LessMoneySplitGold.java" | 4 +- .../Code03_BestArrange.java" | 4 +- .../Code02_NumberOfIslands.java" | 4 +- .../Code01_Hanoi.java" | 2 +- .../Code03_PrintAllPermutations.java" | 4 +- .../Code04_ReverseStackUsingRecursive.java" | 2 +- ...50\346\200\201\350\247\204\345\210\222.md" | 163 ++++++++++++++-- .../Code01_RobotWalk.java" | 74 +++++++ .../Code02_CardsInLine.java" | 111 +++++++++++ .../Code03_Knapsack.java" | 94 +++++++++ .../Code04_ConvertToLetterString.java" | 89 +++++++++ .../Code05_StickersToSpellWord.java" | 180 ++++++++++++++++++ .../Code06_LongestCommonSubsequence.java" | 155 +++++++++++++++ .../Code07_PalindromeSubsequence.java" | 84 ++++++++ .../Code08_HorseJump.java" | 103 ++++++++++ .../Code09_Coffee.java" | 155 +++++++++++++++ .../Code10_MinPathSum.java" | 93 +++++++++ .../Code11_CoinsWayEveryPaperDifferent.java" | 106 +++++++++++ .../Code12_CoinsWayNoLimit.java" | 109 +++++++++++ .../Code13_CoinsWaySameValueSamePapper.java" | 143 ++++++++++++++ .../Code14_MinCoinsNoLimit.java" | 104 ++++++++++ .../Code15_BobDie.java" | 100 ++++++++++ .../Code16_KillMonster.java" | 97 ++++++++++ .../Code17_SplitNumber.java" | 127 ++++++++++++ .../Code18_SplitSumClosed.java" | 111 +++++++++++ .../Code19_SplitSumClosedSizeHalf.java" | 92 +++++++++ .../Code20_NQueens.java" | 115 +++++++++++ 68 files changed, 2611 insertions(+), 103 deletions(-) create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code02_CardsInLine.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code03_Knapsack.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code04_ConvertToLetterString.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code05_StickersToSpellWord.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code06_LongestCommonSubsequence.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code07_PalindromeSubsequence.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code08_HorseJump.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code09_Coffee.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code10_MinPathSum.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code11_CoinsWayEveryPaperDifferent.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code12_CoinsWayNoLimit.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code13_CoinsWaySameValueSamePapper.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code14_MinCoinsNoLimit.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code15_BobDie.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code16_KillMonster.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code17_SplitNumber.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code18_SplitSumClosed.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code19_SplitSumClosedSizeHalf.java" create mode 100644 "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code20_NQueens.java" diff --git a/src/main/java/algorithm_practice/a_Sorting/a_Selection.java b/src/main/java/algorithm_practice/a_Sorting/a_Selection.java index e8a057b6..0883ca74 100644 --- a/src/main/java/algorithm_practice/a_Sorting/a_Selection.java +++ b/src/main/java/algorithm_practice/a_Sorting/a_Selection.java @@ -15,7 +15,7 @@ */ public class a_Selection { public static void main(String[] args) { - int[] a = SysRandom.randomArr(); + int[] a = SysRandom.generateArr(); SysOut.printArray(a); Selection_Sort(a); diff --git a/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java b/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java index fc805a3e..aa958061 100644 --- a/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java +++ b/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java @@ -9,7 +9,7 @@ */ public class b_Insertion { public static void main(String[] args) { - int[] a = SysRandom.randomArr(); + int[] a = SysRandom.generateArr(); SysOut.printArray(a); a = Insertion_Sort(a); diff --git a/src/main/java/algorithm_practice/a_Sorting/d_Merge.java b/src/main/java/algorithm_practice/a_Sorting/d_Merge.java index 1e8ea0dc..1c7cb9f2 100644 --- a/src/main/java/algorithm_practice/a_Sorting/d_Merge.java +++ b/src/main/java/algorithm_practice/a_Sorting/d_Merge.java @@ -10,7 +10,7 @@ public class d_Merge { public static void main(String[] args) { - int[] a = SysRandom.randomArr(); + int[] a = SysRandom.generateArr(); SysOut.printArray(a); divide(a, 0, a.length - 1); diff --git a/src/main/java/common/util/SysRandom.java b/src/main/java/common/util/SysRandom.java index 9abe44d9..0c782440 100644 --- a/src/main/java/common/util/SysRandom.java +++ b/src/main/java/common/util/SysRandom.java @@ -14,14 +14,24 @@ public class SysRandom { private static final Integer RANDOM_MAX_VALUE = 1000; private static final String INVALID_RANGE = "Invalid range, a: {}, b: {}"; - private static double random() { + private static double generate() { return Math.random() * RANDOM_MAX_VALUE; } /** * 随机返回 [0,n)之间的一个int值 */ - public static int random(int n) { + public static int generateNaturalNum(int n) { + if (n < 0) { + throw new IllegalArgumentException(DataUtils.format("Parameter {} must be positive", n)); + } + if (n == 0) { + return 0; + } + return random.nextInt(n); + } + + public static int generatePositiveInt(int n) { if (n < 0) { throw new IllegalArgumentException(DataUtils.format("Parameter {} must be positive", n)); } @@ -34,37 +44,37 @@ public static int random(int n) { /** * 随机返回 [a,b)之间的一个double值 */ - public static double randomDouble(double a, double b) { + public static double generateDouble(double a, double b) { if (a >= b) { throw new IllegalArgumentException(DataUtils.format(INVALID_RANGE, a, b)); } - return a + random() * (b - a); + return a + generate() * (b - a); } /** * 随机返回 [a,b)之间的一个int值 */ - public static int randomInt(int a, int b) { + public static int generateInt(int a, int b) { if (b <= a) { throw new IllegalArgumentException(DataUtils.format(INVALID_RANGE, a, b)); } if ((long) b - a >= Integer.MAX_VALUE) { throw new IllegalArgumentException(DataUtils.format(INVALID_RANGE, a, b)); } - return a + random(b - a); + return a + generateNaturalNum(b - a); } /** * 返回一个[-100,100)范围的随机int型数组 */ - public static int[] randomArr() { - return randomArr(random(50)); + public static int[] generateArr() { + return generateArr(generateNaturalNum(50)); } - public static int[] randomArr(int arrLength) { + public static int[] generateArr(int arrLength) { int[] a = new int[arrLength]; for (int i = 0; i < a.length; i++) { - a[i] = randomInt(-100, 100); + a[i] = generateInt(-100, 100); } return a; } @@ -72,30 +82,62 @@ public static int[] randomArr(int arrLength) { /** * 返回一个[0,100)范围的随机int型数组 */ - public static int[] randomArrNaturalNum() { - return randomArrNaturalNum(random(50)); + public static int[] generateArrNaturalNum() { + return generateArrNaturalNum(generateNaturalNum(50)); } - public static int[] randomArrNaturalNum(int arrLength) { - int[] a = new int[arrLength]; + public static int[] randomArrNaturalNumRandomLength(int randomLength) { + return generateArrNaturalNum(generateNaturalNum(randomLength)); + } + + public static int[] generateArrNaturalNum(int maxLen) { + int arrLen = generateNaturalNum(maxLen); + int[] a = new int[arrLen]; for (int i = 0; i < a.length; i++) { - a[i] = randomInt(0, 100); + a[i] = generateInt(0, 100); } return a; } - public static int[] randomArrNaturalNum(int arrLength, int maxValue) { - int[] a = new int[arrLength]; + public static int[] generateArrPositiveInteger(int maxLen) { + int arrLen = generateNaturalNum(maxLen); + int[] a = new int[arrLen]; for (int i = 0; i < a.length; i++) { - a[i] = randomInt(0, maxValue); + a[i] = generateInt(1, 100); } return a; } + public static int[] generateArrPositiveIntegerNoRepeat(int maxLen) { + int maxValue = 100; + int arrLen = generateNaturalNum(maxLen); + int[] arr = new int[arrLen]; + boolean[] has = new boolean[maxValue]; + for (int i = 0; i < arrLen; i++) { + do { + arr[i] = generateInt(1, maxValue); + } while (has[arr[i]]); + has[arr[i]] = true; + } + return arr; + } + + public static int[] generateArrNaturalNum(int maxLen, int maxValue) { + int arrLen = generateNaturalNum(maxLen); + int[] arr = new int[arrLen]; + for (int i = 0; i < arr.length; i++) { + arr[i] = generateInt(0, maxValue); + } + return arr; + } + /** * 返回一个 0 1 矩阵 */ - public static char[][] randomMatrix(int row, int col) { + public static char[][] generateMatrixZeroOneChar(int row, int col) { + if (row < 0 || col < 0) { + return null; + } char[][] board = new char[row][col]; for (int i = 0; i < row; i++) { for (int j = 0; j < col; j++) { @@ -104,4 +146,41 @@ public static char[][] randomMatrix(int row, int col) { } return board; } + + public static int[][] generateMatrixNaturalNum(int row, int col) { + if (row < 0 || col < 0) { + return null; + } + int[][] result = new int[row][col]; + for (int i = 0; i < result.length; i++) { + for (int j = 0; j < result[0].length; j++) { + result[i][j] = generateNaturalNum(100); + } + } + return result; + } + + /** + * 生成一个随机长度的 由 123456789 组成String + */ + public static String generateStringNaturalNum(int randomLen) { + int length = generateNaturalNum(randomLen); + char[] str = new char[length]; + for (int i = 0; i < length; i++) { + str[i] = (char) (generateNaturalNum(10) + '0'); + } + return String.valueOf(str); + } + + /** + * 生成一个随机长度的 由 abc....xyz 组成String + */ + public static String generateStringLowercaseLetters(int randomLen) { + int length = generateNaturalNum(randomLen); + char[] str = new char[length]; + for (int i = 0; i < length; i++) { + str[i] = (char) (generateNaturalNum(27) + 'a'); + } + return String.valueOf(str); + } } diff --git a/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java b/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java index 35275a47..2a72b088 100644 --- a/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java +++ b/src/main/java/common/util/binaryTree/SerializeAndReConstructTreeImpl.java @@ -28,8 +28,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); PrintBinaryTree.print(head); diff --git "a/src/main/java/data_struct/ds1_\345\240\206/Heap.java" "b/src/main/java/data_struct/ds1_\345\240\206/Heap.java" index 8ccf4aae..af0f8e56 100644 --- "a/src/main/java/data_struct/ds1_\345\240\206/Heap.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/Heap.java" @@ -26,7 +26,7 @@ public class Heap { @Test public void testCase() { int limit = 10; - int[] arr = SysRandom.randomArrNaturalNum(limit); + int[] arr = SysRandom.generateArrNaturalNum(limit); SysOut.printArray(arr); MapHeap maxHeap = new MapHeap(limit); diff --git "a/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" index 3056b238..f429059e 100644 --- "a/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" +++ "b/src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" @@ -18,7 +18,7 @@ public class HeapGreater { @Test public void testCase() { - int[] arr = SysRandom.randomArr(10); + int[] arr = SysRandom.generateArr(10); SysOut.printArray(arr); int limit = 10; diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java index 2af185ad..b7eeaa3e 100644 --- a/src/main/test/UnitTestDemo.java +++ b/src/main/test/UnitTestDemo.java @@ -1,5 +1,7 @@ +import cn.hutool.core.lang.Assert; import common.CommonConstants; import common.util.CompareUtils; +import common.util.SysOut; import common.util.SysRandom; import lombok.extern.slf4j.Slf4j; import org.junit.Test; @@ -18,10 +20,58 @@ public void loopTestCase() { testCase(); } } - + @Test public void testCase() { - int arr[] = SysRandom.randomArrNaturalNum(); + int maxLen = 20; + int maxValue = 30; + int[] arr = SysRandom.generateArrNaturalNum(maxLen); + int aim = SysRandom.generateNaturalNum(maxValue); + int ans1 = test(arr, aim); + int ans2 = test(arr, aim); + + if (ans1 != ans2) { + SysOut.printArray(arr); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + @Test + public void test2() { + int[] arr = SysRandom.randomArrNaturalNumRandomLength(20); + + int ans1 = test(); + int ans2 = test(); + + if (ans1 != ans2) { + SysOut.printArray(arr); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + + SysOut.printArray(arr); + SysOut.println(ans1); + } + + @Test + public void test1() { + String str1 = "a12b3c456d"; + String str2 = "1ef23ghi4j56k"; + int ans1 = test(str1, str2); + int ans2 = test(str1, str2); + Assert.equals(ans1, ans2); + + str1 = "abcde"; + str2 = "ace"; + ans1 = test(str1, str2); + ans2 = test(str1, str2); + Assert.equals(ans1, ans2); + } + + @Test + public void testCase1() { + int[] arr = SysRandom.generateArrNaturalNum(); int[] copyArr = Arrays.copyOf(arr, arr.length); if (!CompareUtils.isSortAsc(arr)) { @@ -32,12 +82,14 @@ public void testCase() { } @Test - public void test() { + public int test(Object... args) { boolean f1 = true; boolean f2 = false; f1 = f1 || f2; System.out.println(f1); + + return 0; } } diff --git a/src/main/test/algorithm_practice/TempTest.java b/src/main/test/algorithm_practice/TempTest.java index 3418000a..9a3f99e1 100644 --- a/src/main/test/algorithm_practice/TempTest.java +++ b/src/main/test/algorithm_practice/TempTest.java @@ -13,7 +13,7 @@ public class TempTest { @Test public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); SysOut.printArray(arr); selectSort(arr); SysOut.printArray(arr); diff --git a/src/main/test/algorithmzuo/README.md b/src/main/test/algorithmzuo/README.md index 2ab6457f..5f66c045 100644 --- a/src/main/test/algorithmzuo/README.md +++ b/src/main/test/algorithmzuo/README.md @@ -1,5 +1,3 @@ # 跟着左神写算法 -笔记: - diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" index 15798d46..ceb15846 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" @@ -24,7 +24,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); selectSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" index fff3719a..1faafc43 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" @@ -24,7 +24,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); bubbleSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" index 2817661d..69379721 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" @@ -24,7 +24,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); insertSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" index 772bbe4f..1452b2bc 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" @@ -23,7 +23,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); mergeSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" index c7713c84..a4534665 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" @@ -23,7 +23,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArrNaturalNum(); + int[] arr = SysRandom.generateArrNaturalNum(); int[] copyArr = Arrays.copyOf(arr, arr.length); mergeSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" index 4d611000..76e1ab01 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" @@ -23,7 +23,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); int expectResult = comparator(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" index 33ec6ee4..b3625b77 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" @@ -23,7 +23,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); int expectResult = comparator(arr); int reversePairCount = mergeSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" index 2d01014a..24b448ae 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" @@ -23,7 +23,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArrNaturalNum(); + int[] arr = SysRandom.generateArrNaturalNum(); int[] copyArr = Arrays.copyOf(arr, arr.length); int expectResult = comparator(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" index 3982a032..58519aae 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" @@ -24,7 +24,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); int[] copyArr = Arrays.copyOf(arr, arr.length); quickSort3(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" index b161b7b4..9ca279b9 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" @@ -25,7 +25,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArrNaturalNum(10); + int[] arr = SysRandom.generateArrNaturalNum(10); int[] copyArr = Arrays.copyOf(arr, arr.length); quickSortWithStack(arr); @@ -51,7 +51,7 @@ private void process(int[] arr, int left, int right) { return; } - SwapUtil.swap(arr, right, SysRandom.random(right - left + 1)); + SwapUtil.swap(arr, right, SysRandom.generateNaturalNum(right - left + 1)); int[] equalArea = partition(arr, left, right); process(arr, left, equalArea[0] - 1); process(arr, equalArea[1] + 1, right); @@ -91,14 +91,14 @@ public void quickSortWithStack(int[] arr) { int length = arr.length; Stack stack = new Stack<>(); - SwapUtil.swap(arr, length - 1, SysRandom.random(length)); + SwapUtil.swap(arr, length - 1, SysRandom.generateNaturalNum(length)); int[] partition = partition(arr, 0, length - 1); stack.push(new SortArea(0, partition[0] - 1)); stack.push(new SortArea(partition[1] + 1, length - 1)); while (!stack.isEmpty()) { SortArea sortArea = stack.pop(); if (sortArea.left < sortArea.right) { - SwapUtil.swap(arr, sortArea.right, sortArea.left + SysRandom.random(sortArea.right - sortArea.left + 1)); + SwapUtil.swap(arr, sortArea.right, sortArea.left + SysRandom.generateNaturalNum(sortArea.right - sortArea.left + 1)); partition = partition(arr, sortArea.left, sortArea.right); stack.push(new SortArea(sortArea.left, partition[0] - 1)); stack.push(new SortArea(partition[1] + 1, sortArea.right)); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" index 3727747a..08bee24c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" @@ -24,7 +24,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArrNaturalNum(); + int[] arr = SysRandom.generateArrNaturalNum(); int[] copyArr = Arrays.copyOf(arr, arr.length); heapSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" index 460c6a12..3efcdd2a 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" @@ -26,7 +26,7 @@ public void loopTestCase() { public void testCase() { int maxSize = 100; int maxValue = 100; - int k = SysRandom.random(maxSize); + int k = SysRandom.generateNaturalNum(maxSize); int[] arr = randomArrayNoMoveMoreK(maxSize, maxValue, k); int[] copyArr = Arrays.copyOf(arr, arr.length); sortArrayDistanceLessK(arr, k); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" index eeb30f30..8f14b5e5 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" @@ -24,7 +24,7 @@ public void loopTestCase() { @Test public void testCase() { // 全是自然数,范围 [0-100) - int arr[] = SysRandom.randomArrNaturalNum(); + int[] arr = SysRandom.generateArrNaturalNum(); int[] copyArr = Arrays.copyOf(arr, arr.length); countSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" index a2832b23..09a7e5d3 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" @@ -23,7 +23,7 @@ public void loopTestCase() { @Test public void testCase() { - int arr[] = SysRandom.randomArrNaturalNum(); + int[] arr = SysRandom.generateArrNaturalNum(); int[] copyArr = Arrays.copyOf(arr, arr.length); radixSort(arr); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" index 632a98ca..02faf91f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" @@ -17,7 +17,7 @@ public class Code01_BSExist { @Test public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - int[] arr = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); Arrays.sort(arr); int num = 11; int ans = find(arr, num); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" index d6f5ed38..01036238 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" @@ -16,7 +16,7 @@ public class Code02_BSNearLeft { @Test public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - int[] arr = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); Arrays.sort(arr); int num = 11; int ans = mostLeftNoLessNumIndex(arr, num); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" index eea3c3a8..0a4c747d 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" @@ -16,7 +16,7 @@ public class Code03_BSNearRight { @Test public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { - int[] arr = SysRandom.randomArr(); + int[] arr = SysRandom.generateArr(); Arrays.sort(arr); int num = 11; int ans = nearestIndex(arr, num); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" index 1dbbd288..e7b6c15f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" @@ -21,26 +21,26 @@ public class Code03_KM { @Test public void testCase() { for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_10; i++) { - int a = SysRandom.random(9) + 1; - int b = SysRandom.random(9) + 1; + int a = SysRandom.generateNaturalNum(9) + 1; + int b = SysRandom.generateNaturalNum(9) + 1; int k = Math.min(a, b); int m = Math.max(a, b); if (k == m) { m++; } - int mTimeNumCount = SysRandom.random(9); + int mTimeNumCount = SysRandom.generateNaturalNum(9); int arrLength = k + m * mTimeNumCount; int[] arr = new int[arrLength]; // 填充出现了 k 次的数 - int kTimesNum = SysRandom.randomInt(-200, 200); + int kTimesNum = SysRandom.generateInt(-200, 200); for (int j = 0; j < k; j++) { arr[j] = kTimesNum; } // 填充出现了 m 次的数 int index = k; - int mTimesNum = SysRandom.randomInt(-200, 200); + int mTimesNum = SysRandom.generateInt(-200, 200); for (int l = 0; l < m; l++) { for (int n = 0; n < mTimeNumCount; n++) { arr[index++] = mTimesNum; @@ -49,7 +49,7 @@ public void testCase() { // j 位置的数和 arr里任意位置的的一个数 for (int j = 0; j < arrLength; j++) { - int randomIndex = SysRandom.random(arrLength); + int randomIndex = SysRandom.generateNaturalNum(arrLength); swap(arr, j, randomIndex); } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" index 4db039cc..82d00315 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" @@ -26,7 +26,7 @@ public void loopTestCase() { @Test public void testCase() { - ListNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr()); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.generateArr()); ListNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); // SysOut.printLinkedNode("origin: ", head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" index 90a1a807..d7b79356 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" @@ -26,7 +26,7 @@ public void loopTestCase() { @Test public void testCase() { - ListNode head = ConstructLinkedNode.constructDoubleLinkedNode(SysRandom.randomArr()); + ListNode head = ConstructLinkedNode.constructDoubleLinkedNode(SysRandom.generateArr()); // SysOut.printDoubleLinkedNode("origin: ", head); ListNode copyHead = ConstructLinkedNode.copyDoubleLinkedNode(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" index 0f958a86..80d38af3 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" @@ -20,7 +20,7 @@ public void loopTestCase() { @Test public void testCase() { - ListNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.randomArr(20)); + ListNode head = ConstructLinkedNode.constructSingleLinkedNode(SysRandom.generateArr(20)); ListNode copyHead = ConstructLinkedNode.copySingleLinkedNode(head); // SysOut.printLinkedNode("before: ", head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" index 0b6cfd5a..4a39929c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" @@ -27,8 +27,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 10); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 10); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" index b75dabf3..33caf94d 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" @@ -19,8 +19,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(0, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(0, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); // PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" index 5febc383..02cf1209 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" @@ -24,8 +24,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); // PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" index d1b14e4a..bab8f779 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" @@ -26,8 +26,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); // PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" index 32869e07..2ff85e5c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" @@ -24,8 +24,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" index badd8cce..b0fcc7fe 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" @@ -26,8 +26,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" index 320e1e58..d98f125c 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" @@ -24,8 +24,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); // PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" index e6a840dc..af7bc4ec 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" @@ -26,8 +26,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" index 06a4b00c..2b9d2475 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" @@ -29,8 +29,8 @@ public void loopTestCase() { @Test public void testCase() { - int maxLevel = SysRandom.randomInt(1, 6); - int maxValue = SysRandom.random(100); + int maxLevel = SysRandom.generateInt(1, 6); + int maxValue = SysRandom.generateNaturalNum(100); TreeNode head = ConstructBinaryTree.generateRandomBinaryTree(maxLevel, maxValue); PrintBinaryTree.print(head); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" index f411424e..37a98c63 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" @@ -21,7 +21,7 @@ public void loopTestCase() { @Test public void testCase() { - int len = SysRandom.randomInt(0, 50); + int len = SysRandom.generateInt(0, 50); String road = randomString(len); int result = minLight(road); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" index efcf076b..17118ccb 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" @@ -19,8 +19,8 @@ public void loopTestCase() { @Test public void testCase() { - int arrLen = SysRandom.random(20); - int[] arr = SysRandom.randomArrNaturalNum(arrLen, 1000); + int arrLen = SysRandom.generateNaturalNum(20); + int[] arr = SysRandom.generateArrNaturalNum(arrLen, 1000); int result = lessMoney(arr); Assert.assertEquals(comparator(arr), result); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" index b26e6795..469f226f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" @@ -20,8 +20,8 @@ public void loopTestCase() { @Test public void testCase() { - int programSize = SysRandom.randomInt(5, 20); - int timeMax = SysRandom.randomInt(10, 30); + int programSize = SysRandom.generateInt(5, 20); + int timeMax = SysRandom.generateInt(10, 30); Program[] programs = generatePrograms(programSize, timeMax); int result = bestArrange(programs); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" index 09e1ae66..9c695bba 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" @@ -23,7 +23,7 @@ public void test() { row = 1000; col = 1000; - board1 = SysRandom.randomMatrix(row, col); + board1 = SysRandom.generateMatrixZeroOneChar(row, col); board2 = CopyUtil.copy(board1); board3 = CopyUtil.copy(board1); @@ -49,7 +49,7 @@ public void test() { row = 10000; col = 10000; - board1 = SysRandom.randomMatrix(row, col); + board1 = SysRandom.generateMatrixZeroOneChar(row, col); board3 = CopyUtil.copy(board1); System.out.println("感染方法、并查集(数组实现)的运行结果和运行时间"); System.out.println("随机生成的二维矩阵规模 : " + row + " * " + col); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" index 26633072..2de2f110 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" @@ -26,7 +26,7 @@ public void loopTestCase() { @Test public void testCase() { - int n = SysRandom.random(100); + int n = SysRandom.generateNaturalNum(100); List hanoiRecur = hanoi1(n); List hanoiNoRecur = hanoi2(n); diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" index 7f24b023..99bd1762 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" @@ -28,7 +28,7 @@ public void test() { /** * 打印一个字符串的全部排列 */ - protected List permutation1(String s) { + public List permutation1(String s) { List allPermutation = Lists.newArrayList(); if (s == null || s.length() == 0) { return allPermutation; @@ -61,7 +61,7 @@ private void process1(char[] str, int index, List allPermutation) { /** * 全排列,不重复 */ - protected List permutation2(String s) { + public List permutation2(String s) { List allPermutation = Lists.newArrayList(); if (s == null || s.length() == 0) { return allPermutation; diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" index afb7f76e..f92c5228 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" @@ -27,7 +27,7 @@ public void test() { /** * 使用递归,将栈逆序 */ - protected void reverse(Stack stack) { + public void reverse(Stack stack) { if (stack == null || stack.isEmpty()) { return; } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" index 2cd1ec21..6cbb21ca 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" @@ -1,17 +1,154 @@ +## 从暴力递归 到动态规划。练! -假设有排成一行的N个位置记为1~N,N一定大于或等于2 -开始时机器人在其中的M位置上(M一定是1~N中的一个) -如果机器人来到1位置,那么下一步只能往右来到2位置; -如果机器人来到N位置,那么下一步只能往左来到N-1位置; -如果机器人来到中间位置,那么下一步可以往左走或者往右走; -规定机器人必须走K步,最终能来到P位置(P也是1~N中的一个)的方法有多少种 -给定四个参数 N、M、K、P,返回方法数 +### [Code01_RobotWalk](./c0700_动态规划/Code01_RobotWalk.java) +假设 有排成一行的N个位置记为1~N,N一定大于或等于2 +开始时机器人在其中的M位置上(M一定是1~N中的一个) +如果机器人来到1位置,那么下一步只能往右来到2位置; +如果机器人来到N位置,那么下一步只能往左来到N-1位置; +如果机器人来到中间位置,那么下一步可以往左走或者往右走; +规定机器人必须走K步,最终能来到P位置(P也是1~N中的一个)的方法有多少种 +给定四个参数 N、M、K、P,返回方法数 +### [Code02_CardsInLine](./c0700_动态规划/Code02_CardsInLine.java) +给定一个整型数组arr,代表数值不同的纸牌排成一条线 +玩家A和玩家B依次拿走每张纸牌 +规定玩家A先拿,玩家B后拿 +但是每个玩家每次只能拿走最左或最右的纸牌 +玩家A和玩家B都绝顶聪明 +请返回最后获胜者的分数 +### [Code03_Knapsack](./c0700_动态规划/Code03_Knapsack.java) +背包问题 +给定两个长度都为N的数组weights和values,weights[i]和values[i]分别代表 i号物品的重量和价值 +给定一个正数bag,表示一个载重bag的袋子,装的物品不能超过这个重量 +返回能装下的最大价值 -给定一个整型数组arr,代表数值不同的纸牌排成一条线 -玩家A和玩家B依次拿走每张纸牌 -规定玩家A先拿,玩家B后拿 -但是每个玩家每次只能拿走最左或最右的纸牌 -玩家A和玩家B都绝顶聪明 -请返回最后获胜者的分数 \ No newline at end of file +### [Code04_ConvertToLetterString](./c0700_动态规划/Code04_ConvertToLetterString.java) +规定1和A对应、2和B对应、3和C对应...26和Z对应 +那么一个数字字符串比如"111”就可以转化为: +"AAA"、"KA"和"AK" +给定一个只有数字字符组成的字符串str,返回有多少种转化结果 + +### [Code05_StickersToSpellWord](./c0700_动态规划/Code05_StickersToSpellWord.java) +给定一个字符串str,给定一个字符串类型的数组arr,出现的字符都是小写英文 +arr每一个字符串,代表一张贴纸,你可以把单个字符剪开使用,目的是拼出str来 +返回需要至少多少张贴纸可以完成这个任务 +例子:target= "babac",stickers = {"ba","c","abcd"} +ba + ba + c 3 +abcd + abcd 2 +abcd+ba 2 +所以返回2 + +### [Code06_LongestCommonSubsequence](./c0700_动态规划/Code06_LongestCommonSubsequence.java) +给定两个字符串str1和str2, +返回这两个字符串的最长公共子序列长度 +比如 : str1 = “a12b3c456d”,str2 = “1ef23ghi4j56k” +最长公共子序列是“123456”,所以返回长度6 + +### [Code07_PalindromeSubsequence](./c0700_动态规划/Code07_PalindromeSubsequence.java) +给定一个字符串str,返回这个字符串的最长回文子序列长度 +比如 : str = “a12b3c43def2ghi1kpm” +最长回文子序列是“1234321”或者“123c321”,返回长度7 + +### [Code08_HorseJump](./c0700_动态规划/Code08_HorseJump.java) +*WIP: 优化 -> 二维* + +请同学们自行想象一个象棋的棋盘, +然后把整个棋盘放入第一象限,棋盘的最左下角是(0,0)位置 +那么整个棋盘就是横坐标上9条线、纵坐标上10条线的区域 +给你三个 参数 x,y,k +返回“马”从(0,0)位置出发,必须走k步 +最后落在(x,y)上的方法数有多少种? + +### ⭐️ [Code09_Coffee](./c0700_动态规划/Code09_Coffee.java) +给定一个数组arr,arr[i]代表第i号咖啡机泡一杯咖啡的时间 +给定一个正数N,表示N个人等着咖啡机泡咖啡,每台咖啡机只能轮流泡咖啡 +只有一台咖啡机,一次只能洗一个杯子,时间耗费a,洗完才能洗下一杯 +每个咖啡杯也可以自己挥发干净,时间耗费b,咖啡杯可以并行挥发 +假设所有人拿到咖啡之后立刻喝干净, +返回从开始等到所有咖啡机变干净的最短时间 +三个参数:int[] arr、int N,int a、int b + +### [Code10_MinPathSum](./c0700_动态规划/Code10_MinPathSum.java) +*WIP: 优化 -> 一维* + +给定一个二维数组matrix,一个人必须从左上角出发,最后到达右下角 +沿途只可以向下或者向右走,沿途的数字都累加就是距离累加和 +返回最小距离累加和 + +### [Code11_CoinsWayEveryPaperDifferent](./c0700_动态规划/Code11_CoinsWayEveryPaperDifferent.java) +*WIP: 优化 -> 一维* + +arr是货币数组,其中的值都是正数。再给定一个正数aim。 +每个值都认为是一张货币, +即便是值相同的货币也认为每一张都是不同的, +返回组成aim的方法数 +例如:arr = {1,1,1},aim = 2 +第0个和第1个能组成2,第1个和第2个能组成2,第0个和第2个能组成2 +一共就3种方法,所以返回3 + +### [Code12_CoinsWayNoLimit](./c0700_动态规划/Code12_CoinsWayNoLimit.java) +arr是面值数组,其中的值都是正数且没有重复。再给定一个正数aim。 +每个值都认为是一种面值,且认为**张数是无限的**。 +返回组成aim的方法数 +例如:arr = {1,2},aim = 4 +方法如下:1+1+1+1、1+1+2、2+2 +一共就3种方法,所以返回3 + +### [Code13_CoinsWaySameValueSamePapper](./c0700_动态规划/Code13_CoinsWaySameValueSamePapper.java) +*WIP: 优化 -> 一维* + +arr是货币数组,其中的值都是正数 +每个值都认为是一张货币, +认为值相同的货币没有任何不同, +返回组成aim的方法数 +例如:arr = {1,2,1,1},aim = 4 +方法:1+1+2 +一共就1种方法,所以返回1 + +### [Code14_MinCoinsNoLimit](./c0700_动态规划/Code14_MinCoinsNoLimit.java) +arr是面值数组,其中的值都是正数且没有重复。再给定一个正数aim。 +每个值都认为是一种面值,且认为张数是无限的。 +返回组成aim的最少货币数 + +### [Code15_BobDie](./c0700_动态规划/Code15_BobDie.java) +*WIP: 优化 -> 一维* + +给定5个参数,N,M,row,col,k +表示在N*M的区域上,醉汉Bob初始在(row,col)位置 +Bob一共要迈出k步,且每步都会等概率向上下左右四个方向走一个单位 +任何时候Bob只要离开N*M的区域,就直接死亡 +返回k步之后,Bob还在N*M的区域的概率 + +### [Code16_KillMonster](./c0700_动态规划/Code16_KillMonster.java) +给定3个参数,N,M,K +怪兽有N滴血,等着英雄来砍自己 +英雄每一次打击,都会让怪兽流失[0~M]的血量 +到底流失多少?每一次在[0~M]上等概率的获得一个值 +求K次打击之后,英雄把怪兽砍死的概率 + +### [Code17_SplitNumber](./c0700_动态规划/Code17_SplitNumber.java) +给定一个正数n,求n的裂开方法数, +规定:后面的数不能比前面的数小 +比如4的裂开方法有: +1+1+1+1、1+1+2、1+3、2+2、4 +5种,所以返回5 + +### [Code18_SplitSumClosed](./c0700_动态规划/Code18_SplitSumClosed.java) +给定一个正数数组arr, +请把arr中所有的数分成两个集合,尽量让两个集合的累加和接近 +返回最接近的情况下,较小集合的累加和 + +### [Code19_SplitSumClosedSizeHalf](./c0700_动态规划/Code19_SplitSumClosedSizeHalf.java) +给定一个正数数组arr,请把arr中所有的数分成两个集合 +如果arr长度为偶数,两个集合包含数的个数要一样多 +如果arr长度为奇数,两个集合包含数的个数必须只差一个 +请尽量让两个集合的累加和接近 +返回最接近的情况下,较小集合的累加和 + +### [Code20_NQueens](./c0700_动态规划/Code20_NQueens.java) +N皇后问题是指在N*N的棋盘上要摆N个皇后, +要求任何两个皇后不同行、不同列, 也不在同一条斜线上 +给定一个整数n,返回n皇后的摆法有多少种。n=1,返回1 +n=2或3,2皇后和3皇后问题无论怎么摆都不行,返回0 +n=8,返回92 diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" index 1a1b612d..75fad309 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" @@ -1,7 +1,81 @@ package algorithmzuo.b_体系学习班.c0700_动态规划; +import org.junit.Test; + /** * Created by nibnait on 2022/11/06 */ public class Code01_RobotWalk { + + @Test + public void test() { + + int N = 9; + int M = 1; + int K = 4; + int P = 5; + int ans1 = robotWalkRecur(N, M, K, P); + System.out.println(ans1); + + int ans2 = robotWalkDp(N, M, K, P); + System.out.println(ans2); + } + + /** + * @param n 格子范围 1 ~ n + * @param m 当前在 m 位置 + * @param k 必须走 k 步 + * @param p 最终到达 p 位置 + * @return 一共有多少种走法 + */ + public int robotWalkRecur(int n, int m, int k, int p) { + if (m <= 0 || m >= n || p <= 0 || p >= n) { + return -1; + } + return process1(n, m, k, p); + } + + private int process1(int n, int cur, int rest, int p) { + if (rest == 0) { + return cur == p ? 1 : 0; + } + if (cur == n) { + return process1(n, cur - 1, rest - 1, p); + } + if (cur == 1) { + return process1(n, cur + 1, rest - 1, p); + } + return process1(n, cur - 1, rest - 1, p) + process1(n, cur + 1, rest - 1, p); + } + + /** + * @param n 格子范围 1 ~ n + * @param m 当前在 m 位置 + * @param k 必须走 k 步 + * @param p 最终到达 p 位置 + * @return 一共有多少种走法 + */ + public int robotWalkDp(int n, int m, int k, int p) { + if (m <= 0 || m >= n || p <= 0 || p >= n) { + return -1; + } + + int[][] dp = new int[n + 1][k + 1]; + // 还剩0步时,只有到达 p 位置,才算有1种走法 + dp[p][0] = 1; + + for (int col = 1; col <= k; col++) { + // 第1行,只依赖 第2行,前一列 位置的值 + dp[1][col] = dp[2][col - 1]; + + for (int row = 2; row <= n-1; row++) { + // [row][col] 位置 + dp[row][col] = dp[row - 1][col - 1] + dp[row + 1][col - 1]; + } + + // 最后一行,只依赖 倒数第2行,前一列 位置的值 + dp[n][col] = dp[n-1][col - 1]; + } + return dp[m][k]; + } } diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code02_CardsInLine.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code02_CardsInLine.java" new file mode 100644 index 00000000..3dca1f44 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code02_CardsInLine.java" @@ -0,0 +1,111 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import lombok.extern.slf4j.Slf4j; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/12 + */ +@Slf4j +public class Code02_CardsInLine { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_10; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int[] arr = SysRandom.randomArrNaturalNumRandomLength(20); + SysOut.printArray(arr); + + int ans1 = winRecur(arr); + int ans2 = winDp(arr); + + if (ans1 != ans2) { + SysOut.printArray(arr); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + + SysOut.println(ans1); + } + + /** + * 两人抽牌,返回获胜者 获得的点数 + */ + public int winRecur(int[] arr) { + if (arr == null || arr.length == 0) { + return 0; + } + + int first = processFirst(arr, 0, arr.length - 1); + int second = processSecond(arr, 0, arr.length - 1); + + return Math.max(first, second); + } + + // 第1个抽牌的人。返回当前牌面的最好结果 + private int processFirst(int[] arr, int left, int right) { + if (left == right) { + return arr[left]; + } + + int p1 = arr[left] + processSecond(arr, left + 1, right); + int p2 = arr[right] + processSecond(arr, left, right - 1); + return Math.max(p1, p2); + } + + // 第2个抽牌的人。返回当前牌面的最好结果 + private int processSecond(int[] arr, int left, int right) { + if (left == right) { + // 就剩1张牌了,但是被对手拿走了。 + return 0; + } + + // 对手拿了当前的 arr[left],只能争取在 left+1, right 上 去拿最好结果了 + int p1 = processFirst(arr, left + 1, right); + // 对手拿了当前的 arr[right] + int p2 = processFirst(arr, left, right - 1); + // 大值已经被对手拿走了,所以只剩下小值了。 + return Math.min(p1, p2); + } + + + /** + * dp数组 + */ + public int winDp(int[] arr) { + if (arr == null || arr.length == 0) { + return 0; + } + + int length = arr.length; + int[][] firstMap = new int[length][length]; + int[][] secondMap = new int[length][length]; + + for (int i = 0; i < length; i++) { + firstMap[i][i] = arr[i]; + } + + for (int startCol = 1; startCol < length; startCol++) { + // 对角线 斜着填 + int row = 0; + int col = startCol; + while (col < length) { + firstMap[row][col] = Math.max(arr[row] + secondMap[row + 1][col], arr[col] + secondMap[row][col - 1]); + secondMap[row][col] = Math.min(firstMap[row + 1][col], firstMap[row][col - 1]); + row++; + col++; + } + } + + return Math.max(firstMap[0][length - 1], secondMap[0][length - 1]); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code03_Knapsack.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code03_Knapsack.java" new file mode 100644 index 00000000..ebe13fd3 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code03_Knapsack.java" @@ -0,0 +1,94 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/12 + */ +public class Code03_Knapsack { + + @Test + public void test() { + int[] weights = {3, 2, 4, 7, 3, 1, 7}; + int[] values = {5, 6, 3, 19, 12, 4, 2}; + int bag = 15; + System.out.println(maxValue(weights, values, bag)); + System.out.println(dp(weights, values, bag)); + } + + /** + * @param weights i号物品的重量 + * @param values i好物品的价值 + * @param bag 背包的容量 + * @return 背包能装下的最大价值 + */ + public int maxValue(int[] weights, int[] values, int bag) { + if (weights == null || values == null || weights.length != values.length || weights.length == 0) { + return 0; + } + + return process(weights, values, 0, bag); + } + +// private int process(int[] weights, int[] values, int index, int bagRest) { +// if (bagRest < 0) { +// return 0; +// } +// if (index == weights.length) { +// return 0; +// } +// if (weights[index] > bagRest) { +// return process(weights, values, index + 1, bagRest); +// } +// return Math.max(process(weights, values, index + 1, bagRest), values[index] + process(weights, values, index + 1, bagRest - weights[index])); +// } + // 上面这个 确实是自然智慧想出来的。但是不太好转dp + private int process(int[] weights, int[] values, int index, int bagRest) { + if (bagRest < 0) { + return -1; + } + if (index == weights.length) { + return 0; + } + + int p1 = process(weights, values, index + 1, bagRest); + int p2 = 0; + int next = process(weights, values, index + 1, bagRest - weights[index]); + if (next != -1) { + p2 = values[index] + next; + } + return Math.max(p1, p2); + } + + /** + * 转成 dp 数组 + */ + public int dp(int[] weights, int[] values, int bag) { + if (weights == null || values == null || weights.length != values.length || weights.length == 0) { + return 0; + } + + // bag 0 ~ bag + // index 0 ~ length + int length = weights.length; + int[][] dp = new int[length + 1][bag + 1]; + + // dp[i][length] = 0, 已完成 + + // dp[index][bagRest] 依赖 Math.max(dp[index+1][bagRest], values[index] + dp[index+1][bagRest - weights[index]) + for (int index = length - 1; index >= 0; index--) { + for (int bagRest = 0; bagRest <= bag; bagRest++) { + int p1 = dp[index + 1][bagRest]; + int p2 = 0; + if (bagRest - weights[index] >= 0) { + int next = dp[index + 1][bagRest - weights[index]]; + p2 = next + values[index]; + } + dp[index][bagRest] = Math.max(p1, p2); + } + } + + return dp[0][bag]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code04_ConvertToLetterString.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code04_ConvertToLetterString.java" new file mode 100644 index 00000000..7d5f5318 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code04_ConvertToLetterString.java" @@ -0,0 +1,89 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/12 + */ +public class Code04_ConvertToLetterString { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + String s = SysRandom.generateStringNaturalNum(30); +// s = "111"; +// s = "1263121"; + int ans1 = numbers(s); + int ans2 = dp(s); + + if (ans1 != ans2) { + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + + SysOut.printf("s:{}, ans: {}", s, ans1); + } + + /** + * 暴力递归 + */ + public int numbers(String s) { + if (s == null || s.length() == 0) { + return 0; + } + + char[] str = s.toCharArray(); + return process(str, 0); + } + + private int process(char[] str, int index) { + if (index == str.length) { + return 1; + } + if (str[index] == '0') { + return 0; + } + + int p1 = process(str, index + 1); + int p2 = 0; + if (index + 1 < str.length && (str[index] - '0') * 10 + str[index + 1] - '0' <= 26) { + p2 = process(str, index + 2); + } + return p1 + p2; + } + + /** + * dp数组 + */ + public int dp(String s) { + if (s == null || s.length() == 0) { + return 0; + } + + char[] str = s.toCharArray(); + int[] dp = new int[str.length + 1]; + dp[str.length] = 1; + for (int index = str.length - 1; index >= 0; index--) { + if (str[index] == '0') { + continue; + } + int ways = dp[index + 1]; + if (index + 1 < str.length && (str[index] - '0') * 10 + str[index + 1] - '0' <= 26) { + ways += process(str, index + 2); + } + dp[index] = ways; + } + + return dp[0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code05_StickersToSpellWord.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code05_StickersToSpellWord.java" new file mode 100644 index 00000000..8dba89a7 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code05_StickersToSpellWord.java" @@ -0,0 +1,180 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.util.SysOut; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by nibnait on 2022/11/12 + */ +public class Code05_StickersToSpellWord { + + @Test + public void test() { + String[] stickers = new String[]{"ba", "c", "abcd"}; + String target = "babac"; + + int ans1 = minStickers1(stickers, target); + int ans2 = minStickers2(stickers, target); + int ans3 = minStickers3(stickers, target); + + if (ans1 != ans2 || ans2 != ans3) { + SysOut.printf("ans1: {}, ans2: {}, ans3: {}", ans1, ans2, ans3); + } + } + + /** + * https://leetcode.com/problems/stickers-to-spell-word + * 暴力递归 + */ + public int minStickers1(String[] stickers, String target) { + if (stickers == null || stickers.length == 0) { + return -1; + } + + int ans = process1(stickers, target); + return ans == Integer.MAX_VALUE ? -1 : ans; + } + + private int process1(String[] stickers, String target) { + if (target.length() == 0) { + return 0; + } + + int min = Integer.MAX_VALUE; + for (String sticker : stickers) { + String rest = minus1(target, sticker); + if (rest.length() != target.length()) { + min = Math.min(min, process1(stickers, rest)); + } + } + return min + (min == Integer.MAX_VALUE ? 0 : 1); + } + + private String minus1(String target, String sticker) { + int[] targetCounts = new int[26]; + for (char c : target.toCharArray()) { + targetCounts[c - 'a']++; + } + + for (char c : sticker.toCharArray()) { + if (targetCounts[c - 'a'] > 0) { + targetCounts[c - 'a']--; + } + } + + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < targetCounts.length; i++) { + if (targetCounts[i] > 0) { + for (int j = 0; j < targetCounts[i]; j++) { + builder.append((char) ('a' + i)); + } + } + } + return builder.toString(); + } + + /** + * 词频统计 + 剪枝 + */ + public int minStickers2(String[] stickers, String target) { + if (target.length() == 0) { + return 0; + } + + int[][] sCounts = new int[stickers.length][26]; + for (int i = 0; i < stickers.length; i++) { + for (char c : stickers[i].toCharArray()) { + sCounts[i][c - 'a']++; + } + } + + int min = process2(sCounts, target); + return min == Integer.MAX_VALUE ? -1 : min; + } + + private int process2(int[][] stickers, String targetStr) { + if (targetStr.length() == 0) { + return 0; + } + + int[] target = new int[26]; + char[] targetChar = targetStr.toCharArray(); + for (char c : targetChar) { + target[c - 'a']++; + } + + int min = Integer.MAX_VALUE; + for (int[] sticker : stickers) { + // 每次只尝试含有 targetChar[0] 字符的贴纸。 + if (sticker[targetChar[0] - 'a'] > 0) { + String rest = minus2(target, sticker); + min = Math.min(min, process2(stickers, rest)); + } + } + + return min + (min == Integer.MAX_VALUE ? 0 : 1); + } + + private String minus2(int[] target, int[] sticker) { + StringBuilder builder = new StringBuilder(); + for (int i = 0; i < 26; i++) { + int nums = target[i] - sticker[i]; + for (int j = 0; j < nums; j++) { + builder.append((char) ('a' + i)); + } + } + return builder.toString(); + } + + /** + * 此题无法转成dp严格依赖数组 + * 只能加个 dp数组 缓存优化 + */ + private int minStickers3(String[] stickers, String target) { + if (target.length() == 0) { + return 0; + } + + int[][] sCounts = new int[stickers.length][26]; + for (int i = 0; i < stickers.length; i++) { + for (char c : stickers[i].toCharArray()) { + sCounts[i][c - 'a']++; + } + } + + Map dp = new HashMap<>(); + dp.put("", 0); + + int min = process3(sCounts, target, dp); + return min == Integer.MAX_VALUE ? -1 : min; + } + + private int process3(int[][] stickers, String targetStr, Map dp) { + if (dp.containsKey(targetStr)) { + return dp.get(targetStr); + } + + int[] target = new int[26]; + char[] targetChar = targetStr.toCharArray(); + for (char c : targetChar) { + target[c - 'a']++; + } + + int min = Integer.MAX_VALUE; + for (int[] sticker : stickers) { + // 每次只尝试含有 targetChar[0] 字符的贴纸。 + if (sticker[targetChar[0] - 'a'] > 0) { + String rest = minus2(target, sticker); + min = Math.min(min, process3(stickers, rest, dp)); + } + } + + int ans = min + (min == Integer.MAX_VALUE ? 0 : 1); + dp.put(targetStr, ans); + return ans; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code06_LongestCommonSubsequence.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code06_LongestCommonSubsequence.java" new file mode 100644 index 00000000..4b3a34a6 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code06_LongestCommonSubsequence.java" @@ -0,0 +1,155 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import cn.hutool.core.lang.Assert; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code06_LongestCommonSubsequence { + + @Test + public void test() { + String str1 = "a12b3c456d"; + String str2 = "1ef23ghi4j56k"; + int ans1 = longestCommonSubsequence1(str1, str2); + int ans2 = longestCommonSubsequence2(str1, str2); + Assert.equals(ans1, ans2); + + str1 = "abcde"; + str2 = "ace"; + ans1 = longestCommonSubsequence1(str1, str2); + ans2 = longestCommonSubsequence2(str1, str2); + Assert.equals(ans1, ans2); + } + + /** + * https://leetcode.com/problems/longest-common-subsequence/ + * 最长公共子序列 + */ +/* + str1[0...p1]和str2[0...p2],这个范围上最长公共子序列长度是多少? + 可能性分类: + a) 最长公共子序列,一定不以str1[p1]字符结尾、也一定不以str2[p2]字符结尾 + b) 最长公共子序列,可能以str1[p1]字符结尾、但是一定不以str2[p2]字符结尾 + c) 最长公共子序列,一定不以str1[p1]字符结尾、但是可能以str2[p2]字符结尾 + d) 最长公共子序列,必须以str1[p1]字符结尾、也必须以str2[p2]字符结尾 + 注意:a)、b)、c)、d)并不是完全互斥的,他们可能会有重叠的情况 + 但是可以肯定,答案不会超过这四种可能性的范围 + 那么我们分别来看一下,这几种可能性怎么调用后续的递归。 + a) 最长公共子序列,一定不以str1[p1]字符结尾、也一定不以str2[p2]字符结尾 + 如果是这种情况,那么有没有str1[p1]和str2[p2]就根本不重要了,因为这两个字符一定没用啊 + 所以砍掉这两个字符,最长公共子序列 = str1[0...p1-1]与str2[0...p2-1]的最长公共子序列长度(后续递归) + b) 最长公共子序列,可能以str1[p1]字符结尾、但是一定不以str2[p2]字符结尾 + 如果是这种情况,那么我们可以确定str2[p2]一定没有用,要砍掉;但是str1[p1]可能有用,所以要保留 + 所以,最长公共子序列 = str1[0...p1]与str2[0...p2-1]的最长公共子序列长度(后续递归) + c) 最长公共子序列,一定不以str1[p1]字符结尾、但是可能以str2[p2]字符结尾 + 跟上面分析过程类似,最长公共子序列 = str1[0...p1-1]与str2[0...p2]的最长公共子序列长度(后续递归) + d) 最长公共子序列,必须以str1[p1]字符结尾、也必须以str2[p2]字符结尾 + 同时可以看到,可能性d)存在的条件,一定是在str1[p1] == str2[p2]的情况下,才成立的 + 所以,最长公共子序列总长度 = str1[0...p1-1]与str2[0...p2-1]的最长公共子序列长度(后续递归) + 1(共同的结尾) + 综上,四种情况已经穷尽了所有可能性。四种情况中取最大即可 + 其中b)、c)一定参与最大值的比较, + 当str1[p1] == str2[p2]时,a)一定比d)小,所以d)参与 + 当str1[p1] != str2[p2]时,d)压根不存在,所以a)参与 + 但是再次注意了! + a)是:str1[0...p1-1]与str2[0...p2-1]的最长公共子序列长度 + b)是:str1[0...p1]与str2[0...p2-1]的最长公共子序列长度 + c)是:str1[0...p1-1]与str2[0...p2]的最长公共子序列长度 + a)中str1的范围 < b)中str1的范围,a)中str2的范围 == b)中str2的范围 + 所以a)不用求也知道,它比不过b)啊,因为有一个样本的范围比b)小啊! + a)中str1的范围 == c)中str1的范围,a)中str2的范围 < c)中str2的范围 + 所以a)不用求也知道,它比不过c)啊,因为有一个样本的范围比c)小啊! + 至此,可以知道,a)就是个垃圾,有它没它,都不影响最大值的决策 + 所以,当str1[p1] == str2[p2]时,b)、c)、d)中选出最大值 + 当str1[p1] != str2[p2]时,b)、c)中选出最大值 +*/ + public int longestCommonSubsequence1(String str1, String str2) { + if (str1 == null || str1.length() == 0 || str2 == null || str2.length() == 0) { + return 0; + } + + return process(str1.toCharArray(), str2.toCharArray(), str1.length() - 1, str2.length() - 1); + } + + private int process(char[] str1, char[] str2, int p1, int p2) { + if (p1 == 0 && p2 == 0) { + // str1[0..0]和str2[0..0],都只剩一个字符了 + // 那如果字符相等,公共子序列长度就是1,不相等就是0 + // 这显而易见 + return str1[p1] == str2[p2] ? 1 : 0; + } else if (p1 == 0) { + // 这里的情况为: + // str1[0...0]和str2[0...p2],str1只剩1个字符了,但是str2不只一个字符 + // 因为str1只剩一个字符了,所以str1[0...0]和str2[0...p2]公共子序列最多长度为1 + // 如果str1[0] == str2[p2],那么此时相等已经找到了!公共子序列长度就是1,也不可能更大了 + // 如果str1[0] != str2[p2],只是此时不相等而已, + // 那么str2[0...p2-1]上有没有字符等于str1[0]呢?不知道,所以递归继续找 + if (str1[p1] == str2[p2]) { + return 1; + } else { + return process(str1, str2, 0, p2 - 1); + } + } else if (p2 == 0) { + // 和上面的else if同理 + // str1[0...p1]和str2[0...0],str2只剩1个字符了,但是str1不只一个字符 + // 因为str2只剩一个字符了,所以str1[0...p1]和str2[0...0]公共子序列最多长度为1 + // 如果str1[p1] == str2[0],那么此时相等已经找到了!公共子序列长度就是1,也不可能更大了 + // 如果str1[p1] != str2[0],只是此时不相等而已, + // 那么str1[0...p1-1]上有没有字符等于str2[0]呢?不知道,所以递归继续找 + if (str1[p1] == str2[p2]) { + return 1; + } else { + return process(str1, str2, p1 - 1, 0); + } + } else { // p1 != 0 && p2 != 0 + // 这里的情况为: + // str1[0...p1]和str2[0...p1],str1和str2都不只一个字符 + // 看函数开始之前的注释部分 + // ans1就是可能性c) + int ans1 = process(str1, str2, p1 - 1, p2); + // ans2就是可能性b) + int ans2 = process(str1, str2, p1, p2 - 1); + // ans3就是可能性d),如果可能性d)存在,即str1[p1] == str2[p2],那么p3就求出来,参与pk + // 如果可能性d)不存在,即str1[p1] != str2[p2],那么让p3等于0,然后去参与pk,反正不影响 + int ans3 = str1[p1] == str2[p2] ? (1 + process(str1, str2, p1 - 1, p2 - 1)) : process(str1, str2, p1 - 1, p2 - 1); + return Math.max(ans1, Math.max(ans2, ans3)); + } + } + + /** + * dp数组 + */ + public int longestCommonSubsequence2(String str1, String str2) { + if (str1 == null || str1.length() == 0 || str2 == null || str2.length() == 0) { + return 0; + } + + char[] s1 = str1.toCharArray(); + char[] s2 = str2.toCharArray(); + int[][] dp = new int[str1.length()][str2.length()]; + dp[0][0] = s1[0] == s2[0] ? 1 : 0; + + // 第0列 + for (int p2 = 1; p2 < s2.length; p2++) { + dp[0][p2] = s1[0] == s2[p2] ? 1 : dp[0][p2 - 1]; + } + + // 第0行 + for (int p1 = 1; p1 < s1.length; p1++) { + dp[p1][0] = s1[p1] == s2[0] ? 1 : dp[p1 - 1][0]; + } + + for (int p1 = 1; p1 < s1.length; p1++) { + for (int p2 = 1; p2 < s2.length; p2++) { + int ans1 = dp[p1 - 1][p2]; + int ans2 = dp[p1][p2 - 1]; + int ans3 = s1[p1] == s2[p2] ? (1 + dp[p1 - 1][p2 - 1]) : dp[p1 - 1][p2 - 1]; + dp[p1][p2] = Math.max(ans1, Math.max(ans2, ans3)); + } + } + + return dp[s1.length - 1][s2.length - 1]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code07_PalindromeSubsequence.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code07_PalindromeSubsequence.java" new file mode 100644 index 00000000..a1894d31 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code07_PalindromeSubsequence.java" @@ -0,0 +1,84 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code07_PalindromeSubsequence { + + @Test + public void test() { + String str = "a12b3c43def2ghi1kpm"; + int ans1 = longestPalindromeSubseq1(str); + int ans2 = longestPalindromeSubseq2(str); + + if (ans1 != ans2) { + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + } + + } + + /** + * https://leetcode.com/problems/longest-palindromic-subsequence/ + *

+ * 返回这个字符串的最长回文子序列长度 + */ + public int longestPalindromeSubseq1(String str) { + if (str == null || str.length() == 0) { + return 0; + } + + return process(str.toCharArray(), 0, str.length() - 1); + } + + private int process(char[] str, int left, int right) { + if (left == right) { + return 1; + } + + if (left + 1 == right) { + return str[left] == str[right] ? 2 : 1; + } + + int p1 = process(str, left + 1, right); + int p2 = process(str, left, right - 1); + int p3 = str[left] == str[right] ? 2 : 0; + p3 += process(str, left + 1, right - 1); + return Math.max(p1, Math.max(p2, p3)); + } + + /** + * 转成 dp 数组 + */ + public int longestPalindromeSubseq2(String str) { + if (str == null || str.length() == 0) { + return 0; + } + + int length = str.length(); + int[][] dp = new int[length][length]; + + char[] s = str.toCharArray(); + for (int i = 0; i < length; i++) { + dp[i][i] = 1; + if (i + 1 < length) { + dp[i][i + 1] = s[i] == s[i + 1] ? 2 : 1; + } + } + + for (int left = length - 3; left >= 0; left--) { + for (int right = left + 2; right < length; right++) { + int p1 = dp[left + 1][right]; + int p2 = dp[left][right - 1]; + int p3 = s[left] == s[right] ? 2 : 0; + p3 += dp[left + 1][right - 1]; + dp[left][right] = Math.max(p1, Math.max(p2, p3)); + } + } + + return dp[0][length - 1]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code08_HorseJump.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code08_HorseJump.java" new file mode 100644 index 00000000..b0106fbc --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code08_HorseJump.java" @@ -0,0 +1,103 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code08_HorseJump { + + @Test + public void test() { + int x = 7; + int y = 7; + int k = 10; + + int ans1 = ways(x, y, k); + int ans2 = dp(x, y, k); + + if (ans1 != ans2) { + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + } + } + + private static final int tableXLength = 9; + private static final int tableYLength = 10; + + /** + * 从(0,0) 出发,必须走 k 步,落在 (x, y) 位置 + *

+ * 有多少种走法? + */ + public int ways(int x, int y, int k) { + if (x < 0 || x >= tableXLength || y < 0 || y >= tableYLength) { + return 0; + } + return process(x, y, 0, 0, k); + } + + /** + * 终点 (x, y) + * 当前走到了 (curX, curY) + * 还剩 rest 步 + *

+ * 有多少种走法? + */ + private int process(int x, int y, int curX, int curY, int rest) { + if (curX < 0 || curX >= tableXLength || curY < 0 || curY >= tableYLength) { + return 0; + } + if (rest == 0) { + return x == curX && y == curY ? 1 : 0; + } + + int ways = process(x, y, curX + 1, curY + 2, rest - 1); + ways += process(x, y, curX + 2, curY + 1, rest - 1); + ways += process(x, y, curX + 2, curY - 1, rest - 1); + ways += process(x, y, curX + 1, curY - 2, rest - 1); + ways += process(x, y, curX - 1, curY - 2, rest - 1); + ways += process(x, y, curX - 2, curY - 1, rest - 1); + ways += process(x, y, curX - 2, curY + 1, rest - 1); + ways += process(x, y, curX - 1, curY + 2, rest - 1); + return ways; + } + + /** + * 转成 dp 数组 + *

+ * 再优化,就是把 搞两个二维数组即可 + */ + public int dp(int x, int y, int k) { + if (x < 0 || x >= tableXLength || y < 0 || y >= tableYLength) { + return 0; + } + + int[][][] dp = new int[tableXLength][tableYLength][k + 1]; + dp[x][y][0] = 1; + + for (int rest = 1; rest <= k; rest++) { + for (int curX = 0; curX < tableXLength; curX++) { + for (int curY = 0; curY < tableYLength; curY++) { + int ways = getValue(dp, curX + 1, curY + 2, rest - 1); + ways += getValue(dp, curX + 2, curY + 1, rest - 1); + ways += getValue(dp, curX + 2, curY - 1, rest - 1); + ways += getValue(dp, curX + 1, curY - 2, rest - 1); + ways += getValue(dp, curX - 1, curY - 2, rest - 1); + ways += getValue(dp, curX - 2, curY - 1, rest - 1); + ways += getValue(dp, curX - 2, curY + 1, rest - 1); + ways += getValue(dp, curX - 1, curY + 2, rest - 1); + dp[curX][curY][rest] = ways; + } + } + } + return dp[0][0][k]; + } + + private int getValue(int[][][] dp, int x, int y, int k) { + if (x < 0 || x >= tableXLength || y < 0 || y >= tableYLength) { + return 0; + } + return dp[x][y][k]; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code09_Coffee.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code09_Coffee.java" new file mode 100644 index 00000000..8a4fd2aa --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code09_Coffee.java" @@ -0,0 +1,155 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.Comparator; +import java.util.PriorityQueue; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code09_Coffee { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int[] arr = SysRandom.randomArrNaturalNumRandomLength(10); + + int n = (int) (Math.random() * 7) + 1; + int a = (int) (Math.random() * 7) + 1; + int b = (int) (Math.random() * 10) + 1; + int ans1 = minTime(arr, n, a, b); + int ans2 = dp(arr, n, a, b); + if (ans1 != ans2) { + SysOut.printArray(arr); + SysOut.printf("n={} 个人\n a={} 洗干净\n b={} 挥发干净\n", a, b, n); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + private class Machine { + public int timePoint; + public int workTime; + + public Machine(int timePoint, int workTime) { + this.timePoint = timePoint; + this.workTime = workTime; + } + } + + private class MachineComparetor implements Comparator { + @Override + public int compare(Machine o1, Machine o2) { + return (o1.timePoint + o1.workTime) - (o2.timePoint + o2.workTime); + } + } + + public int minTime(int[] arr, int n, int a, int b) { + if (arr == null || arr.length == 0) { + return -1; + } + PriorityQueue heap = new PriorityQueue<>(new MachineComparetor()); + for (int workTime : arr) { + heap.add(new Machine(0, workTime)); + } + + int[] drinks = new int[n]; + for (int i = 0; i < n; i++) { + Machine cur = heap.poll(); + cur.timePoint += cur.workTime; + drinks[i] = cur.timePoint; + heap.add(cur); + } + + return bestTime(drinks, a, b, 0, 0); + } + + /** + * + * @param drinks 所有被子可以洗的时间 + * @param wash 单杯洗干净的时间点(串行) + * @param air 挥发干净的时间点(并行) + * @param free 洗的机器可以用的时间点 + * @param index 当前到了第 index 号杯子 + * @return drinks[index] 都变干净,最早的结束时间 + */ + private int bestTime(int[] drinks, int wash, int air, int free, int index) { + if (index == drinks.length) { + return 0; + } + + // index号杯子 决定洗 + int selfClean1 = Math.max(drinks[index], free) + wash; + int restClean1 = bestTime(drinks, wash, air, selfClean1, index + 1); + int p1 = Math.max(selfClean1, restClean1); + + // index号杯子 决定挥发 + int selfClean2 = drinks[index] + air; + int restClean2 = bestTime(drinks, wash, air, free, index + 1); + int p2 = Math.max(selfClean2, restClean2); + + return Math.min(p1, p2); + } + + /** + * dp 数组 + */ + public int dp(int[] arr, int n, int a, int b) { + if (arr == null || arr.length == 0) { + return -1; + } + PriorityQueue heap = new PriorityQueue<>(new MachineComparetor()); + for (int workTime : arr) { + heap.add(new Machine(0, workTime)); + } + + int[] drinks = new int[n]; + for (int i = 0; i < n; i++) { + Machine cur = heap.poll(); + cur.timePoint += cur.workTime; + drinks[i] = cur.timePoint; + heap.add(cur); + } + + return bestTime(drinks, a, b); + } + + private int bestTime(int[] drinks, int wash, int air) { + int N = drinks.length; + int maxFree = 0; + for (int i = 0; i < drinks.length; i++) { + maxFree = Math.max(maxFree, drinks[i]) + wash; + } + int[][] dp = new int[N + 1][maxFree + 1]; + for (int index = N - 1; index >= 0; index--) { + for (int free = 0; free <= maxFree; free++) { + int selfClean1 = Math.max(drinks[index], free) + wash; + if (selfClean1 > maxFree) { + break; // 因为后面的也都不用填了 + } + // index号杯子 决定洗 + int restClean1 = dp[index + 1][selfClean1]; + int p1 = Math.max(selfClean1, restClean1); + // index号杯子 决定挥发 + int selfClean2 = drinks[index] + air; + int restClean2 = dp[index + 1][free]; + int p2 = Math.max(selfClean2, restClean2); + dp[index][free] = Math.min(p1, p2); + } + } + return dp[0][0]; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code10_MinPathSum.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code10_MinPathSum.java" new file mode 100644 index 00000000..1ec211d1 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code10_MinPathSum.java" @@ -0,0 +1,93 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code10_MinPathSum { + + @Test + public void test() { + int rowSize = 10; + int colSize = 10; + int[][] m = SysRandom.generateMatrixNaturalNum(rowSize, colSize); + int ans1 = minPathSum1(m); + int ans2 = minPathSum2(m); + + if (ans1 != ans2) { + SysOut.printArray(m); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + public int minPathSum1(int[][] m) { + if (m == null || m.length == 0) { + return 0; + } + + return process(m, 0, 0); + } + + private int process(int[][] m, int x, int y) { + int xLen = m.length; + int yLen = m[0].length; + if (x == xLen - 1 && y == yLen - 1) { + return m[xLen - 1][yLen - 1]; + } + + // 往右走 + int p1 = Integer.MAX_VALUE; + if (x + 1 < xLen) { + p1 = m[x][y] + process(m, x + 1, y); + } + // 往下走 + int p2 = Integer.MAX_VALUE; + if (y + 1 < yLen) { + p2 = m[x][y] + process(m, x, y + 1); + } + return Math.min(p1, p2); + } + + /** + * 动态规划 + * 优化 -> 一维 + */ + public int minPathSum2(int[][] m) { + if (m == null || m.length == 0) { + return 0; + } + + int xLen = m.length; + int yLen = m[0].length; + int[][] dp = new int[xLen][yLen]; + dp[xLen - 1][yLen - 1] = m[xLen - 1][yLen - 1]; + // 最后一行 + for (int x = yLen - 2; x >= 0; x--) { + dp[xLen - 1][x] = m[xLen - 1][x] + dp[xLen - 1][x + 1]; + } + // 最后一列 + for (int y = xLen - 2; y >= 0; y--) { + dp[y][yLen - 1] = m[y][yLen - 1] + dp[y+1][yLen - 1]; + } + + for (int x = xLen - 2; x >= 0; x--) { + for (int y = yLen - 2; y >= 0; y--) { + // 往右走 + int p1 = m[x][y] + dp[x + 1][y]; + // 往下走 + int p2 = m[x][y] + dp[x][y + 1]; + dp[x][y] = Math.min(p1, p2); + } + } + + return dp[0][0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code11_CoinsWayEveryPaperDifferent.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code11_CoinsWayEveryPaperDifferent.java" new file mode 100644 index 00000000..83fd99cc --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code11_CoinsWayEveryPaperDifferent.java" @@ -0,0 +1,106 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code11_CoinsWayEveryPaperDifferent { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLen = 20; + int maxValue = 30; + int[] arr = SysRandom.generateArrNaturalNum(maxLen); + int aim = SysRandom.generateNaturalNum(maxValue); + +// arr = new int[]{1, 1, 1}; +// aim = 2; + int ans1 = coinWays1(arr, aim); + int ans2 = coinWays2(arr, aim); + + if (ans1 != ans2) { + SysOut.printf("arr:{}, aim: {}", arr, aim); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + private int coinWays1(int[] arr, int aim) { + if (arr == null || arr.length == 0) { + return 0; + } + + return process(arr, aim, 0); + } + + private int process(int[] arr, int rest, int index) { + if (rest == 0) { + return 1; + } + if (index == arr.length) { + return 0; + } + + // 选 arr[index] + int ways = process(arr, rest - arr[index], index + 1); + // 不选 arr[index] + ways += process(arr, rest, index + 1); + return ways; + } + + /** + * 动态规划 + * 优化 -> 一维 + */ + private int coinWays2(int[] arr, int aim) { + if (arr == null || arr.length == 0) { + return 0; + } + + int len = arr.length; + int[][] dp = new int[aim + 1][len]; + + // 第一行 + for (int index = 0; index < len; index++) { + dp[0][index] = 1; + } + + // 最后一列 + for (int rest = 1; rest <= aim; rest++) { + if (rest == arr[len - 1]) { + dp[rest][len - 1] = 1; + } + } + + // 普通位置 依赖后面的一行 + for (int index = len - 2; index >= 0; index--) { + for (int rest = 1; rest <= aim; rest++) { + // 选 arr[index] + int ways = 0; + if (rest - arr[index] >= 0) { + ways = dp[rest - arr[index]][index + 1]; + } + // 不选 arr[index] + ways += dp[rest][index + 1]; + dp[rest][index] = ways; + } + } + + return dp[aim][0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code12_CoinsWayNoLimit.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code12_CoinsWayNoLimit.java" new file mode 100644 index 00000000..9c750cc8 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code12_CoinsWayNoLimit.java" @@ -0,0 +1,109 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code12_CoinsWayNoLimit { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLen = 20; + int maxValue = 30; + int[] arr = SysRandom.generateArrPositiveIntegerNoRepeat(maxLen); + int aim = SysRandom.generateNaturalNum(maxValue); + +// arr = new int[]{1, 2}; +// aim = 4; + int ans1 = coinWays1(arr, aim); + int ans2 = coinWays2(arr, aim); + + if (ans1 != ans2) { + SysOut.printf("arr:{}, aim: {}", arr, aim); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + private int coinWays1(int[] arr, int aim) { + if (arr == null || arr.length == 0) { + return 0; + } + + return process(arr, aim, 0); + } + + private int process(int[] arr, int rest, int index) { + if (rest == 0) { + return 1; + } + if (index == arr.length) { + return 0; + } + + int ways = 0; + int cur = arr[index]; + int zhang = rest / cur; + for (int j = 0; j <= zhang; j++) { + ways += process(arr, rest - j * cur, index + 1); + } + + return ways; + } + + /** + * 动态规划 + */ + private int coinWays2(int[] arr, int aim) { + if (arr == null || arr.length == 0) { + return 0; + } + + int len = arr.length; + int[][] dp = new int[aim + 1][len]; + // 第一行 + for (int index = 0; index < len; index++) { + dp[0][index] = 1; + } + + // 最后一列 + for (int rest = 1; rest <= aim; rest++) { + int cur = arr[len - 1]; + if (rest % cur == 0 && rest / cur > 0) { + // 当前来到了 arr[len - 1] 这张牌。 + // 就看 用 x张 arr[len-1] 能不能组成 rest。能就算一种方法。 + dp[rest][len - 1] = 1; + } + } + + // 普通位置,依赖后面的一列 + for (int rest = 0; rest <= aim; rest++) { + for (int index = len - 2; index >= 0; index--) { + int ways = 0; + int cur = arr[index]; + int zhang = rest / cur; + for (int j = 0; j <= zhang; j++) { + ways += dp[rest - j * cur][index + 1]; + } + dp[rest][index] = ways; + } + } + + return dp[aim][0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code13_CoinsWaySameValueSamePapper.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code13_CoinsWaySameValueSamePapper.java" new file mode 100644 index 00000000..940f5e64 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code13_CoinsWaySameValueSamePapper.java" @@ -0,0 +1,143 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.HashMap; +import java.util.Map; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code13_CoinsWaySameValueSamePapper { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLen = 20; + int maxValue = 30; + int[] arr = SysRandom.generateArrPositiveInteger(maxLen); + int aim = SysRandom.generateNaturalNum(maxValue); + +// arr = new int[]{1, 2, 1, 1}; +// aim = 4; + int ans1 = coinWays1(arr, aim); + int ans2 = coinWays2(arr, aim); + + if (ans1 != ans2) { + SysOut.printArray(arr); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + private int coinWays1(int[] arr, int aim) { + if (arr == null || arr.length == 0) { + return 0; + } + + Info info = getInfo(arr); + + return process(info.coins, info.nums, aim, 0); + } + + private int process(int[] coins, int[] nums, int rest, int index) { + if (rest == 0) { + return 1; + } + if (index == coins.length) { + return 0; + } + + int cur = coins[index]; + int ways = 0; + for (int zhang = 0; zhang <= nums[index]; zhang++) { + ways += process(coins, nums, rest - cur * zhang, index + 1); + } + + return ways; + } + + private Info getInfo(int[] arr) { + Map info = new HashMap<>(); + for (int coin : arr) { + info.merge(coin, 1, Integer::sum); + } + + int[] coins = new int[info.size()]; + int[] nums = new int[info.size()]; + int i = 0; + for (Map.Entry entry : info.entrySet()) { + coins[i] = entry.getKey(); + nums[i++] = entry.getValue(); + } + + return new Info(coins, nums); + } + + private class Info { + public int[] coins; + public int[] nums; + + public Info(int[] coins, int[] nums) { + this.coins = coins; + this.nums = nums; + } + } + + /** + * 动态规划 + * 优化 -> 一维 + */ + private int coinWays2(int[] arr, int aim) { + if (arr == null || arr.length == 0) { + return 0; + } + + Info info = getInfo(arr); + int[] coins = info.coins; + int[] nums = info.nums; + + int len = coins.length; + int[][] dp = new int[aim + 1][len]; + // 第一行 + for (int index = 0; index < len; index++) { + dp[0][index] = 1; + } + + // 最后一列 + for (int rest = 1; rest <= aim; rest++) { + int cur = coins[len - 1]; + if (rest % cur == 0 && rest / cur <= nums[len - 1]) { + dp[rest][len - 1] = 1; + } + } + + // 普通位置,依赖后面的一列 + for (int index = len - 2; index >= 0; index--) { + for (int rest = 0; rest <= aim; rest++) { + int cur = coins[index]; + int ways = 0; + for (int zhang = 0; zhang <= nums[index]; zhang++) { + if (rest - cur * zhang >= 0) { + ways += dp[rest - cur * zhang][index + 1]; + } + } + dp[rest][index] = ways; + } + } + return dp[aim][0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code14_MinCoinsNoLimit.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code14_MinCoinsNoLimit.java" new file mode 100644 index 00000000..0af7dae4 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code14_MinCoinsNoLimit.java" @@ -0,0 +1,104 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code14_MinCoinsNoLimit { + + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLen = 20; + int maxValue = 30; + int[] arr = SysRandom.generateArrPositiveIntegerNoRepeat(maxLen); + int aim = SysRandom.generatePositiveInt(maxValue); + +// arr = new int[]{1, 2, 3}; +// aim = 4; + int ans1 = coinWays1(arr, aim); + int ans2 = coinWays2(arr, aim); + + if (ans1 != ans2) { + SysOut.printf("arr:{}, aim: {}", arr, aim); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + private int coinWays1(int[] arr, int aim) { + if (arr == null || arr.length == 0 || aim == 0) { + return 0; + } + + int ans = process(arr, aim, 0); + return ans == Integer.MAX_VALUE ? -1 : ans; + } + + private int process(int[] arr, int rest, int index) { + if (index == arr.length) { + return rest == 0 ? 0 : Integer.MAX_VALUE; + } + int cur = arr[index]; + int abs = Integer.MAX_VALUE; + for (int zhang = 0; zhang <= rest / cur; zhang++) { + int next = process(arr, rest - zhang * cur, index + 1); + if (next == Integer.MAX_VALUE) { + continue; + } + abs = Math.min(abs, zhang + next); + } + + return abs; + } + + /** + * 动态规划 + */ + private int coinWays2(int[] arr, int aim) { + if (arr == null || arr.length == 0 || aim == 0) { + return 0; + } + int len = arr.length; + int[][] dp = new int[aim + 1][len + 1]; + + // 最后一列 + dp[0][len] = 0; + for (int rest = 1; rest <= aim; rest++) { + dp[rest][len] = Integer.MAX_VALUE; + } + + // 普通位置,依赖后面的一列 + for (int index = len - 1; index >= 0; index--) { + for (int rest = 0; rest <= aim; rest++) { + int ans = Integer.MAX_VALUE; + int cur = arr[index]; + for (int zhang = 0; zhang <= rest / cur; zhang++) { + int next = dp[rest - zhang * cur][index + 1]; + if (next == Integer.MAX_VALUE) { + continue; + } + ans = Math.min(ans, zhang + next); + } + dp[rest][index] = ans; + } + } + + return dp[aim][0] == Integer.MAX_VALUE ? -1 : dp[aim][0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code15_BobDie.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code15_BobDie.java" new file mode 100644 index 00000000..a52febdd --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code15_BobDie.java" @@ -0,0 +1,100 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code15_BobDie { + + @Test + public void test() { + int row = 6; + int col = 6; + int k = 10; + int N = 50; + int M = 50; + double ans1 = livePosibility1(row, col, k, N, M); + double ans2 = livePosibility2(row, col, k, N, M); + + if (ans1 != ans2) { + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + public double livePosibility1(int row, int col, int k, int N, int M) { + if (row < 0 || row >= N || col < 0 || col >= N) { + return 0; + } + + int liveWays = process(N, M, row, col, k); + return liveWays / Math.pow(4, k); + } + + private int process(int n, int m, int curRow, int curCol, int rest) { + if (curRow < 0 || curRow >= n || curCol < 0 || curCol >= m) { + return 0; + } + if (rest == 0) { + return 1; + } + + // 上 + int ways = process(n, m, curRow - 1, curCol, rest - 1); + // 下 + ways += process(n, m, curRow + 1, curCol, rest - 1); + // 左 + ways += process(n, m, curRow, curCol - 1, rest - 1); + // 右 + ways += process(n, m, curRow, curCol + 1, rest - 1); + return ways; + } + + /** + * 动态规划 + * 优化 -> 二维 + */ + public double livePosibility2(int row, int col, int k, int n, int m) { + if (row < 0 || row >= n || col < 0 || col >= n) { + return 0; + } + + int[][][] dp = new int[n][m][k + 1]; + for (int i = 0; i < n; i++) { + for (int j = 0; j < m; j++) { + dp[i][j][0] = 1; + } + } + + for (int rest = 1; rest <= k; rest++) { + for (int curRow = 0; curRow < n; curRow++) { + for (int curCol = 0; curCol < m; curCol++) { + // 上 + int ways = getValue(dp, n, m, curRow - 1, curCol, rest - 1); + // 下 + ways += getValue(dp, n, m, curRow + 1, curCol, rest - 1); + // 左 + ways += getValue(dp, n, m, curRow, curCol - 1, rest - 1); + // 右 + ways += getValue(dp, n, m, curRow, curCol + 1, rest - 1); + dp[curCol][curRow][rest] = ways; + } + } + + } + + return dp[row][col][k] / Math.pow(4, k); + } + + private int getValue(int[][][] dp, int n, int m, int curRow, int curCol, int rest) { + if (curRow < 0 || curRow >= n || curCol < 0 || curCol >= m) { + return 0; + } + return dp[curRow][curCol][rest]; + } +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code16_KillMonster.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code16_KillMonster.java" new file mode 100644 index 00000000..e5e3dd97 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code16_KillMonster.java" @@ -0,0 +1,97 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code16_KillMonster { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int nMax = 10; + int mMax = 10; + int kMax = 10; + + int n = SysRandom.generateNaturalNum(nMax); + int m = SysRandom.generateNaturalNum(mMax); + int k = SysRandom.generateNaturalNum(kMax); + + double ans1 = killProbability1(n, m, k); + double ans2 = killProbability2(n, m, k); + + if (ans1 != ans2) { + SysOut.printf("n={}, m={}, k={}", n, m, k); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + } + + /** + * 暴力递归 + */ + private double killProbability1(int n, int m, int k) { + if (m * k < n || m <= 0 || k <= 0) { + return 0; + } + + long kill = process(m, n, k); + return kill / Math.pow(m + 1, k); + } + + private long process(int m, int restBlood, int restTimes) { + if (restTimes == 0) { + return restBlood <= 0 ? 1 : 0; + } + if (restBlood <= 0) { + return (long) Math.pow(m + 1, restTimes); + } + + long ways = 0; + for (int i = 0; i <= m; i++) { + ways += process(m, restBlood - i, restTimes - 1); + } + return ways; + } + + /** + * 动态规划 + */ + private double killProbability2(int n, int m, int k) { + if (m * k < n || m <= 0 || k <= 0) { + return 0; + } + long[][] dp = new long[n + 1][k + 1]; + // 第一列,只有 0滴血,省0次时,才算1种方法 + dp[0][0] = 1; + + // 从第2列开始,每次填一列 + // 依赖 前一列的值 + for (int restBlood = 0; restBlood <= n; restBlood++) { + for (int restTimes = 1; restTimes <= k; restTimes++) { + long ways = 0; + for (int i = 0; i <= m; i++) { + if (restBlood - i <= 0) { + ways += (long) Math.pow(m + 1, restTimes - 1); + } else { + ways += dp[restBlood - i][restTimes - 1]; + } + } + dp[restBlood][restTimes] = ways; + } + } + + return dp[n][k] / Math.pow(m + 1, k); + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code17_SplitNumber.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code17_SplitNumber.java" new file mode 100644 index 00000000..6a1d93cb --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code17_SplitNumber.java" @@ -0,0 +1,127 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code17_SplitNumber { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int test = 4; + int ans1 = ways(test); + int ans2 = dp1(test); + int ans3 = dp2(test); + + if (ans1 != ans2 || ans2 != ans3) { + SysOut.printf("ans1: {}, ans2: {}, ans3: {}", ans1, ans2, ans3); + throw new RuntimeException(); + } + + } + + /** + * 暴力递归 + */ + public int ways(int n) { + if (n <= 0) { + return 0; + } + if (n == 1) { + return 1; + } + + return process(1, n); + } + + /** + * @param pre 前面已经拆出来的数的和 + * @param rest 还剩 rest 需要去拆 + * @return 拆的方法数 + */ + private int process(int pre, int rest) { + if (rest == 0) { + return 1; + } + if (pre > rest) { + return 0; + } + int ways = 0; + for (int i = pre; i <= rest; i++) { + ways += process(i, rest - i); + } + return ways; + } + + /** + * 动态规划 + */ + public int dp1(int n) { + if (n <= 0) { + return 0; + } + if (n == 1) { + return 1; + } + + int[][] dp = new int[n + 1][n + 1]; + + // 第一列,第i行i列 + for (int i = 0; i <= n; i++) { + dp[i][0] = 1; + dp[i][i] = 1; + } + + for (int pre = n - 1; pre >= 1; pre--) { + for (int rest = pre + 1; rest <= n; rest++) { + int ways = 0; + for (int i = pre; i <= rest; i++) { + ways += dp[i][rest - i]; + } + dp[pre][rest] = ways; + } + } + + return dp[1][n]; + } + + /** + * 对 dp[i][rest - i] 的枚举值的优化 + * 通过观察 得出 dp[pre][rest] = dp[pre + 1][rest] + dp[pre][rest - pre]; + */ + public int dp2(int n) { + if (n <= 0) { + return 0; + } + if (n == 1) { + return 1; + } + + int[][] dp = new int[n + 1][n + 1]; + + // 第一列,第i行i列 + for (int i = 0; i <= n; i++) { + dp[i][0] = 1; + dp[i][i] = 1; + } + + for (int pre = n - 1; pre >= 1; pre--) { + for (int rest = pre + 1; rest <= n; rest++) { + dp[pre][rest] = dp[pre + 1][rest] + dp[pre][rest - pre]; + } + } + + return dp[1][n]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code18_SplitSumClosed.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code18_SplitSumClosed.java" new file mode 100644 index 00000000..31165536 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code18_SplitSumClosed.java" @@ -0,0 +1,111 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code18_SplitSumClosed { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLen = 20; + int maxValue = 50; + int[] arr = SysRandom.generateArrNaturalNum(maxLen, maxValue); + int ans1 = minSum1(arr); + int ans2 = minSum2(arr); + + if (ans1 != ans2) { + SysOut.printf("arr: {}, sum={}", arr, Arrays.stream(arr).sum()); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + + } + + /** + * 暴力递归 + */ + public int minSum1(int[] arr) { + if (arr == null || arr.length == 0) { + return 0; + } + + int sum = 0; + for (int i : arr) { + sum += i; + } + return process(arr, sum / 2, 0); + } + + /** + * 求从 arr 中选出一个子集的累加和 是 <= sum/2 && 最大的 + */ + private int process(int[] arr, int rest, int index) { + if (index == arr.length) { + return 0; + } + if (rest == 0) { + return 0; + } + + // 要 arr[index] + int sum1 = Integer.MIN_VALUE; + if (rest >= arr[index]) { + sum1 = arr[index] + process(arr, rest - arr[index], index + 1); + } + // 不要 arr[index] + int sum2 = process(arr, rest, index + 1); + return Math.max(sum1, sum2); + } + + /** + * 动态规划 + */ + public int minSum2(int[] arr) { + if (arr == null || arr.length == 0) { + return 0; + } + + int sum = 0; + for (int i : arr) { + sum += i; + } + + sum /= 2; + int len = arr.length; + int[][] dp = new int[sum + 1][len]; + // 最后一列 + for (int rest = arr[len - 1]; rest <= sum; rest++) { + dp[rest][len - 1] = arr[len - 1]; + } + + // 普通位置,依赖后面的一列 + for (int index = len - 2; index >= 0; index--) { + for (int rest = 0; rest <= sum; rest++) { + int sum1 = Integer.MIN_VALUE; + if (rest >= arr[index]) { + sum1 = arr[index] + dp[rest - arr[index]][index + 1]; + } + // 不要 arr[index] + int sum2 = dp[rest][index + 1]; + dp[rest][index] = Math.max(sum1, sum2); + } + } + + return dp[sum][0]; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code19_SplitSumClosedSizeHalf.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code19_SplitSumClosedSizeHalf.java" new file mode 100644 index 00000000..808aeb19 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code19_SplitSumClosedSizeHalf.java" @@ -0,0 +1,92 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import common.CommonConstants; +import common.util.SysOut; +import common.util.SysRandom; +import org.junit.Test; + +import java.util.Arrays; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code19_SplitSumClosedSizeHalf { + + @Test + public void loopTestCase() { + for (int i = 0; i < CommonConstants.TEST_CASE_COUNT_1000; i++) { + testCase(); + } + } + + @Test + public void testCase() { + int maxLen = 10; + int maxValue = 50; + int[] arr = SysRandom.generateArrNaturalNum(maxLen, maxValue); + int ans1 = minSum1(arr); + int ans2 = minSum2(arr); + + if (ans1 != ans2) { + SysOut.printf("arr: {}, sum={}", arr, Arrays.stream(arr).sum()); + SysOut.printf("ans1: {}, ans2: {}", ans1, ans2); + throw new RuntimeException(); + } + + } + + /** + * 暴力递归 + */ + public int minSum1(int[] arr) { + if (arr == null || arr.length == 0) { + return 0; + } + + int sum = 0; + for (int i : arr) { + sum += i; + } + + sum /= 2; + int len = arr.length / 2; + if (arr.length % 2 == 0) { + return process(arr, sum, 0, len); + } else { + return Math.max( + process(arr, sum, 0, len), + process(arr, sum, 0, len + 1) + ); + } + + } + + private int process(int[] arr, int sumRest, int index, int rest) { + if (index == arr.length) { + return rest == 0 ? 0 : -1; + } + + // 不要 + int sum1 = process(arr, sumRest, index + 1, rest); + + // 要 + int sum2 = -1; + int next = -1; + if (sumRest >= arr[index]) { + next = process(arr, sumRest - arr[index], index + 1, rest - 1); + } + if (next != -1) { + sum2 = arr[index] + next; + } + + return Math.max(sum1, sum2); + } + + /** + * 动态规划 + */ + public int minSum2(int[] arr) { + return 0; + } + +} diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code20_NQueens.java" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code20_NQueens.java" new file mode 100644 index 00000000..eccc6f88 --- /dev/null +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code20_NQueens.java" @@ -0,0 +1,115 @@ +package algorithmzuo.b_体系学习班.c0700_动态规划; + +import org.junit.Test; + +/** + * Created by nibnait on 2022/11/13 + */ +public class Code20_NQueens { + + @Test + public void test() { + int n = 13; + + long start = System.currentTimeMillis(); + System.out.println(NQueen2(n)); + long end = System.currentTimeMillis(); + System.out.println("cost time: " + (end - start) + "ms"); + + start = System.currentTimeMillis(); + System.out.println(NQueen1(n)); + end = System.currentTimeMillis(); + System.out.println("cost time: " + (end - start) + "ms"); + + } + + /** + * N皇后问题 + */ + public int NQueen1(int n) { + if (n <= 0) { + return 0; + } + if (n == 1) { + return 1; + } + + int[] record = new int[n]; + return process(record, 0); + } + + /** + * + * @param record record[i] 表示 第i行,皇后饭后了 record[i] 位置上 + * @param i 当前来到了第1行。 第 0...i-1 行,都已经放好了皇后 + * @return 当前情况下,继续往下摆,有多少种摆法。 + */ + private int process(int[] record, int i) { + if (i == record.length) { + return 1; + } + + int ans = 0; + // i行的皇后,放哪一列呢?j列, + for (int j = 0; j < record.length; j++) { + if (isValid(record, i, j)) { + record[i] = j; + ans += process(record, i + 1); + } + } + + return ans; + } + + /** + * + * @param record + * @param i 当前第 i 行 + * @param j 放在 j 位置上 + * @return 是否与 第 0...i-1 行 有冲突 + */ + private boolean isValid(int[] record, int i, int j) { + // 0..i-1 + for (int row = 0; row < i; row++) { + if (j == record[row] || Math.abs(record[row] - j) == Math.abs(i - row)) { + return false; + } + } + return true; + } + + /** + * 基于位运算解 N皇后问题 + * (时间复杂度不变,只是常数时间可以做到更少) + */ + public int NQueen2(int n) { + if (n < 1 || n > 32) { + return 0; + } + // 如果你是13皇后问题,limit 最右13个1,其他都是0 + int limit = n == 32 ? -1 : (1 << n) - 1; + return process2(limit, 0, 0, 0); + } + + // 7皇后问题 + // limit : 0....0 1 1 1 1 1 1 1 + // 之前皇后的列影响:colLim + // 之前皇后的左下对角线影响:leftDiaLim + // 之前皇后的右下对角线影响:rightDiaLim + public static int process2(int limit, int colLim, int leftDiaLim, int rightDiaLim) { + if (colLim == limit) { + return 1; + } + // pos中所有是1的位置,是你可以去尝试皇后的位置 + int pos = limit & (~(colLim | leftDiaLim | rightDiaLim)); + int mostRightOne = 0; + int res = 0; + while (pos != 0) { + mostRightOne = pos & (~pos + 1); + pos = pos - mostRightOne; + res += process2(limit, colLim | mostRightOne, (leftDiaLim | mostRightOne) << 1, + (rightDiaLim | mostRightOne) >>> 1); + } + return res; + } +} From f27e5c24062c1820420b93720ce32c4db935f847 Mon Sep 17 00:00:00 2001 From: tianbin Date: Tue, 22 Nov 2022 08:13:42 +0800 Subject: [PATCH 27/36] update 20221122 --- ...\346\216\245\351\233\250\346\260\264.java" | 43 +++++++++++--- ...\347\232\204\347\237\251\345\275\242.java" | 59 +++++++++++++++++++ ...\351\225\277\345\255\220\344\270\262.java" | 40 ++++++++++++- ...\345\212\240\346\262\271\347\253\231.java" | 51 +++++++++++++++- .../cc/tianbin/design_pattern/Singleton.java | 13 ---- .../java/\345\271\266\345\217\221/Main.java" | 8 +++ src/main/resources/META-INF/MANIFEST.MF | 3 + .../README.md" | 6 +- ...50\346\200\201\350\247\204\345\210\222.md" | 10 ++-- .../README.md" | 5 +- src/main/test/tmp/interview/Main.java | 14 +++++ 11 files changed, 223 insertions(+), 29 deletions(-) create mode 100644 "src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" delete mode 100644 src/main/java/cc/tianbin/design_pattern/Singleton.java create mode 100644 src/main/resources/META-INF/MANIFEST.MF create mode 100644 src/main/test/tmp/interview/Main.java diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" index 6b008f49..c5e8d3c9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" @@ -1,5 +1,6 @@ package algorithm_practice.LeetCode.code000; +import cn.hutool.core.lang.Assert; import junit.framework.TestCase; import org.junit.Test; @@ -25,36 +26,64 @@ public class H042_接雨水 extends TestCase { public void testCase() { // 6 int[] height = new int[]{0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}; - System.out.println(trap(height)); + Assert.equals(6, trap(height)); // 2 int[] height2 = new int[]{2, 0, 2}; - System.out.println(trap(height2)); + Assert.equals(2, trap(height2)); // 1 int[] height3 = new int[]{4, 2, 3}; - System.out.println(trap(height3)); + Assert.equals(1, trap(height3)); // 10 int[] height4 = new int[]{4, 2, 0, 3, 2, 4, 3, 4}; - System.out.println(trap(height4)); + Assert.equals(10, trap(height4)); // 6 int[] height5 = new int[]{0, 1, 0, 2, 1, 0, 1, 3, 2, 1, 2, 1}; - System.out.println(trap(height5)); + Assert.equals(6, trap(height5)); // 7 int[] height6 = new int[]{0,7,1,4,6}; - System.out.println(trap(height6)); + Assert.equals(7, trap(height6)); } + public int trap(int[] height) { + if (height == null || height.length == 0) { + return 0; + } + + int len = height.length; + + int leftMax = height[0]; + int rightMax = height[len - 1]; + int p1 = 1; + int p2 = len - 2; + int sum = 0; + while (p1 < p2) { + if (leftMax >= rightMax) { + // 右边更小 + sum += Math.max(0, rightMax - height[p2]); + rightMax = Math.max(rightMax, height[p2--]); + } else { + // 左边更小 + sum += Math.max(0, leftMax - height[p1]); + leftMax = Math.max(leftMax, height[p1++]); + } + } + + return sum; + } + + /* 单调栈结构: */ - public int trap(int[] height) { + public int trap2(int[] height) { int length = height.length; if (length < 3) { return 0; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" new file mode 100644 index 00000000..599227da --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" @@ -0,0 +1,59 @@ +package algorithm_practice.LeetCode.code000; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Stack; + +/** + * 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 + * 求在该柱状图中,能够勾勒出来的矩形的最大面积。 + * + * 输入:heights = [2,1,5,6,2,3] + * 输出:10 + * 解释:最大的矩形为图中红色区域,面积为 10 + * + * 输入: heights = [2,4] + * 输出: 4 + * + * https://leetcode.cn/problems/largest-rectangle-in-histogram/ + * Created by nibnait on 2022/11/16 + */ +public class H084_柱状图中最大的矩形 { + + @Test + public void test() { + int[] heights = new int[]{2,1,5,6,2,3}; + int ans = largestRectangleArea(heights); + Assert.assertEquals(10, ans); + + heights = new int[]{2,4}; + ans = largestRectangleArea(heights); + Assert.assertEquals(4, ans); + } + + public int largestRectangleArea(int[] heights) { + if (heights == null || heights.length == 0) { + return 0; + } + int maxArea = 0; + Stack stack = new Stack(); + for (int i = 0; i < heights.length; i++) { + while (!stack.isEmpty() && heights[i] <= heights[stack.peek()]) { + int j = stack.pop(); + int k = stack.isEmpty() ? -1 : stack.peek(); + int curArea = (i - k - 1) * heights[j]; + maxArea = Math.max(maxArea, curArea); + } + stack.push(i); + } + while (!stack.isEmpty()) { + int j = stack.pop(); + int k = stack.isEmpty() ? -1 : stack.peek(); + int curArea = (heights.length - k - 1) * heights[j]; + maxArea = Math.max(maxArea, curArea); + } + return maxArea; + } + +} diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" index c2940b9e..b9e1ee3a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" @@ -5,7 +5,9 @@ import junit.framework.TestCase; import org.junit.Test; +import java.util.HashMap; import java.util.HashSet; +import java.util.Map; /* 给定一个字符串,请你找出其中不含有重复字符的 最长子串 的长度。 @@ -98,6 +100,42 @@ public int lengthOfLongestSubstring(String s) { return Math.max(result, hashSet.size()); } + public int lengthOfLongestSubstring4(String str) { + if (str == null || str.length() == 0) { + return 0; + } + if (str.length() == 1) { + return 1; + } + char[] chars = str.toCharArray(); + if (str.length() == 2) { + return chars[0] == chars[1] ? 1 : 2; + } + + + int p1 = 0; + int p2 = 1; + int subLen = 0; + Map map = new HashMap<>(); + map.put(chars[p1], p1); + while (p2 < str.length()) { + char curChar = chars[p2]; + if (!map.containsKey(curChar)) { + map.put(curChar, p2); + p2 ++; + } else { + subLen = Math.max(subLen, map.size()); + Integer index = map.get(curChar); + for (int i = p1; i <= index; i++) { + map.remove(chars[i]); + } + p1 = index + 1; + } + } + + return Math.max(subLen, map.size()); + } + /** 法2:滑动窗口 O (N) p1 = 0,指向滑动窗口的起点 @@ -107,7 +145,7 @@ public int lengthOfLongestSubstring(String s) { 用HashSet来查询窗口内是否有当前最新字符arr[p2], 有则记下当前 p1++,并hashSet.remore(arr[p1]) 否则配hashSet.add(arr[p2]),result = Math.max(currentHashSet.size, result),p2++ - + 注意边界条件! */ private int lengthOfLongestSubstring3(String s) { diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" "b/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" index b585a03e..523e09fb 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" @@ -3,6 +3,8 @@ import org.junit.Assert; import org.junit.Test; +import java.util.LinkedList; + /** * 在一条环路上有 N 个加油站,其中第 i 个加油站有汽油 gas[i] 升。 *

@@ -69,6 +71,53 @@ public void testCase() { } + /** + * 窗口内最大值最小值的更新结构 + */ + public static int canCompleteCircuit(int[] gas, int[] cost) { + boolean[] good = goodArray(gas, cost); + for (int i = 0; i < gas.length; i++) { + if (good[i]) { + return i; + } + } + return -1; + } + + public static boolean[] goodArray(int[] g, int[] c) { + int N = g.length; + int M = N << 1; + int[] arr = new int[M]; + for (int i = 0; i < N; i++) { + arr[i] = g[i] - c[i]; + arr[i + N] = g[i] - c[i]; + } + for (int i = 1; i < M; i++) { + arr[i] += arr[i - 1]; + } + LinkedList w = new LinkedList<>(); + for (int i = 0; i < N; i++) { + while (!w.isEmpty() && arr[w.peekLast()] >= arr[i]) { + w.pollLast(); + } + w.addLast(i); + } + boolean[] ans = new boolean[N]; + for (int offset = 0, i = 0, j = N; j < M; offset = arr[i++], j++) { + if (arr[w.peekFirst()] - offset >= 0) { + ans[i] = true; + } + if (w.peekFirst() == i) { + w.pollFirst(); + } + while (!w.isEmpty() && arr[w.peekLast()] >= arr[j]) { + w.pollLast(); + } + w.addLast(j); + } + return ans; + } + /** * 换个思路:只遍历一遍。 * totalLeft = 总油量 - 总耗油量 @@ -80,7 +129,7 @@ public void testCase() { * * 不用担心 i+1 = gas.length,因为如果这样的话 totalLeft 一定< 0 */ - public int canCompleteCircuit(int[] gas, int[] cost) { + public int canCompleteCircuit4(int[] gas, int[] cost) { int curLeft = 0; int start = 0; int totalLeft = 0; diff --git a/src/main/java/cc/tianbin/design_pattern/Singleton.java b/src/main/java/cc/tianbin/design_pattern/Singleton.java deleted file mode 100644 index 9c188c71..00000000 --- a/src/main/java/cc/tianbin/design_pattern/Singleton.java +++ /dev/null @@ -1,13 +0,0 @@ -package cc.tianbin.design_pattern; - -/* - 单例模式 - */ -public class Singleton{ - - //饿汉,直接new - - //懒汉,用的时候才new - // 双重检查锁 -} - diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" index 412ad304..0ab41c16 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" @@ -48,5 +48,13 @@ public void testReentrantLook() throws InterruptedException { lock.lock(); lock.tryLock(); lock.tryLock(0, null); + + + // 公平锁 + ReentrantLock fairSync = new ReentrantLock(true); + // 非公平锁 + ReentrantLock nonfairSync = new ReentrantLock(false); + // 指的是lock方法,发生抢占那一刻,是直接去后面排队,还是先跟当前排到的人 cas 一下 + } } diff --git a/src/main/resources/META-INF/MANIFEST.MF b/src/main/resources/META-INF/MANIFEST.MF new file mode 100644 index 00000000..365eb694 --- /dev/null +++ b/src/main/resources/META-INF/MANIFEST.MF @@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Premain-Class: cc.tianbin.demo.agent.MyAgent +Can-Redefine-Classes: true diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" index 371d9071..20c5f8ab 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" @@ -1,2 +1,6 @@ # 体系学习班 - + +[课程目录](https://github.com/algorithmzuo/class-notes/blob/main/%E8%AF%BE%E5%A0%82%E5%86%85%E5%AE%B9%E6%B1%87%E6%80%BB/%E7%AE%97%E6%B3%95%E5%92%8C%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E4%BD%93%E7%B3%BB%E5%AD%A6%E4%B9%A0%E7%8F%AD) + +[代码](https://github.com/algorithmzuo/algorithmbasic2020) + diff --git "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" index 6cbb21ca..9bbacf2f 100644 --- "a/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" +++ "b/src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" @@ -1,8 +1,8 @@ ## 从暴力递归 到动态规划。练! ### [Code01_RobotWalk](./c0700_动态规划/Code01_RobotWalk.java) -假设 有排成一行的N个位置记为1~N,N一定大于或等于2 -开始时机器人在其中的M位置上(M一定是1~N中的一个) +假设 有排成一行的N个位置记为1-N,N一定大于或等于2 +开始时机器人在其中的M位置上(M一定是1-N中的一个) 如果机器人来到1位置,那么下一步只能往右来到2位置; 如果机器人来到N位置,那么下一步只能往左来到N-1位置; 如果机器人来到中间位置,那么下一步可以往左走或者往右走; @@ -107,9 +107,9 @@ arr是货币数组,其中的值都是正数 一共就1种方法,所以返回1 ### [Code14_MinCoinsNoLimit](./c0700_动态规划/Code14_MinCoinsNoLimit.java) -arr是面值数组,其中的值都是正数且没有重复。再给定一个正数aim。 -每个值都认为是一种面值,且认为张数是无限的。 -返回组成aim的最少货币数 +arr是面值数组,其中的值都是正数且没有重复。再给定一个正数aim。 +每个值都认为是一种面值,且认为张数是无限的。 +返回组成aim的最少货币数 ### [Code15_BobDie](./c0700_动态规划/Code15_BobDie.java) *WIP: 优化 -> 一维* diff --git "a/src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" "b/src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" index 604da471..b51bbb4f 100644 --- "a/src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" +++ "b/src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" @@ -1,2 +1,5 @@ # 刷题班 - + +[课程目录](https://github.com/algorithmzuo/class-notes/blob/main/%E8%AF%BE%E5%A0%82%E5%86%85%E5%AE%B9%E6%B1%87%E6%80%BB/%E5%A4%A7%E5%8E%82%E7%AE%97%E6%B3%95%E5%92%8C%E6%95%B0%E6%8D%AE%E7%BB%93%E6%9E%84%E5%88%B7%E9%A2%98%E7%8F%AD) + +[代码](https://github.com/algorithmzuo/coding-for-great-offer) diff --git a/src/main/test/tmp/interview/Main.java b/src/main/test/tmp/interview/Main.java new file mode 100644 index 00000000..50423ae5 --- /dev/null +++ b/src/main/test/tmp/interview/Main.java @@ -0,0 +1,14 @@ +package tmp.interview; + +import org.junit.Test; + +public class Main { + + @Test + public void test() { + + + } + + +} From 4fdb4ad21b5dfd9fcb91b26606e5771e87f6cc7c Mon Sep 17 00:00:00 2001 From: tianbin Date: Fri, 20 Jan 2023 14:36:00 +0800 Subject: [PATCH 28/36] =?UTF-8?q?=E5=A4=87=E4=BB=BD=E4=B8=80=E4=B8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\346\225\260\344\271\213\345\222\214.java" | 66 +- ...\346\225\260\347\233\270\345\212\240.java" | 93 +- ...\346\225\260\344\271\213\345\222\214.java" | 77 +- ...\346\257\215\347\273\204\345\220\210.java" | 59 ++ ...\344\270\262\347\233\270\344\271\230.java" | 107 ++- ...\345\205\250\346\216\222\345\210\227.java" | 5 +- ...345\205\250\346\216\222\345\210\2272.java" | 40 + ...\350\275\254\351\223\276\350\241\250.java" | 3 +- src/main/java/algorithm_practice/README.md | 9 +- .../java/\345\271\266\345\217\221/README.md" | 0 .../thread_demo/README.md" | 2 + src/main/java/common/util/AssertUtils.java | 55 ++ src/main/java/common/util/CompareUtils.java | 74 ++ .../java/common/util/ConstructLinkedNode.java | 15 + src/main/java/common/util/LogUtil.java | 33 + src/main/test/UnitTestDemo.java | 827 +++++++++++++++++- 16 files changed, 1391 insertions(+), 74 deletions(-) create mode 100644 "src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/README.md" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/thread_demo/README.md" create mode 100644 src/main/java/common/util/AssertUtils.java create mode 100644 src/main/java/common/util/LogUtil.java diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" index 7c684133..19512271 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" @@ -1,7 +1,10 @@ package algorithm_practice.LeetCode.code000; -import com.alibaba.fastjson.JSON; +import common.util.CompareUtils; +import org.junit.Assert; +import org.junit.Test; +import java.util.Arrays; import java.util.HashMap; import java.util.Map; @@ -24,11 +27,24 @@ 著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。 */ public class E001_两数之和 { - public static void main(String[] args) { + + @Test + public void test() { int[] nums = new int[]{3,2,4}; int target = 6; - System.out.println(JSON.toJSONString(twoSum_v1(nums, target))); - System.out.println(JSON.toJSONString(twoSum_v2(nums, target))); + Assert.assertTrue(CompareUtils.compareArrayIgnoreOrder(twoSum_v2(nums, target), twoSum(nums, target))); + + nums = new int[]{2,7,11,15}; + target = 9; + Assert.assertTrue(CompareUtils.compareArrayIgnoreOrder(twoSum_v2(nums, target), twoSum(nums, target))); + + nums = new int[]{3,3}; + target = 6; + + int[] arr1 = twoSum_v2(nums, target); + int[] arr2 = twoSum(nums, target); + Assert.assertTrue(CompareUtils.compareArrayIgnoreOrder(arr1, arr2)); + } /** @@ -41,8 +57,32 @@ public static void main(String[] args) { * * 时间复杂度:O(n^2) + O(n) */ + private int[] twoSum(int[] nums, int target) { + Map map = new HashMap<>(); + for(int i=0; i target) { + p2 --; + } else { + p1 ++; + } + } + + return new int[2]; + } /** * 使用HashMap,来找 和为target的下一个数字。 @@ -67,22 +107,4 @@ private static int[] twoSum_v2(int[] nums, int target) { return result; } - /** - * 简单又暴力 - * 时间复杂度:O(n^2) - * @param nums - * @param target - * @return - */ - private static int[] twoSum_v1(int[] nums, int target) { - int[] result = new int[]{}; - for (int i = 0; i < nums.length; i++) { - for (int j = 1; j < nums.length; j++) { - if (target == nums[i] + nums[j]) { - result = new int[]{i, j}; - } - } - } - return result; - } } diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" index ef8264b9..d4c73d98 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" @@ -1,6 +1,10 @@ package algorithm_practice.LeetCode.code000; +import com.google.common.collect.Lists; import common.datastruct.ListNode; +import common.util.AssertUtils; +import common.util.ConstructLinkedNode; +import org.junit.Test; /* 给出两个 非空 的链表用来表示两个非负的整数。其中,它们各自的位数是按照 逆序 的方式存储的,并且它们的每个结点只能存储 一位 数字。 @@ -20,31 +24,74 @@ */ public class M002_两数相加 { - public static void main(String[] args) { - //1,8 0 - //1, 9,9 - ListNode firstListNode = new ListNode(2); - firstListNode.next = new ListNode(7); - firstListNode.next.next = new ListNode(1); + @Test + public void test() { + // 2 7 1 + // 3 2 9 9 + // 5 9 0 0 1 + ListNode firstListNode = ConstructLinkedNode.constructSingleLinkedNode(Lists.newArrayList(2, 7, 1)); + ListNode secondListNode = ConstructLinkedNode.constructSingleLinkedNode(Lists.newArrayList(3, 2, 9, 9)); + ListNode expectSumListNode = ConstructLinkedNode.constructSingleLinkedNode(Lists.newArrayList(5, 9, 0, 0, 1)); - ListNode secondListNode = new ListNode(3); - secondListNode.next = new ListNode(2); - secondListNode.next.next = new ListNode(9); - secondListNode.next.next.next = new ListNode(9); + AssertUtils.compareListNode(expectSumListNode, addTwoNumbers(firstListNode, secondListNode)); + AssertUtils.compareListNode(expectSumListNode, addTwoNumbers_v2(firstListNode, secondListNode)); + AssertUtils.compareListNode(expectSumListNode, addTwoNumbers_v3(firstListNode, secondListNode)); - addTwoNumbers(firstListNode, secondListNode).printListNode(); - System.out.println(); - addTwoNumbers_v2(firstListNode, secondListNode).printListNode(); + + firstListNode = ConstructLinkedNode.constructSingleLinkedNode(Lists.newArrayList(3, 7)); + secondListNode = ConstructLinkedNode.constructSingleLinkedNode(Lists.newArrayList(9, 2)); + expectSumListNode = ConstructLinkedNode.constructSingleLinkedNode(Lists.newArrayList(2, 0, 1)); + AssertUtils.compareListNode(expectSumListNode, addTwoNumbers(firstListNode, secondListNode)); } + public ListNode addTwoNumbers(ListNode l1, ListNode l2) { + ListNode head = new ListNode(); + ListNode p = head; + int carry = 0; + + while (l1 != null && l2 != null) { + int val = (carry + l1.val + l2.val) % 10; + carry = (carry + l1.val + l2.val) / 10; + + p.next = new ListNode(val); + p = p.next; + + l1 = l1.next; + l2 = l2.next; + } + + while (l1 != null) { + p.next = new ListNode((carry + l1.val) % 10); + carry = (carry + l1.val) / 10; + + l1 = l1.next; + p = p.next; + } + + while (l2 != null) { + p.next = new ListNode((carry + l2.val) % 10); + carry = (carry + l2.val) / 10; + + l2 = l2.next; + p = p.next; + } + + if (carry != 0) { + p.next = new ListNode(carry); + } + + return head.next; + } + /** * 法2:递归 + * * @param l1 * @param l2 * @return */ - private static ListNode addTwoNumbers_v2(ListNode l1, ListNode l2) { + private ListNode addTwoNumbers_v2(ListNode l1, ListNode l2) { int carry = 0; ListNode result = new ListNode(0); result.next = sumListNode(l1, l2, carry); @@ -53,7 +100,7 @@ private static ListNode addTwoNumbers_v2(ListNode l1, ListNode l2) { static int TEN = 10; - private static ListNode sumListNode(ListNode l1, ListNode l2, int carry) { + private ListNode sumListNode(ListNode l1, ListNode l2, int carry) { if (l1 == null && l2 == null) { return carry > 0 ? new ListNode(carry) : null; } @@ -69,14 +116,15 @@ private static ListNode sumListNode(ListNode l1, ListNode l2, int carry) { /** * 法1:两大数相加 - * 保留一个头 - * 使用一个valNode,依次往后移动, - * 注意末尾二次进位 + * 保留一个头 + * 使用一个valNode,依次往后移动, + * 注意末尾二次进位 + * * @param l1 * @param l2 * @return */ - private static ListNode addTwoNumbers(ListNode l1, ListNode l2) { + private ListNode addTwoNumbers_v3(ListNode l1, ListNode l2) { int TEN = 10; ListNode result = null; int carry = 0; @@ -102,14 +150,15 @@ private static ListNode addTwoNumbers(ListNode l1, ListNode l2) { /** * 标准答案,1. 注意命名规范。 - * dummyHead、currentNode + * dummyHead、currentNode + *

+ * 2. dummyHead赋值的时机。 * - * 2. dummyHead赋值的时机。 * @param l1 * @param l2 * @return */ - private static ListNode daan(ListNode l1, ListNode l2) { + private ListNode daan(ListNode l1, ListNode l2) { int TEN = 10; int carry = 0; ListNode currentNode = new ListNode(0); diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" index 16797958..979caa28 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" @@ -1,13 +1,13 @@ package algorithm_practice.LeetCode.code000; -import com.alibaba.fastjson.JSON; -import com.sun.tools.doclint.Entity; +import common.util.AssertUtils; import junit.framework.TestCase; import org.junit.Test; import java.util.ArrayList; import java.util.Arrays; import java.util.List; +import java.util.stream.Collectors; /* 给定一个包含 n 个整数的数组 nums,判断 nums 中是否存在三个元素 a,b,c ,使得 a + b + c = 0 ?找出所有满足条件且不重复的三元组。 @@ -32,21 +32,68 @@ public class M015_三数之和 extends TestCase { @Test public void testCase() { int[] nums = new int[]{-1, 0, 1, 2, -1, -4}; - System.out.println(JSON.toJSONString(threeSum(nums))); + List> expect = Arrays.asList(Arrays.asList(-1,0,1), Arrays.asList(-1,-1,2)); + AssertUtils.compareListList(expect, threeSum(nums), nums); - int[] nums2 = new int[]{0, 0, 0, 0}; - System.out.println(JSON.toJSONString(threeSum(nums2))); + nums = new int[]{0, 0, 0, 0}; + expect = Arrays.asList(Arrays.asList(0,0,0)); + AssertUtils.compareListList(expect, threeSum(nums), nums); - int[] nums3 = new int[]{-2, 0, 1, 1, 2}; - System.out.println(JSON.toJSONString(threeSum(nums3))); + nums = new int[]{-2, 0, 1, 1, 2}; + expect = Arrays.asList(Arrays.asList(-2,0,2), Arrays.asList(-2,1,1)); + AssertUtils.compareListList(expect, threeSum(nums), nums); //[82597,-9243,62390,83030,-97960,-26521,-61011,83390,-38677,12333,75987,46091,83794,19355,-71037,-6242,-28801,324,1202,-90885,-2989,-95597,-34333,35528,5680,89093,-90606,50360,-29393,-27012,53313,65213,99818,-82405,-41661,-3333,-51952,72135,-1523,26377,74685,96992,92263,15929,5467,-99555,-43348,-41689,-60383,-3990,32165,65265,-72973,-58372,12741,-48568,-46596,72419,-1859,34153,62937,81310,-61823,-96770,-54944,8845,-91184,24208,-29078,31495,65258,14198,85395,70506,-40908,56740,-12228,-40072,32429,93001,68445,-73927,25731,-91859,-24150,10093,-60271,-81683,-18126,51055,48189,-6468,25057,81194,-58628,74042,66158,-14452,-49851,-43667,11092,39189,-17025,-79173,13606,83172,92647,-59741,19343,-26644,-57607,82908,-20655,1637,80060,98994,39331,-31274,-61523,91225,-72953,13211,-75116,-98421,-41571,-69074,99587,39345,42151,-2460,98236,15690,-52507,-95803,-48935,-46492,-45606,-79254,-99851,52533,73486,39948,-7240,71815,-585,-96252,90990,-93815,93340,-71848,58733,-14859,-83082,-75794,-82082,-24871,-15206,91207,-56469,-93618,67131,-8682,75719,87429,-98757,-7535,-24890,-94160,85003,33928,75538,97456,-66424,-60074,-8527,-28697,-22308,2246,-70134,-82319,-10184,87081,-34949,-28645,-47352,-83966,-60418,-15293,-53067,-25921,55172,75064,95859,48049,34311,-86931,-38586,33686,-36714,96922,76713,-22165,-80585,-34503,-44516,39217,-28457,47227,-94036,43457,24626,-87359,26898,-70819,30528,-32397,-69486,84912,-1187,-98986,-32958,4280,-79129,-65604,9344,58964,50584,71128,-55480,24986,15086,-62360,-42977,-49482,-77256,-36895,-74818,20,3063,-49426,28152,-97329,6086,86035,-88743,35241,44249,19927,-10660,89404,24179,-26621,-6511,57745,-28750,96340,-97160,-97822,-49979,52307,79462,94273,-24808,77104,9255,-83057,77655,21361,55956,-9096,48599,-40490,-55107,2689,29608,20497,66834,-34678,23553,-81400,-66630,-96321,-34499,-12957,-20564,25610,-4322,-58462,20801,53700,71527,24669,-54534,57879,-3221,33636,3900,97832,-27688,-98715,5992,24520,-55401,-57613,-69926,57377,-77610,20123,52174,860,60429,-91994,-62403,-6218,-90610,-37263,-15052,62069,-96465,44254,89892,-3406,19121,-41842,-87783,-64125,-56120,73904,-22797,-58118,-4866,5356,75318,46119,21276,-19246,-9241,-97425,57333,-15802,93149,25689,-5532,95716,39209,-87672,-29470,-16324,-15331,27632,-39454,56530,-16000,29853,46475,78242,-46602,83192,-73440,-15816,50964,-36601,89758,38375,-40007,-36675,-94030,67576,46811,-64919,45595,76530,40398,35845,41791,67697,-30439,-82944,63115,33447,-36046,-50122,-34789,43003,-78947,-38763,-89210,32756,-20389,-31358,-90526,-81607,88741,86643,98422,47389,-75189,13091,95993,-15501,94260,-25584,-1483,-67261,-70753,25160,89614,-90620,-48542,83889,-12388,-9642,-37043,-67663,28794,-8801,13621,12241,55379,84290,21692,-95906,-85617,-17341,-63767,80183,-4942,-51478,30997,-13658,8838,17452,-82869,-39897,68449,31964,98158,-49489,62283,-62209,-92792,-59342,55146,-38533,20496,62667,62593,36095,-12470,5453,-50451,74716,-17902,3302,-16760,-71642,-34819,96459,-72860,21638,47342,-69897,-40180,44466,76496,84659,13848,-91600,-90887,-63742,-2156,-84981,-99280,94326,-33854,92029,-50811,98711,-36459,-75555,79110,-88164,-97397,-84217,97457,64387,30513,-53190,-83215,252,2344,-27177,-92945,-89010,82662,-11670,86069,53417,42702,97082,3695,-14530,-46334,17910,77999,28009,-12374,15498,-46941,97088,-35030,95040,92095,-59469,-24761,46491,67357,-66658,37446,-65130,-50416,99197,30925,27308,54122,-44719,12582,-99525,-38446,-69050,-22352,94757,-56062,33684,-40199,-46399,96842,-50881,-22380,-65021,40582,53623,-76034,77018,-97074,-84838,-22953,-74205,79715,-33920,-35794,-91369,73421,-82492,63680,-14915,-33295,37145,76852,-69442,60125,-74166,74308,-1900,-30195,-16267,-60781,-27760,5852,38917,25742,-3765,49097,-63541,98612,-92865,-30248,9612,-8798,53262,95781,-42278,-36529,7252,-27394,-5021,59178,80934,-48480,-75131,-54439,-19145,-48140,98457,-6601,-51616,-89730,78028,32083,-48904,16822,-81153,-8832,48720,-80728,-45133,-86647,-4259,-40453,2590,28613,50523,-4105,-27790,-74579,-17223,63721,33489,-47921,97628,-97691,-14782,-65644,18008,-93651,-71266,80990,-76732,-47104,35368,28632,59818,-86269,-89753,34557,-92230,-5933,-3487,-73557,-13174,-43981,-43630,-55171,30254,-83710,-99583,-13500,71787,5017,-25117,-78586,86941,-3251,-23867,-36315,75973,86272,-45575,77462,-98836,-10859,70168,-32971,-38739,-12761,93410,14014,-30706,-77356,-85965,-62316,63918,-59914,-64088,1591,-10957,38004,15129,-83602,-51791,34381,-89382,-26056,8942,5465,71458,-73805,-87445,-19921,-80784,69150,-34168,28301,-68955,18041,6059,82342,9947,39795,44047,-57313,48569,81936,-2863,-80932,32976,-86454,-84207,33033,32867,9104,-16580,-25727,80157,-70169,53741,86522,84651,68480,84018,61932,7332,-61322,-69663,76370,41206,12326,-34689,17016,82975,-23386,39417,72793,44774,-96259,3213,79952,29265,-61492,-49337,14162,65886,3342,-41622,-62659,-90402,-24751,88511,54739,-21383,-40161,-96610,-24944,-602,-76842,-21856,69964,43994,-15121,-85530,12718,13170,-13547,69222,62417,-75305,-81446,-38786,-52075,-23110,97681,-82800,-53178,11474,35857,94197,-58148,-23689,32506,92154,-64536,-73930,-77138,97446,-83459,70963,22452,68472,-3728,-25059,-49405,95129,-6167,12808,99918,30113,-12641,-26665,86362,-33505,50661,26714,33701,89012,-91540,40517,-12716,-57185,-87230,29914,-59560,13200,-72723,58272,23913,-45586,-96593,-26265,-2141,31087,81399,92511,-34049,20577,2803,26003,8940,42117,40887,-82715,38269,40969,-50022,72088,21291,-67280,-16523,90535,18669,94342,-39568,-88080,-99486,-20716,23108,-28037,63342,36863,-29420,-44016,75135,73415,16059,-4899,86893,43136,-7041,33483,-67612,25327,40830,6184,61805,4247,81119,-22854,-26104,-63466,63093,-63685,60369,51023,51644,-16350,74438,-83514,99083,10079,-58451,-79621,48471,67131,-86940,99093,11855,-22272,-67683,-44371,9541,18123,37766,-70922,80385,-57513,-76021,-47890,36154,72935,84387,-92681,-88303,-7810,59902,-90,-64704,-28396,-66403,8860,13343,33882,85680,7228,28160,-14003,54369,-58893,92606,-63492,-10101,64714,58486,29948,-44679,-22763,10151,-56695,4031,-18242,-36232,86168,-14263,9883,47124,47271,92761,-24958,-73263,-79661,-69147,-18874,29546,-92588,-85771,26451,-86650,-43306,-59094,-47492,-34821,-91763,-47670,33537,22843,67417,-759,92159,63075,94065,-26988,55276,65903,30414,-67129,-99508,-83092,-91493,-50426,14349,-83216,-76090,32742,-5306,-93310,-60750,-60620,-45484,-21108,-58341,-28048,-52803,69735,78906,81649,32565,-86804,-83202,-65688,-1760,89707,93322,-72750,84134,71900,-37720,19450,-78018,22001,-23604,26276,-21498,65892,-72117,-89834,-23867,55817,-77963,42518,93123,-83916,63260,-2243,-97108,85442,-36775,17984,-58810,99664,-19082,93075,-69329,87061,79713,16296,70996,13483,-74582,49900,-27669,-40562,1209,-20572,34660,83193,75579,7344,64925,88361,60969,3114,44611,-27445,53049,-16085,-92851,-53306,13859,-33532,86622,-75666,-18159,-98256,51875,-42251,-27977,-18080,23772,38160,41779,9147,94175,99905,-85755,62535,-88412,-52038,-68171,93255,-44684,-11242,-104,31796,62346,-54931,-55790,-70032,46221,56541,-91947,90592,93503,4071,20646,4856,-63598,15396,-50708,32138,-85164,38528,-89959,53852,57915,-42421,-88916,-75072,67030,-29066,49542,-71591,61708,-53985,-43051,28483,46991,-83216,80991,-46254,-48716,39356,-8270,-47763,-34410,874,-1186,-7049,28846,11276,21960,-13304,-11433,-4913,55754,79616,70423,-27523,64803,49277,14906,-97401,-92390,91075,70736,21971,-3303,55333,-93996,76538,54603,-75899,98801,46887,35041,48302,-52318,55439,24574,14079,-24889,83440,14961,34312,-89260,-22293,-81271,-2586,-71059,-10640,-93095,-5453,-70041,66543,74012,-11662,-52477,-37597,-70919,92971,-17452,-67306,-80418,7225,-89296,24296,86547,37154,-10696,74436,-63959,58860,33590,-88925,-97814,-83664,85484,-8385,-50879,57729,-74728,-87852,-15524,-91120,22062,28134,80917,32026,49707,-54252,-44319,-35139,13777,44660,85274,25043,58781,-89035,-76274,6364,-63625,72855,43242,-35033,12820,-27460,77372,-47578,-61162,-70758,-1343,-4159,64935,56024,-2151,43770,19758,-30186,-86040,24666,-62332,-67542,73180,-25821,-27826,-45504,-36858,-12041,20017,-24066,-56625,-52097,-47239,-90694,8959,7712,-14258,-5860,55349,61808,-4423,-93703,64681,-98641,-25222,46999,-83831,-54714,19997,-68477,66073,51801,-66491,52061,-52866,79907,-39736,-68331,68937,91464,98892,910,93501,31295,-85873,27036,-57340,50412,21,-2445,29471,71317,82093,-94823,-54458,-97410,39560,-7628,66452,39701,54029,37906,46773,58296,60370,-61090,85501,-86874,71443,-72702,-72047,14848,34102,77975,-66294,-36576,31349,52493,-70833,-80287,94435,39745,-98291,84524,-18942,10236,93448,50846,94023,-6939,47999,14740,30165,81048,84935,-19177,-13594,32289,62628,-90612,-542,-66627,64255,71199,-83841,-82943,-73885,8623,-67214,-9474,-35249,62254,-14087,-90969,21515,-83303,94377,-91619,19956,-98810,96727,-91939,29119,-85473,-82153,-69008,44850,74299,-76459,-86464,8315,-49912,-28665,59052,-69708,76024,-92738,50098,18683,-91438,18096,-19335,35659,91826,15779,-73070,67873,-12458,-71440,-46721,54856,97212,-81875,35805,36952,68498,81627,-34231,81712,27100,-9741,-82612,18766,-36392,2759,41728,69743,26825,48355,-17790,17165,56558,3295,-24375,55669,-16109,24079,73414,48990,-11931,-78214,90745,19878,35673,-15317,-89086,94675,-92513,88410,-93248,-19475,-74041,-19165,32329,-26266,-46828,-18747,45328,8990,-78219,-25874,-74801,-44956,-54577,-29756,-99822,-35731,-18348,-68915,-83518,-53451,95471,-2954,-13706,-8763,-21642,-37210,16814,-60070,-42743,27697,-36333,-42362,11576,85742,-82536,68767,-56103,-63012,71396,-78464,-68101,-15917,-11113,-3596,77626,-60191,-30585,-73584,6214,-84303,18403,23618,-15619,-89755,-59515,-59103,-74308,-63725,-29364,-52376,-96130,70894,-12609,50845,-2314,42264,-70825,64481,55752,4460,-68603,-88701,4713,-50441,-51333,-77907,97412,-66616,-49430,60489,-85262,-97621,-18980,44727,-69321,-57730,66287,-92566,-64427,-14270,11515,-92612,-87645,61557,24197,-81923,-39831,-10301,-23640,-76219,-68025,92761,-76493,68554,-77734,-95620,-11753,-51700,98234,-68544,-61838,29467,46603,-18221,-35441,74537,40327,-58293,75755,-57301,-7532,-94163,18179,-14388,-22258,-46417,-48285,18242,-77551,82620,250,-20060,-79568,-77259,82052,-98897,-75464,48773,-79040,-11293,45941,-67876,-69204,-46477,-46107,792,60546,-34573,-12879,-94562,20356,-48004,-62429,96242,40594,2099,99494,25724,-39394,-2388,-18563,-56510,-83570,-29214,3015,74454,74197,76678,-46597,60630,-76093,37578,-82045,-24077,62082,-87787,-74936,58687,12200,-98952,70155,-77370,21710,-84625,-60556,-84128,925,65474,-15741,-94619,88377,89334,44749,22002,-45750,-93081,-14600,-83447,46691,85040,-66447,-80085,56308,44310,24979,-29694,57991,4675,-71273,-44508,13615,-54710,23552,-78253,-34637,50497,68706,81543,-88408,-21405,6001,-33834,-21570,-46692,-25344,20310,71258,-97680,11721,59977,59247,-48949,98955,-50276,-80844,-27935,-76102,55858,-33492,40680,66691,-33188,8284,64893,-7528,6019,-85523,8434,-64366,-56663,26862,30008,-7611,-12179,-70076,21426,-11261,-36864,-61937,-59677,929,-21052,3848,-20888,-16065,98995,-32293,-86121,-54564,77831,68602,74977,31658,40699,29755,98424,80358,-69337,26339,13213,-46016,-18331,64713,-46883,-58451,-70024,-92393,-4088,70628,-51185,71164,-75791,-1636,-29102,-16929,-87650,-84589,-24229,-42137,-15653,94825,13042,88499,-47100,-90358,-7180,29754,-65727,-42659,-85560,-9037,-52459,20997,-47425,17318,21122,20472,-23037,65216,-63625,-7877,-91907,24100,-72516,22903,-85247,-8938,73878,54953,87480,-31466,-99524,35369,-78376,89984,-15982,94045,-7269,23319,-80456,-37653,-76756,2909,81936,54958,-12393,60560,-84664,-82413,66941,-26573,-97532,64460,18593,-85789,-38820,-92575,-43663,-89435,83272,-50585,13616,-71541,-53156,727,-27644,16538,34049,57745,34348,35009,16634,-18791,23271,-63844,95817,21781,16590,59669,15966,-6864,48050,-36143,97427,-59390,96931,78939,-1958,50777,43338,-51149,39235,-27054,-43492,67457,-83616,37179,10390,85818,2391,73635,87579,-49127,-81264,-79023,-81590,53554,-74972,-83940,-13726,-39095,29174,78072,76104,47778,25797,-29515,-6493,-92793,22481,-36197,-65560,42342,15750,97556,99634,-56048,-35688,13501,63969,-74291,50911,39225,93702,-3490,-59461,-30105,-46761,-80113,92906,-68487,50742,36152,-90240,-83631,24597,-50566,-15477,18470,77038,40223,-80364,-98676,70957,-63647,99537,13041,31679,86631,37633,-16866,13686,-71565,21652,-46053,-80578,-61382,68487,-6417,4656,20811,67013,-30868,-11219,46,74944,14627,56965,42275,-52480,52162,-84883,-52579,-90331,92792,42184,-73422,-58440,65308,-25069,5475,-57996,59557,-17561,2826,-56939,14996,-94855,-53707,99159,43645,-67719,-1331,21412,41704,31612,32622,1919,-69333,-69828,22422,-78842,57896,-17363,27979,-76897,35008,46482,-75289,65799,20057,7170,41326,-76069,90840,-81253,-50749,3649,-42315,45238,-33924,62101,96906,58884,-7617,-28689,-66578,62458,50876,-57553,6739,41014,-64040,-34916,37940,13048,-97478,-11318,-89440,-31933,-40357,-59737,-76718,-14104,-31774,28001,4103,41702,-25120,-31654,63085,-3642,84870,-83896,-76422,-61520,12900,88678,85547,33132,-88627,52820,63915,-27472,78867,-51439,33005,-23447,-3271,-39308,39726,-74260,-31874,-36893,93656,910,-98362,60450,-88048,99308,13947,83996,-90415,-35117,70858,-55332,-31721,97528,82982,-86218,6822,25227,36946,97077,-4257,-41526,56795,89870,75860,-70802,21779,14184,-16511,-89156,-31422,71470,69600,-78498,74079,-19410,40311,28501,26397,-67574,-32518,68510,38615,19355,-6088,-97159,-29255,-92523,3023,-42536,-88681,64255,41206,44119,52208,39522,-52108,91276,-70514,83436,63289,-79741,9623,99559,12642,85950,83735,-21156,-67208,98088,-7341,-27763,-30048,-44099,-14866,-45504,-91704,19369,13700,10481,-49344,-85686,33994,19672,36028,60842,66564,-24919,33950,-93616,-47430,-35391,-28279,56806,74690,39284,-96683,-7642,-75232,37657,-14531,-86870,-9274,-26173,98640,88652,64257,46457,37814,-19370,9337,-22556,-41525,39105,-28719,51611,-93252,98044,-90996,21710,-47605,-64259,-32727,53611,-31918,-3555,33316,-66472,21274,-37731,-2919,15016,48779,-88868,1897,41728,46344,-89667,37848,68092,-44011,85354,-43776,38739,-31423,-66330,65167,-22016,59405,34328,-60042,87660,-67698,-59174,-1408,-46809,-43485,-88807,-60489,13974,22319,55836,-62995,-37375,-4185,32687,-36551,-75237,58280,26942,-73756,71756,78775,-40573,14367,-71622,-77338,24112,23414,-7679,-51721,87492,85066,-21612,57045,10673,-96836,52461,-62218,-9310,65862,-22748,89906,-96987,-98698,26956,-43428,46141,47456,28095,55952,67323,-36455,-60202,-43302,-82932,42020,77036,10142,60406,70331,63836,58850,-66752,52109,21395,-10238,-98647,-41962,27778,69060,98535,-28680,-52263,-56679,66103,-42426,27203,80021,10153,58678,36398,63112,34911,20515,62082,-15659,-40785,27054,43767,-20289,65838,-6954,-60228,-72226,52236,-35464,25209,-15462,-79617,-41668,-84083,62404,-69062,18913,46545,20757,13805,24717,-18461,-47009,-25779,68834,64824,34473,39576,31570,14861,-15114,-41233,95509,68232,67846,84902,-83060,17642,-18422,73688,77671,-26930,64484,-99637,73875,6428,21034,-73471,19664,-68031,15922,-27028,48137,54955,-82793,-41144,-10218,-24921,-28299,-2288,68518,-54452,15686,-41814,66165,-72207,-61986,80020,50544,-99500,16244,78998,40989,14525,-56061,-24692,-94790,21111,37296,-90794,72100,70550,-31757,17708,-74290,61910,78039,-78629,-25033,73172,-91953,10052,64502,99585,-1741,90324,-73723,68942,28149,30218,24422,16659,10710,-62594,94249,96588,46192,34251,73500,-65995,-81168,41412,-98724,-63710,-54696,-52407,19746,45869,27821,-94866,-76705,-13417,-61995,-71560,43450,67384,-8838,-80293,-28937,23330,-89694,-40586,46918,80429,-5475,78013,25309,-34162,37236,-77577,86744,26281,-29033,-91813,35347,13033,-13631,-24459,3325,-71078,-75359,81311,19700,47678,-74680,-84113,45192,35502,37675,19553,76522,-51098,-18211,89717,4508,-82946,27749,85995,89912,-53678,-64727,-14778,32075,-63412,-40524,86440,-2707,-36821,63850,-30883,67294,-99468,-23708,34932,34386,98899,29239,-23385,5897,54882,98660,49098,70275,17718,88533,52161,63340,50061,-89457,19491,-99156,24873,-17008,64610,-55543,50495,17056,-10400,-56678,-29073,-42960,-76418,98562,-88104,-96255,10159,-90724,54011,12052,45871,-90933,-69420,67039,37202,78051,-52197,-40278,-58425,65414,-23394,-1415,6912,-53447,7352,17307,-78147,63727,98905,55412,-57658,-32884,-44878,22755,39730,3638,35111,39777,74193,38736,-11829,-61188,-92757,55946,-71232,-63032,-83947,39147,-96684,-99233,25131,-32197,24406,-55428,-61941,25874,-69453,64483,-19644,-68441,12783,87338,-48676,66451,-447,-61590,50932,-11270,29035,65698,-63544,10029,80499,-9461,86368,91365,-81810,-71914,-52056,-13782,44240,-30093,-2437,24007,67581,-17365,-69164,-8420,-69289,-29370,48010,90439,13141,69243,50668,39328,61731,78266,-81313,17921,-38196,55261,9948,-24970,75712,-72106,28696,7461,31621,61047,51476,56512,11839,-96916,-82739,28924,-99927,58449,37280,69357,11219,-32119,-62050,-48745,-83486,-52376,42668,82659,68882,38773,46269,-96005,97630,25009,-2951,-67811,99801,81587,-79793,-18547,-83086,69512,33127,-92145,-88497,47703,59527,1909,88785,-88882,69188,-46131,-5589,-15086,36255,-53238,-33009,82664,53901,35939,-42946,-25571,33298,69291,53199,74746,-40127,-39050,91033,51717,-98048,87240,36172,65453,-94425,-63694,-30027,59004,88660,3649,-20267,-52565,-67321,34037,4320,91515,-56753,60115,27134,68617,-61395,-26503,-98929,-8849,-63318,10709,-16151,61905,-95785,5262,23670,-25277,90206,-19391,45735,37208,-31992,-92450,18516,-90452,-58870,-58602,93383,14333,17994,82411,-54126,-32576,35440,-60526,-78764,-25069,-9022,-394,92186,-38057,55328,-61569,67780,77169,19546,-92664,-94948,44484,-13439,83529,27518,-48333,72998,38342,-90553,-98578,-76906,81515,-16464,78439,92529,35225,-39968,-10130,-7845,-32245,-74955,-74996,67731,-13897,-82493,33407,93619,59560,-24404,-57553,19486,-45341,34098,-24978,-33612,79058,71847,76713,-95422,6421,-96075,-59130,-28976,-16922,-62203,69970,68331,21874,40551,89650,51908,58181,66480,-68177,34323,-3046,-49656,-59758,43564,-10960,-30796,15473,-20216,46085,-85355,41515,-30669,-87498,57711,56067,63199,-83805,62042,91213,-14606,4394,-562,74913,10406,96810,-61595,32564,31640,-9732,42058,98052,-7908,-72330,1558,-80301,34878,32900,3939,-8824,88316,20937,21566,-3218,-66080,-31620,86859,54289,90476,-42889,-15016,-18838,75456,30159,-67101,42328,-92703,85850,-5475,23470,-80806,68206,17764,88235,46421,-41578,74005,-81142,80545,20868,-1560,64017,83784,68863,-97516,-13016,-72223,79630,-55692,82255,88467,28007,-34686,-69049,-41677,88535,-8217,68060,-51280,28971,49088,49235,26905,-81117,-44888,40623,74337,-24662,97476,79542,-72082,-35093,98175,-61761,-68169,59697,-62542,-72965,59883,-64026,-37656,-92392,-12113,-73495,98258,68379,-21545,64607,-70957,-92254,-97460,-63436,-8853,-19357,-51965,-76582,12687,-49712,45413,-60043,33496,31539,-57347,41837,67280,-68813,52088,-13155,-86430,-15239,-45030,96041,18749,-23992,46048,35243,-79450,85425,-58524,88781,-39454,53073,-48864,-82289,39086,82540,-11555,25014,-5431,-39585,-89526,2705,31953,-81611,36985,-56022,68684,-27101,11422,64655,-26965,-63081,-13840,-91003,-78147,-8966,41488,1988,99021,-61575,-47060,65260,-23844,-21781,-91865,-19607,44808,2890,63692,-88663,-58272,15970,-65195,-45416,-48444,-78226,-65332,-24568,42833,-1806,-71595,80002,-52250,30952,48452,-90106,31015,-22073,62339,63318,78391,28699,77900,-4026,-76870,-45943,33665,9174,-84360,-22684,-16832,-67949,-38077,-38987,-32847,51443,-53580,-13505,9344,-92337,26585,70458,-52764,-67471,-68411,-1119,-2072,-93476,67981,40887,-89304,-12235,41488,1454,5355,-34855,-72080,24514,-58305,3340,34331,8731,77451,-64983,-57876,82874,62481,-32754,-39902,22451,-79095,-23904,78409,-7418,77916] - int[] nums4 = new int[]{82597, -9243, 62390, 83030, -97960, -26521, -61011, 83390, -38677, 12333, 75987, 46091, 83794, 19355, -71037, -6242, -28801, 324, 1202, -90885, -2989, -95597, -34333, 35528, 5680, 89093, -90606, 50360, -29393, -27012, 53313, 65213, 99818, -82405, -41661, -3333, -51952, 72135, -1523, 26377, 74685, 96992, 92263, 15929, 5467, -99555, -43348, -41689, -60383, -3990, 32165, 65265, -72973, -58372, 12741, -48568, -46596, 72419, -1859, 34153, 62937, 81310, -61823, -96770, -54944, 8845, -91184, 24208, -29078, 31495, 65258, 14198, 85395, 70506, -40908, 56740, -12228, -40072, 32429, 93001, 68445, -73927, 25731, -91859, -24150, 10093, -60271, -81683, -18126, 51055, 48189, -6468, 25057, 81194, -58628, 74042, 66158, -14452, -49851, -43667, 11092, 39189, -17025, -79173, 13606, 83172, 92647, -59741, 19343, -26644, -57607, 82908, -20655, 1637, 80060, 98994, 39331, -31274, -61523, 91225, -72953, 13211, -75116, -98421, -41571, -69074, 99587, 39345, 42151, -2460, 98236, 15690, -52507, -95803, -48935, -46492, -45606, -79254, -99851, 52533, 73486, 39948, -7240, 71815, -585, -96252, 90990, -93815, 93340, -71848, 58733, -14859, -83082, -75794, -82082, -24871, -15206, 91207, -56469, -93618, 67131, -8682, 75719, 87429, -98757, -7535, -24890, -94160, 85003, 33928, 75538, 97456, -66424, -60074, -8527, -28697, -22308, 2246, -70134, -82319, -10184, 87081, -34949, -28645, -47352, -83966, -60418, -15293, -53067, -25921, 55172, 75064, 95859, 48049, 34311, -86931, -38586, 33686, -36714, 96922, 76713, -22165, -80585, -34503, -44516, 39217, -28457, 47227, -94036, 43457, 24626, -87359, 26898, -70819, 30528, -32397, -69486, 84912, -1187, -98986, -32958, 4280, -79129, -65604, 9344, 58964, 50584, 71128, -55480, 24986, 15086, -62360, -42977, -49482, -77256, -36895, -74818, 20, 3063, -49426, 28152, -97329, 6086, 86035, -88743, 35241, 44249, 19927, -10660, 89404, 24179, -26621, -6511, 57745, -28750, 96340, -97160, -97822, -49979, 52307, 79462, 94273, -24808, 77104, 9255, -83057, 77655, 21361, 55956, -9096, 48599, -40490, -55107, 2689, 29608, 20497, 66834, -34678, 23553, -81400, -66630, -96321, -34499, -12957, -20564, 25610, -4322, -58462, 20801, 53700, 71527, 24669, -54534, 57879, -3221, 33636, 3900, 97832, -27688, -98715, 5992, 24520, -55401, -57613, -69926, 57377, -77610, 20123, 52174, 860, 60429, -91994, -62403, -6218, -90610, -37263, -15052, 62069, -96465, 44254, 89892, -3406, 19121, -41842, -87783, -64125, -56120, 73904, -22797, -58118, -4866, 5356, 75318, 46119, 21276, -19246, -9241, -97425, 57333, -15802, 93149, 25689, -5532, 95716, 39209, -87672, -29470, -16324, -15331, 27632, -39454, 56530, -16000, 29853, 46475, 78242, -46602, 83192, -73440, -15816, 50964, -36601, 89758, 38375, -40007, -36675, -94030, 67576, 46811, -64919, 45595, 76530, 40398, 35845, 41791, 67697, -30439, -82944, 63115, 33447, -36046, -50122, -34789, 43003, -78947, -38763, -89210, 32756, -20389, -31358, -90526, -81607, 88741, 86643, 98422, 47389, -75189, 13091, 95993, -15501, 94260, -25584, -1483, -67261, -70753, 25160, 89614, -90620, -48542, 83889, -12388, -9642, -37043, -67663, 28794, -8801, 13621, 12241, 55379, 84290, 21692, -95906, -85617, -17341, -63767, 80183, -4942, -51478, 30997, -13658, 8838, 17452, -82869, -39897, 68449, 31964, 98158, -49489, 62283, -62209, -92792, -59342, 55146, -38533, 20496, 62667, 62593, 36095, -12470, 5453, -50451, 74716, -17902, 3302, -16760, -71642, -34819, 96459, -72860, 21638, 47342, -69897, -40180, 44466, 76496, 84659, 13848, -91600, -90887, -63742, -2156, -84981, -99280, 94326, -33854, 92029, -50811, 98711, -36459, -75555, 79110, -88164, -97397, -84217, 97457, 64387, 30513, -53190, -83215, 252, 2344, -27177, -92945, -89010, 82662, -11670, 86069, 53417, 42702, 97082, 3695, -14530, -46334, 17910, 77999, 28009, -12374, 15498, -46941, 97088, -35030, 95040, 92095, -59469, -24761, 46491, 67357, -66658, 37446, -65130, -50416, 99197, 30925, 27308, 54122, -44719, 12582, -99525, -38446, -69050, -22352, 94757, -56062, 33684, -40199, -46399, 96842, -50881, -22380, -65021, 40582, 53623, -76034, 77018, -97074, -84838, -22953, -74205, 79715, -33920, -35794, -91369, 73421, -82492, 63680, -14915, -33295, 37145, 76852, -69442, 60125, -74166, 74308, -1900, -30195, -16267, -60781, -27760, 5852, 38917, 25742, -3765, 49097, -63541, 98612, -92865, -30248, 9612, -8798, 53262, 95781, -42278, -36529, 7252, -27394, -5021, 59178, 80934, -48480, -75131, -54439, -19145, -48140, 98457, -6601, -51616, -89730, 78028, 32083, -48904, 16822, -81153, -8832, 48720, -80728, -45133, -86647, -4259, -40453, 2590, 28613, 50523, -4105, -27790, -74579, -17223, 63721, 33489, -47921, 97628, -97691, -14782, -65644, 18008, -93651, -71266, 80990, -76732, -47104, 35368, 28632, 59818, -86269, -89753, 34557, -92230, -5933, -3487, -73557, -13174, -43981, -43630, -55171, 30254, -83710, -99583, -13500, 71787, 5017, -25117, -78586, 86941, -3251, -23867, -36315, 75973, 86272, -45575, 77462, -98836, -10859, 70168, -32971, -38739, -12761, 93410, 14014, -30706, -77356, -85965, -62316, 63918, -59914, -64088, 1591, -10957, 38004, 15129, -83602, -51791, 34381, -89382, -26056, 8942, 5465, 71458, -73805, -87445, -19921, -80784, 69150, -34168, 28301, -68955, 18041, 6059, 82342, 9947, 39795, 44047, -57313, 48569, 81936, -2863, -80932, 32976, -86454, -84207, 33033, 32867, 9104, -16580, -25727, 80157, -70169, 53741, 86522, 84651, 68480, 84018, 61932, 7332, -61322, -69663, 76370, 41206, 12326, -34689, 17016, 82975, -23386, 39417, 72793, 44774, -96259, 3213, 79952, 29265, -61492, -49337, 14162, 65886, 3342, -41622, -62659, -90402, -24751, 88511, 54739, -21383, -40161, -96610, -24944, -602, -76842, -21856, 69964, 43994, -15121, -85530, 12718, 13170, -13547, 69222, 62417, -75305, -81446, -38786, -52075, -23110, 97681, -82800, -53178, 11474, 35857, 94197, -58148, -23689, 32506, 92154, -64536, -73930, -77138, 97446, -83459, 70963, 22452, 68472, -3728, -25059, -49405, 95129, -6167, 12808, 99918, 30113, -12641, -26665, 86362, -33505, 50661, 26714, 33701, 89012, -91540, 40517, -12716, -57185, -87230, 29914, -59560, 13200, -72723, 58272, 23913, -45586, -96593, -26265, -2141, 31087, 81399, 92511, -34049, 20577, 2803, 26003, 8940, 42117, 40887, -82715, 38269, 40969, -50022, 72088, 21291, -67280, -16523, 90535, 18669, 94342, -39568, -88080, -99486, -20716, 23108, -28037, 63342, 36863, -29420, -44016, 75135, 73415, 16059, -4899, 86893, 43136, -7041, 33483, -67612, 25327, 40830, 6184, 61805, 4247, 81119, -22854, -26104, -63466, 63093, -63685, 60369, 51023, 51644, -16350, 74438, -83514, 99083, 10079, -58451, -79621, 48471, 67131, -86940, 99093, 11855, -22272, -67683, -44371, 9541, 18123, 37766, -70922, 80385, -57513, -76021, -47890, 36154, 72935, 84387, -92681, -88303, -7810, 59902, -90, -64704, -28396, -66403, 8860, 13343, 33882, 85680, 7228, 28160, -14003, 54369, -58893, 92606, -63492, -10101, 64714, 58486, 29948, -44679, -22763, 10151, -56695, 4031, -18242, -36232, 86168, -14263, 9883, 47124, 47271, 92761, -24958, -73263, -79661, -69147, -18874, 29546, -92588, -85771, 26451, -86650, -43306, -59094, -47492, -34821, -91763, -47670, 33537, 22843, 67417, -759, 92159, 63075, 94065, -26988, 55276, 65903, 30414, -67129, -99508, -83092, -91493, -50426, 14349, -83216, -76090, 32742, -5306, -93310, -60750, -60620, -45484, -21108, -58341, -28048, -52803, 69735, 78906, 81649, 32565, -86804, -83202, -65688, -1760, 89707, 93322, -72750, 84134, 71900, -37720, 19450, -78018, 22001, -23604, 26276, -21498, 65892, -72117, -89834, -23867, 55817, -77963, 42518, 93123, -83916, 63260, -2243, -97108, 85442, -36775, 17984, -58810, 99664, -19082, 93075, -69329, 87061, 79713, 16296, 70996, 13483, -74582, 49900, -27669, -40562, 1209, -20572, 34660, 83193, 75579, 7344, 64925, 88361, 60969, 3114, 44611, -27445, 53049, -16085, -92851, -53306, 13859, -33532, 86622, -75666, -18159, -98256, 51875, -42251, -27977, -18080, 23772, 38160, 41779, 9147, 94175, 99905, -85755, 62535, -88412, -52038, -68171, 93255, -44684, -11242, -104, 31796, 62346, -54931, -55790, -70032, 46221, 56541, -91947, 90592, 93503, 4071, 20646, 4856, -63598, 15396, -50708, 32138, -85164, 38528, -89959, 53852, 57915, -42421, -88916, -75072, 67030, -29066, 49542, -71591, 61708, -53985, -43051, 28483, 46991, -83216, 80991, -46254, -48716, 39356, -8270, -47763, -34410, 874, -1186, -7049, 28846, 11276, 21960, -13304, -11433, -4913, 55754, 79616, 70423, -27523, 64803, 49277, 14906, -97401, -92390, 91075, 70736, 21971, -3303, 55333, -93996, 76538, 54603, -75899, 98801, 46887, 35041, 48302, -52318, 55439, 24574, 14079, -24889, 83440, 14961, 34312, -89260, -22293, -81271, -2586, -71059, -10640, -93095, -5453, -70041, 66543, 74012, -11662, -52477, -37597, -70919, 92971, -17452, -67306, -80418, 7225, -89296, 24296, 86547, 37154, -10696, 74436, -63959, 58860, 33590, -88925, -97814, -83664, 85484, -8385, -50879, 57729, -74728, -87852, -15524, -91120, 22062, 28134, 80917, 32026, 49707, -54252, -44319, -35139, 13777, 44660, 85274, 25043, 58781, -89035, -76274, 6364, -63625, 72855, 43242, -35033, 12820, -27460, 77372, -47578, -61162, -70758, -1343, -4159, 64935, 56024, -2151, 43770, 19758, -30186, -86040, 24666, -62332, -67542, 73180, -25821, -27826, -45504, -36858, -12041, 20017, -24066, -56625, -52097, -47239, -90694, 8959, 7712, -14258, -5860, 55349, 61808, -4423, -93703, 64681, -98641, -25222, 46999, -83831, -54714, 19997, -68477, 66073, 51801, -66491, 52061, -52866, 79907, -39736, -68331, 68937, 91464, 98892, 910, 93501, 31295, -85873, 27036, -57340, 50412, 21, -2445, 29471, 71317, 82093, -94823, -54458, -97410, 39560, -7628, 66452, 39701, 54029, 37906, 46773, 58296, 60370, -61090, 85501, -86874, 71443, -72702, -72047, 14848, 34102, 77975, -66294, -36576, 31349, 52493, -70833, -80287, 94435, 39745, -98291, 84524, -18942, 10236, 93448, 50846, 94023, -6939, 47999, 14740, 30165, 81048, 84935, -19177, -13594, 32289, 62628, -90612, -542, -66627, 64255, 71199, -83841, -82943, -73885, 8623, -67214, -9474, -35249, 62254, -14087, -90969, 21515, -83303, 94377, -91619, 19956, -98810, 96727, -91939, 29119, -85473, -82153, -69008, 44850, 74299, -76459, -86464, 8315, -49912, -28665, 59052, -69708, 76024, -92738, 50098, 18683, -91438, 18096, -19335, 35659, 91826, 15779, -73070, 67873, -12458, -71440, -46721, 54856, 97212, -81875, 35805, 36952, 68498, 81627, -34231, 81712, 27100, -9741, -82612, 18766, -36392, 2759, 41728, 69743, 26825, 48355, -17790, 17165, 56558, 3295, -24375, 55669, -16109, 24079, 73414, 48990, -11931, -78214, 90745, 19878, 35673, -15317, -89086, 94675, -92513, 88410, -93248, -19475, -74041, -19165, 32329, -26266, -46828, -18747, 45328, 8990, -78219, -25874, -74801, -44956, -54577, -29756, -99822, -35731, -18348, -68915, -83518, -53451, 95471, -2954, -13706, -8763, -21642, -37210, 16814, -60070, -42743, 27697, -36333, -42362, 11576, 85742, -82536, 68767, -56103, -63012, 71396, -78464, -68101, -15917, -11113, -3596, 77626, -60191, -30585, -73584, 6214, -84303, 18403, 23618, -15619, -89755, -59515, -59103, -74308, -63725, -29364, -52376, -96130, 70894, -12609, 50845, -2314, 42264, -70825, 64481, 55752, 4460, -68603, -88701, 4713, -50441, -51333, -77907, 97412, -66616, -49430, 60489, -85262, -97621, -18980, 44727, -69321, -57730, 66287, -92566, -64427, -14270, 11515, -92612, -87645, 61557, 24197, -81923, -39831, -10301, -23640, -76219, -68025, 92761, -76493, 68554, -77734, -95620, -11753, -51700, 98234, -68544, -61838, 29467, 46603, -18221, -35441, 74537, 40327, -58293, 75755, -57301, -7532, -94163, 18179, -14388, -22258, -46417, -48285, 18242, -77551, 82620, 250, -20060, -79568, -77259, 82052, -98897, -75464, 48773, -79040, -11293, 45941, -67876, -69204, -46477, -46107, 792, 60546, -34573, -12879, -94562, 20356, -48004, -62429, 96242, 40594, 2099, 99494, 25724, -39394, -2388, -18563, -56510, -83570, -29214, 3015, 74454, 74197, 76678, -46597, 60630, -76093, 37578, -82045, -24077, 62082, -87787, -74936, 58687, 12200, -98952, 70155, -77370, 21710, -84625, -60556, -84128, 925, 65474, -15741, -94619, 88377, 89334, 44749, 22002, -45750, -93081, -14600, -83447, 46691, 85040, -66447, -80085, 56308, 44310, 24979, -29694, 57991, 4675, -71273, -44508, 13615, -54710, 23552, -78253, -34637, 50497, 68706, 81543, -88408, -21405, 6001, -33834, -21570, -46692, -25344, 20310, 71258, -97680, 11721, 59977, 59247, -48949, 98955, -50276, -80844, -27935, -76102, 55858, -33492, 40680, 66691, -33188, 8284, 64893, -7528, 6019, -85523, 8434, -64366, -56663, 26862, 30008, -7611, -12179, -70076, 21426, -11261, -36864, -61937, -59677, 929, -21052, 3848, -20888, -16065, 98995, -32293, -86121, -54564, 77831, 68602, 74977, 31658, 40699, 29755, 98424, 80358, -69337, 26339, 13213, -46016, -18331, 64713, -46883, -58451, -70024, -92393, -4088, 70628, -51185, 71164, -75791, -1636, -29102, -16929, -87650, -84589, -24229, -42137, -15653, 94825, 13042, 88499, -47100, -90358, -7180, 29754, -65727, -42659, -85560, -9037, -52459, 20997, -47425, 17318, 21122, 20472, -23037, 65216, -63625, -7877, -91907, 24100, -72516, 22903, -85247, -8938, 73878, 54953, 87480, -31466, -99524, 35369, -78376, 89984, -15982, 94045, -7269, 23319, -80456, -37653, -76756, 2909, 81936, 54958, -12393, 60560, -84664, -82413, 66941, -26573, -97532, 64460, 18593, -85789, -38820, -92575, -43663, -89435, 83272, -50585, 13616, -71541, -53156, 727, -27644, 16538, 34049, 57745, 34348, 35009, 16634, -18791, 23271, -63844, 95817, 21781, 16590, 59669, 15966, -6864, 48050, -36143, 97427, -59390, 96931, 78939, -1958, 50777, 43338, -51149, 39235, -27054, -43492, 67457, -83616, 37179, 10390, 85818, 2391, 73635, 87579, -49127, -81264, -79023, -81590, 53554, -74972, -83940, -13726, -39095, 29174, 78072, 76104, 47778, 25797, -29515, -6493, -92793, 22481, -36197, -65560, 42342, 15750, 97556, 99634, -56048, -35688, 13501, 63969, -74291, 50911, 39225, 93702, -3490, -59461, -30105, -46761, -80113, 92906, -68487, 50742, 36152, -90240, -83631, 24597, -50566, -15477, 18470, 77038, 40223, -80364, -98676, 70957, -63647, 99537, 13041, 31679, 86631, 37633, -16866, 13686, -71565, 21652, -46053, -80578, -61382, 68487, -6417, 4656, 20811, 67013, -30868, -11219, 46, 74944, 14627, 56965, 42275, -52480, 52162, -84883, -52579, -90331, 92792, 42184, -73422, -58440, 65308, -25069, 5475, -57996, 59557, -17561, 2826, -56939, 14996, -94855, -53707, 99159, 43645, -67719, -1331, 21412, 41704, 31612, 32622, 1919, -69333, -69828, 22422, -78842, 57896, -17363, 27979, -76897, 35008, 46482, -75289, 65799, 20057, 7170, 41326, -76069, 90840, -81253, -50749, 3649, -42315, 45238, -33924, 62101, 96906, 58884, -7617, -28689, -66578, 62458, 50876, -57553, 6739, 41014, -64040, -34916, 37940, 13048, -97478, -11318, -89440, -31933, -40357, -59737, -76718, -14104, -31774, 28001, 4103, 41702, -25120, -31654, 63085, -3642, 84870, -83896, -76422, -61520, 12900, 88678, 85547, 33132, -88627, 52820, 63915, -27472, 78867, -51439, 33005, -23447, -3271, -39308, 39726, -74260, -31874, -36893, 93656, 910, -98362, 60450, -88048, 99308, 13947, 83996, -90415, -35117, 70858, -55332, -31721, 97528, 82982, -86218, 6822, 25227, 36946, 97077, -4257, -41526, 56795, 89870, 75860, -70802, 21779, 14184, -16511, -89156, -31422, 71470, 69600, -78498, 74079, -19410, 40311, 28501, 26397, -67574, -32518, 68510, 38615, 19355, -6088, -97159, -29255, -92523, 3023, -42536, -88681, 64255, 41206, 44119, 52208, 39522, -52108, 91276, -70514, 83436, 63289, -79741, 9623, 99559, 12642, 85950, 83735, -21156, -67208, 98088, -7341, -27763, -30048, -44099, -14866, -45504, -91704, 19369, 13700, 10481, -49344, -85686, 33994, 19672, 36028, 60842, 66564, -24919, 33950, -93616, -47430, -35391, -28279, 56806, 74690, 39284, -96683, -7642, -75232, 37657, -14531, -86870, -9274, -26173, 98640, 88652, 64257, 46457, 37814, -19370, 9337, -22556, -41525, 39105, -28719, 51611, -93252, 98044, -90996, 21710, -47605, -64259, -32727, 53611, -31918, -3555, 33316, -66472, 21274, -37731, -2919, 15016, 48779, -88868, 1897, 41728, 46344, -89667, 37848, 68092, -44011, 85354, -43776, 38739, -31423, -66330, 65167, -22016, 59405, 34328, -60042, 87660, -67698, -59174, -1408, -46809, -43485, -88807, -60489, 13974, 22319, 55836, -62995, -37375, -4185, 32687, -36551, -75237, 58280, 26942, -73756, 71756, 78775, -40573, 14367, -71622, -77338, 24112, 23414, -7679, -51721, 87492, 85066, -21612, 57045, 10673, -96836, 52461, -62218, -9310, 65862, -22748, 89906, -96987, -98698, 26956, -43428, 46141, 47456, 28095, 55952, 67323, -36455, -60202, -43302, -82932, 42020, 77036, 10142, 60406, 70331, 63836, 58850, -66752, 52109, 21395, -10238, -98647, -41962, 27778, 69060, 98535, -28680, -52263, -56679, 66103, -42426, 27203, 80021, 10153, 58678, 36398, 63112, 34911, 20515, 62082, -15659, -40785, 27054, 43767, -20289, 65838, -6954, -60228, -72226, 52236, -35464, 25209, -15462, -79617, -41668, -84083, 62404, -69062, 18913, 46545, 20757, 13805, 24717, -18461, -47009, -25779, 68834, 64824, 34473, 39576, 31570, 14861, -15114, -41233, 95509, 68232, 67846, 84902, -83060, 17642, -18422, 73688, 77671, -26930, 64484, -99637, 73875, 6428, 21034, -73471, 19664, -68031, 15922, -27028, 48137, 54955, -82793, -41144, -10218, -24921, -28299, -2288, 68518, -54452, 15686, -41814, 66165, -72207, -61986, 80020, 50544, -99500, 16244, 78998, 40989, 14525, -56061, -24692, -94790, 21111, 37296, -90794, 72100, 70550, -31757, 17708, -74290, 61910, 78039, -78629, -25033, 73172, -91953, 10052, 64502, 99585, -1741, 90324, -73723, 68942, 28149, 30218, 24422, 16659, 10710, -62594, 94249, 96588, 46192, 34251, 73500, -65995, -81168, 41412, -98724, -63710, -54696, -52407, 19746, 45869, 27821, -94866, -76705, -13417, -61995, -71560, 43450, 67384, -8838, -80293, -28937, 23330, -89694, -40586, 46918, 80429, -5475, 78013, 25309, -34162, 37236, -77577, 86744, 26281, -29033, -91813, 35347, 13033, -13631, -24459, 3325, -71078, -75359, 81311, 19700, 47678, -74680, -84113, 45192, 35502, 37675, 19553, 76522, -51098, -18211, 89717, 4508, -82946, 27749, 85995, 89912, -53678, -64727, -14778, 32075, -63412, -40524, 86440, -2707, -36821, 63850, -30883, 67294, -99468, -23708, 34932, 34386, 98899, 29239, -23385, 5897, 54882, 98660, 49098, 70275, 17718, 88533, 52161, 63340, 50061, -89457, 19491, -99156, 24873, -17008, 64610, -55543, 50495, 17056, -10400, -56678, -29073, -42960, -76418, 98562, -88104, -96255, 10159, -90724, 54011, 12052, 45871, -90933, -69420, 67039, 37202, 78051, -52197, -40278, -58425, 65414, -23394, -1415, 6912, -53447, 7352, 17307, -78147, 63727, 98905, 55412, -57658, -32884, -44878, 22755, 39730, 3638, 35111, 39777, 74193, 38736, -11829, -61188, -92757, 55946, -71232, -63032, -83947, 39147, -96684, -99233, 25131, -32197, 24406, -55428, -61941, 25874, -69453, 64483, -19644, -68441, 12783, 87338, -48676, 66451, -447, -61590, 50932, -11270, 29035, 65698, -63544, 10029, 80499, -9461, 86368, 91365, -81810, -71914, -52056, -13782, 44240, -30093, -2437, 24007, 67581, -17365, -69164, -8420, -69289, -29370, 48010, 90439, 13141, 69243, 50668, 39328, 61731, 78266, -81313, 17921, -38196, 55261, 9948, -24970, 75712, -72106, 28696, 7461, 31621, 61047, 51476, 56512, 11839, -96916, -82739, 28924, -99927, 58449, 37280, 69357, 11219, -32119, -62050, -48745, -83486, -52376, 42668, 82659, 68882, 38773, 46269, -96005, 97630, 25009, -2951, -67811, 99801, 81587, -79793, -18547, -83086, 69512, 33127, -92145, -88497, 47703, 59527, 1909, 88785, -88882, 69188, -46131, -5589, -15086, 36255, -53238, -33009, 82664, 53901, 35939, -42946, -25571, 33298, 69291, 53199, 74746, -40127, -39050, 91033, 51717, -98048, 87240, 36172, 65453, -94425, -63694, -30027, 59004, 88660, 3649, -20267, -52565, -67321, 34037, 4320, 91515, -56753, 60115, 27134, 68617, -61395, -26503, -98929, -8849, -63318, 10709, -16151, 61905, -95785, 5262, 23670, -25277, 90206, -19391, 45735, 37208, -31992, -92450, 18516, -90452, -58870, -58602, 93383, 14333, 17994, 82411, -54126, -32576, 35440, -60526, -78764, -25069, -9022, -394, 92186, -38057, 55328, -61569, 67780, 77169, 19546, -92664, -94948, 44484, -13439, 83529, 27518, -48333, 72998, 38342, -90553, -98578, -76906, 81515, -16464, 78439, 92529, 35225, -39968, -10130, -7845, -32245, -74955, -74996, 67731, -13897, -82493, 33407, 93619, 59560, -24404, -57553, 19486, -45341, 34098, -24978, -33612, 79058, 71847, 76713, -95422, 6421, -96075, -59130, -28976, -16922, -62203, 69970, 68331, 21874, 40551, 89650, 51908, 58181, 66480, -68177, 34323, -3046, -49656, -59758, 43564, -10960, -30796, 15473, -20216, 46085, -85355, 41515, -30669, -87498, 57711, 56067, 63199, -83805, 62042, 91213, -14606, 4394, -562, 74913, 10406, 96810, -61595, 32564, 31640, -9732, 42058, 98052, -7908, -72330, 1558, -80301, 34878, 32900, 3939, -8824, 88316, 20937, 21566, -3218, -66080, -31620, 86859, 54289, 90476, -42889, -15016, -18838, 75456, 30159, -67101, 42328, -92703, 85850, -5475, 23470, -80806, 68206, 17764, 88235, 46421, -41578, 74005, -81142, 80545, 20868, -1560, 64017, 83784, 68863, -97516, -13016, -72223, 79630, -55692, 82255, 88467, 28007, -34686, -69049, -41677, 88535, -8217, 68060, -51280, 28971, 49088, 49235, 26905, -81117, -44888, 40623, 74337, -24662, 97476, 79542, -72082, -35093, 98175, -61761, -68169, 59697, -62542, -72965, 59883, -64026, -37656, -92392, -12113, -73495, 98258, 68379, -21545, 64607, -70957, -92254, -97460, -63436, -8853, -19357, -51965, -76582, 12687, -49712, 45413, -60043, 33496, 31539, -57347, 41837, 67280, -68813, 52088, -13155, -86430, -15239, -45030, 96041, 18749, -23992, 46048, 35243, -79450, 85425, -58524, 88781, -39454, 53073, -48864, -82289, 39086, 82540, -11555, 25014, -5431, -39585, -89526, 2705, 31953, -81611, 36985, -56022, 68684, -27101, 11422, 64655, -26965, -63081, -13840, -91003, -78147, -8966, 41488, 1988, 99021, -61575, -47060, 65260, -23844, -21781, -91865, -19607, 44808, 2890, 63692, -88663, -58272, 15970, -65195, -45416, -48444, -78226, -65332, -24568, 42833, -1806, -71595, 80002, -52250, 30952, 48452, -90106, 31015, -22073, 62339, 63318, 78391, 28699, 77900, -4026, -76870, -45943, 33665, 9174, -84360, -22684, -16832, -67949, -38077, -38987, -32847, 51443, -53580, -13505, 9344, -92337, 26585, 70458, -52764, -67471, -68411, -1119, -2072, -93476, 67981, 40887, -89304, -12235, 41488, 1454, 5355, -34855, -72080, 24514, -58305, 3340, 34331, 8731, 77451, -64983, -57876, 82874, 62481, -32754, -39902, 22451, -79095, -23904, 78409, -7418, 77916}; - System.out.println(JSON.toJSONString(threeSum(nums4))); + nums = new int[]{82597, -9243, 62390, 83030, -97960, -26521, -61011, 83390, -38677, 12333, 75987, 46091, 83794, 19355, -71037, -6242, -28801, 324, 1202, -90885, -2989, -95597, -34333, 35528, 5680, 89093, -90606, 50360, -29393, -27012, 53313, 65213, 99818, -82405, -41661, -3333, -51952, 72135, -1523, 26377, 74685, 96992, 92263, 15929, 5467, -99555, -43348, -41689, -60383, -3990, 32165, 65265, -72973, -58372, 12741, -48568, -46596, 72419, -1859, 34153, 62937, 81310, -61823, -96770, -54944, 8845, -91184, 24208, -29078, 31495, 65258, 14198, 85395, 70506, -40908, 56740, -12228, -40072, 32429, 93001, 68445, -73927, 25731, -91859, -24150, 10093, -60271, -81683, -18126, 51055, 48189, -6468, 25057, 81194, -58628, 74042, 66158, -14452, -49851, -43667, 11092, 39189, -17025, -79173, 13606, 83172, 92647, -59741, 19343, -26644, -57607, 82908, -20655, 1637, 80060, 98994, 39331, -31274, -61523, 91225, -72953, 13211, -75116, -98421, -41571, -69074, 99587, 39345, 42151, -2460, 98236, 15690, -52507, -95803, -48935, -46492, -45606, -79254, -99851, 52533, 73486, 39948, -7240, 71815, -585, -96252, 90990, -93815, 93340, -71848, 58733, -14859, -83082, -75794, -82082, -24871, -15206, 91207, -56469, -93618, 67131, -8682, 75719, 87429, -98757, -7535, -24890, -94160, 85003, 33928, 75538, 97456, -66424, -60074, -8527, -28697, -22308, 2246, -70134, -82319, -10184, 87081, -34949, -28645, -47352, -83966, -60418, -15293, -53067, -25921, 55172, 75064, 95859, 48049, 34311, -86931, -38586, 33686, -36714, 96922, 76713, -22165, -80585, -34503, -44516, 39217, -28457, 47227, -94036, 43457, 24626, -87359, 26898, -70819, 30528, -32397, -69486, 84912, -1187, -98986, -32958, 4280, -79129, -65604, 9344, 58964, 50584, 71128, -55480, 24986, 15086, -62360, -42977, -49482, -77256, -36895, -74818, 20, 3063, -49426, 28152, -97329, 6086, 86035, -88743, 35241, 44249, 19927, -10660, 89404, 24179, -26621, -6511, 57745, -28750, 96340, -97160, -97822, -49979, 52307, 79462, 94273, -24808, 77104, 9255, -83057, 77655, 21361, 55956, -9096, 48599, -40490, -55107, 2689, 29608, 20497, 66834, -34678, 23553, -81400, -66630, -96321, -34499, -12957, -20564, 25610, -4322, -58462, 20801, 53700, 71527, 24669, -54534, 57879, -3221, 33636, 3900, 97832, -27688, -98715, 5992, 24520, -55401, -57613, -69926, 57377, -77610, 20123, 52174, 860, 60429, -91994, -62403, -6218, -90610, -37263, -15052, 62069, -96465, 44254, 89892, -3406, 19121, -41842, -87783, -64125, -56120, 73904, -22797, -58118, -4866, 5356, 75318, 46119, 21276, -19246, -9241, -97425, 57333, -15802, 93149, 25689, -5532, 95716, 39209, -87672, -29470, -16324, -15331, 27632, -39454, 56530, -16000, 29853, 46475, 78242, -46602, 83192, -73440, -15816, 50964, -36601, 89758, 38375, -40007, -36675, -94030, 67576, 46811, -64919, 45595, 76530, 40398, 35845, 41791, 67697, -30439, -82944, 63115, 33447, -36046, -50122, -34789, 43003, -78947, -38763, -89210, 32756, -20389, -31358, -90526, -81607, 88741, 86643, 98422, 47389, -75189, 13091, 95993, -15501, 94260, -25584, -1483, -67261, -70753, 25160, 89614, -90620, -48542, 83889, -12388, -9642, -37043, -67663, 28794, -8801, 13621, 12241, 55379, 84290, 21692, -95906, -85617, -17341, -63767, 80183, -4942, -51478, 30997, -13658, 8838, 17452, -82869, -39897, 68449, 31964, 98158, -49489, 62283, -62209, -92792, -59342, 55146, -38533, 20496, 62667, 62593, 36095, -12470, 5453, -50451, 74716, -17902, 3302, -16760, -71642, -34819, 96459, -72860, 21638, 47342, -69897, -40180, 44466, 76496, 84659, 13848, -91600, -90887, -63742, -2156, -84981, -99280, 94326, -33854, 92029, -50811, 98711, -36459, -75555, 79110, -88164, -97397, -84217, 97457, 64387, 30513, -53190, -83215, 252, 2344, -27177, -92945, -89010, 82662, -11670, 86069, 53417, 42702, 97082, 3695, -14530, -46334, 17910, 77999, 28009, -12374, 15498, -46941, 97088, -35030, 95040, 92095, -59469, -24761, 46491, 67357, -66658, 37446, -65130, -50416, 99197, 30925, 27308, 54122, -44719, 12582, -99525, -38446, -69050, -22352, 94757, -56062, 33684, -40199, -46399, 96842, -50881, -22380, -65021, 40582, 53623, -76034, 77018, -97074, -84838, -22953, -74205, 79715, -33920, -35794, -91369, 73421, -82492, 63680, -14915, -33295, 37145, 76852, -69442, 60125, -74166, 74308, -1900, -30195, -16267, -60781, -27760, 5852, 38917, 25742, -3765, 49097, -63541, 98612, -92865, -30248, 9612, -8798, 53262, 95781, -42278, -36529, 7252, -27394, -5021, 59178, 80934, -48480, -75131, -54439, -19145, -48140, 98457, -6601, -51616, -89730, 78028, 32083, -48904, 16822, -81153, -8832, 48720, -80728, -45133, -86647, -4259, -40453, 2590, 28613, 50523, -4105, -27790, -74579, -17223, 63721, 33489, -47921, 97628, -97691, -14782, -65644, 18008, -93651, -71266, 80990, -76732, -47104, 35368, 28632, 59818, -86269, -89753, 34557, -92230, -5933, -3487, -73557, -13174, -43981, -43630, -55171, 30254, -83710, -99583, -13500, 71787, 5017, -25117, -78586, 86941, -3251, -23867, -36315, 75973, 86272, -45575, 77462, -98836, -10859, 70168, -32971, -38739, -12761, 93410, 14014, -30706, -77356, -85965, -62316, 63918, -59914, -64088, 1591, -10957, 38004, 15129, -83602, -51791, 34381, -89382, -26056, 8942, 5465, 71458, -73805, -87445, -19921, -80784, 69150, -34168, 28301, -68955, 18041, 6059, 82342, 9947, 39795, 44047, -57313, 48569, 81936, -2863, -80932, 32976, -86454, -84207, 33033, 32867, 9104, -16580, -25727, 80157, -70169, 53741, 86522, 84651, 68480, 84018, 61932, 7332, -61322, -69663, 76370, 41206, 12326, -34689, 17016, 82975, -23386, 39417, 72793, 44774, -96259, 3213, 79952, 29265, -61492, -49337, 14162, 65886, 3342, -41622, -62659, -90402, -24751, 88511, 54739, -21383, -40161, -96610, -24944, -602, -76842, -21856, 69964, 43994, -15121, -85530, 12718, 13170, -13547, 69222, 62417, -75305, -81446, -38786, -52075, -23110, 97681, -82800, -53178, 11474, 35857, 94197, -58148, -23689, 32506, 92154, -64536, -73930, -77138, 97446, -83459, 70963, 22452, 68472, -3728, -25059, -49405, 95129, -6167, 12808, 99918, 30113, -12641, -26665, 86362, -33505, 50661, 26714, 33701, 89012, -91540, 40517, -12716, -57185, -87230, 29914, -59560, 13200, -72723, 58272, 23913, -45586, -96593, -26265, -2141, 31087, 81399, 92511, -34049, 20577, 2803, 26003, 8940, 42117, 40887, -82715, 38269, 40969, -50022, 72088, 21291, -67280, -16523, 90535, 18669, 94342, -39568, -88080, -99486, -20716, 23108, -28037, 63342, 36863, -29420, -44016, 75135, 73415, 16059, -4899, 86893, 43136, -7041, 33483, -67612, 25327, 40830, 6184, 61805, 4247, 81119, -22854, -26104, -63466, 63093, -63685, 60369, 51023, 51644, -16350, 74438, -83514, 99083, 10079, -58451, -79621, 48471, 67131, -86940, 99093, 11855, -22272, -67683, -44371, 9541, 18123, 37766, -70922, 80385, -57513, -76021, -47890, 36154, 72935, 84387, -92681, -88303, -7810, 59902, -90, -64704, -28396, -66403, 8860, 13343, 33882, 85680, 7228, 28160, -14003, 54369, -58893, 92606, -63492, -10101, 64714, 58486, 29948, -44679, -22763, 10151, -56695, 4031, -18242, -36232, 86168, -14263, 9883, 47124, 47271, 92761, -24958, -73263, -79661, -69147, -18874, 29546, -92588, -85771, 26451, -86650, -43306, -59094, -47492, -34821, -91763, -47670, 33537, 22843, 67417, -759, 92159, 63075, 94065, -26988, 55276, 65903, 30414, -67129, -99508, -83092, -91493, -50426, 14349, -83216, -76090, 32742, -5306, -93310, -60750, -60620, -45484, -21108, -58341, -28048, -52803, 69735, 78906, 81649, 32565, -86804, -83202, -65688, -1760, 89707, 93322, -72750, 84134, 71900, -37720, 19450, -78018, 22001, -23604, 26276, -21498, 65892, -72117, -89834, -23867, 55817, -77963, 42518, 93123, -83916, 63260, -2243, -97108, 85442, -36775, 17984, -58810, 99664, -19082, 93075, -69329, 87061, 79713, 16296, 70996, 13483, -74582, 49900, -27669, -40562, 1209, -20572, 34660, 83193, 75579, 7344, 64925, 88361, 60969, 3114, 44611, -27445, 53049, -16085, -92851, -53306, 13859, -33532, 86622, -75666, -18159, -98256, 51875, -42251, -27977, -18080, 23772, 38160, 41779, 9147, 94175, 99905, -85755, 62535, -88412, -52038, -68171, 93255, -44684, -11242, -104, 31796, 62346, -54931, -55790, -70032, 46221, 56541, -91947, 90592, 93503, 4071, 20646, 4856, -63598, 15396, -50708, 32138, -85164, 38528, -89959, 53852, 57915, -42421, -88916, -75072, 67030, -29066, 49542, -71591, 61708, -53985, -43051, 28483, 46991, -83216, 80991, -46254, -48716, 39356, -8270, -47763, -34410, 874, -1186, -7049, 28846, 11276, 21960, -13304, -11433, -4913, 55754, 79616, 70423, -27523, 64803, 49277, 14906, -97401, -92390, 91075, 70736, 21971, -3303, 55333, -93996, 76538, 54603, -75899, 98801, 46887, 35041, 48302, -52318, 55439, 24574, 14079, -24889, 83440, 14961, 34312, -89260, -22293, -81271, -2586, -71059, -10640, -93095, -5453, -70041, 66543, 74012, -11662, -52477, -37597, -70919, 92971, -17452, -67306, -80418, 7225, -89296, 24296, 86547, 37154, -10696, 74436, -63959, 58860, 33590, -88925, -97814, -83664, 85484, -8385, -50879, 57729, -74728, -87852, -15524, -91120, 22062, 28134, 80917, 32026, 49707, -54252, -44319, -35139, 13777, 44660, 85274, 25043, 58781, -89035, -76274, 6364, -63625, 72855, 43242, -35033, 12820, -27460, 77372, -47578, -61162, -70758, -1343, -4159, 64935, 56024, -2151, 43770, 19758, -30186, -86040, 24666, -62332, -67542, 73180, -25821, -27826, -45504, -36858, -12041, 20017, -24066, -56625, -52097, -47239, -90694, 8959, 7712, -14258, -5860, 55349, 61808, -4423, -93703, 64681, -98641, -25222, 46999, -83831, -54714, 19997, -68477, 66073, 51801, -66491, 52061, -52866, 79907, -39736, -68331, 68937, 91464, 98892, 910, 93501, 31295, -85873, 27036, -57340, 50412, 21, -2445, 29471, 71317, 82093, -94823, -54458, -97410, 39560, -7628, 66452, 39701, 54029, 37906, 46773, 58296, 60370, -61090, 85501, -86874, 71443, -72702, -72047, 14848, 34102, 77975, -66294, -36576, 31349, 52493, -70833, -80287, 94435, 39745, -98291, 84524, -18942, 10236, 93448, 50846, 94023, -6939, 47999, 14740, 30165, 81048, 84935, -19177, -13594, 32289, 62628, -90612, -542, -66627, 64255, 71199, -83841, -82943, -73885, 8623, -67214, -9474, -35249, 62254, -14087, -90969, 21515, -83303, 94377, -91619, 19956, -98810, 96727, -91939, 29119, -85473, -82153, -69008, 44850, 74299, -76459, -86464, 8315, -49912, -28665, 59052, -69708, 76024, -92738, 50098, 18683, -91438, 18096, -19335, 35659, 91826, 15779, -73070, 67873, -12458, -71440, -46721, 54856, 97212, -81875, 35805, 36952, 68498, 81627, -34231, 81712, 27100, -9741, -82612, 18766, -36392, 2759, 41728, 69743, 26825, 48355, -17790, 17165, 56558, 3295, -24375, 55669, -16109, 24079, 73414, 48990, -11931, -78214, 90745, 19878, 35673, -15317, -89086, 94675, -92513, 88410, -93248, -19475, -74041, -19165, 32329, -26266, -46828, -18747, 45328, 8990, -78219, -25874, -74801, -44956, -54577, -29756, -99822, -35731, -18348, -68915, -83518, -53451, 95471, -2954, -13706, -8763, -21642, -37210, 16814, -60070, -42743, 27697, -36333, -42362, 11576, 85742, -82536, 68767, -56103, -63012, 71396, -78464, -68101, -15917, -11113, -3596, 77626, -60191, -30585, -73584, 6214, -84303, 18403, 23618, -15619, -89755, -59515, -59103, -74308, -63725, -29364, -52376, -96130, 70894, -12609, 50845, -2314, 42264, -70825, 64481, 55752, 4460, -68603, -88701, 4713, -50441, -51333, -77907, 97412, -66616, -49430, 60489, -85262, -97621, -18980, 44727, -69321, -57730, 66287, -92566, -64427, -14270, 11515, -92612, -87645, 61557, 24197, -81923, -39831, -10301, -23640, -76219, -68025, 92761, -76493, 68554, -77734, -95620, -11753, -51700, 98234, -68544, -61838, 29467, 46603, -18221, -35441, 74537, 40327, -58293, 75755, -57301, -7532, -94163, 18179, -14388, -22258, -46417, -48285, 18242, -77551, 82620, 250, -20060, -79568, -77259, 82052, -98897, -75464, 48773, -79040, -11293, 45941, -67876, -69204, -46477, -46107, 792, 60546, -34573, -12879, -94562, 20356, -48004, -62429, 96242, 40594, 2099, 99494, 25724, -39394, -2388, -18563, -56510, -83570, -29214, 3015, 74454, 74197, 76678, -46597, 60630, -76093, 37578, -82045, -24077, 62082, -87787, -74936, 58687, 12200, -98952, 70155, -77370, 21710, -84625, -60556, -84128, 925, 65474, -15741, -94619, 88377, 89334, 44749, 22002, -45750, -93081, -14600, -83447, 46691, 85040, -66447, -80085, 56308, 44310, 24979, -29694, 57991, 4675, -71273, -44508, 13615, -54710, 23552, -78253, -34637, 50497, 68706, 81543, -88408, -21405, 6001, -33834, -21570, -46692, -25344, 20310, 71258, -97680, 11721, 59977, 59247, -48949, 98955, -50276, -80844, -27935, -76102, 55858, -33492, 40680, 66691, -33188, 8284, 64893, -7528, 6019, -85523, 8434, -64366, -56663, 26862, 30008, -7611, -12179, -70076, 21426, -11261, -36864, -61937, -59677, 929, -21052, 3848, -20888, -16065, 98995, -32293, -86121, -54564, 77831, 68602, 74977, 31658, 40699, 29755, 98424, 80358, -69337, 26339, 13213, -46016, -18331, 64713, -46883, -58451, -70024, -92393, -4088, 70628, -51185, 71164, -75791, -1636, -29102, -16929, -87650, -84589, -24229, -42137, -15653, 94825, 13042, 88499, -47100, -90358, -7180, 29754, -65727, -42659, -85560, -9037, -52459, 20997, -47425, 17318, 21122, 20472, -23037, 65216, -63625, -7877, -91907, 24100, -72516, 22903, -85247, -8938, 73878, 54953, 87480, -31466, -99524, 35369, -78376, 89984, -15982, 94045, -7269, 23319, -80456, -37653, -76756, 2909, 81936, 54958, -12393, 60560, -84664, -82413, 66941, -26573, -97532, 64460, 18593, -85789, -38820, -92575, -43663, -89435, 83272, -50585, 13616, -71541, -53156, 727, -27644, 16538, 34049, 57745, 34348, 35009, 16634, -18791, 23271, -63844, 95817, 21781, 16590, 59669, 15966, -6864, 48050, -36143, 97427, -59390, 96931, 78939, -1958, 50777, 43338, -51149, 39235, -27054, -43492, 67457, -83616, 37179, 10390, 85818, 2391, 73635, 87579, -49127, -81264, -79023, -81590, 53554, -74972, -83940, -13726, -39095, 29174, 78072, 76104, 47778, 25797, -29515, -6493, -92793, 22481, -36197, -65560, 42342, 15750, 97556, 99634, -56048, -35688, 13501, 63969, -74291, 50911, 39225, 93702, -3490, -59461, -30105, -46761, -80113, 92906, -68487, 50742, 36152, -90240, -83631, 24597, -50566, -15477, 18470, 77038, 40223, -80364, -98676, 70957, -63647, 99537, 13041, 31679, 86631, 37633, -16866, 13686, -71565, 21652, -46053, -80578, -61382, 68487, -6417, 4656, 20811, 67013, -30868, -11219, 46, 74944, 14627, 56965, 42275, -52480, 52162, -84883, -52579, -90331, 92792, 42184, -73422, -58440, 65308, -25069, 5475, -57996, 59557, -17561, 2826, -56939, 14996, -94855, -53707, 99159, 43645, -67719, -1331, 21412, 41704, 31612, 32622, 1919, -69333, -69828, 22422, -78842, 57896, -17363, 27979, -76897, 35008, 46482, -75289, 65799, 20057, 7170, 41326, -76069, 90840, -81253, -50749, 3649, -42315, 45238, -33924, 62101, 96906, 58884, -7617, -28689, -66578, 62458, 50876, -57553, 6739, 41014, -64040, -34916, 37940, 13048, -97478, -11318, -89440, -31933, -40357, -59737, -76718, -14104, -31774, 28001, 4103, 41702, -25120, -31654, 63085, -3642, 84870, -83896, -76422, -61520, 12900, 88678, 85547, 33132, -88627, 52820, 63915, -27472, 78867, -51439, 33005, -23447, -3271, -39308, 39726, -74260, -31874, -36893, 93656, 910, -98362, 60450, -88048, 99308, 13947, 83996, -90415, -35117, 70858, -55332, -31721, 97528, 82982, -86218, 6822, 25227, 36946, 97077, -4257, -41526, 56795, 89870, 75860, -70802, 21779, 14184, -16511, -89156, -31422, 71470, 69600, -78498, 74079, -19410, 40311, 28501, 26397, -67574, -32518, 68510, 38615, 19355, -6088, -97159, -29255, -92523, 3023, -42536, -88681, 64255, 41206, 44119, 52208, 39522, -52108, 91276, -70514, 83436, 63289, -79741, 9623, 99559, 12642, 85950, 83735, -21156, -67208, 98088, -7341, -27763, -30048, -44099, -14866, -45504, -91704, 19369, 13700, 10481, -49344, -85686, 33994, 19672, 36028, 60842, 66564, -24919, 33950, -93616, -47430, -35391, -28279, 56806, 74690, 39284, -96683, -7642, -75232, 37657, -14531, -86870, -9274, -26173, 98640, 88652, 64257, 46457, 37814, -19370, 9337, -22556, -41525, 39105, -28719, 51611, -93252, 98044, -90996, 21710, -47605, -64259, -32727, 53611, -31918, -3555, 33316, -66472, 21274, -37731, -2919, 15016, 48779, -88868, 1897, 41728, 46344, -89667, 37848, 68092, -44011, 85354, -43776, 38739, -31423, -66330, 65167, -22016, 59405, 34328, -60042, 87660, -67698, -59174, -1408, -46809, -43485, -88807, -60489, 13974, 22319, 55836, -62995, -37375, -4185, 32687, -36551, -75237, 58280, 26942, -73756, 71756, 78775, -40573, 14367, -71622, -77338, 24112, 23414, -7679, -51721, 87492, 85066, -21612, 57045, 10673, -96836, 52461, -62218, -9310, 65862, -22748, 89906, -96987, -98698, 26956, -43428, 46141, 47456, 28095, 55952, 67323, -36455, -60202, -43302, -82932, 42020, 77036, 10142, 60406, 70331, 63836, 58850, -66752, 52109, 21395, -10238, -98647, -41962, 27778, 69060, 98535, -28680, -52263, -56679, 66103, -42426, 27203, 80021, 10153, 58678, 36398, 63112, 34911, 20515, 62082, -15659, -40785, 27054, 43767, -20289, 65838, -6954, -60228, -72226, 52236, -35464, 25209, -15462, -79617, -41668, -84083, 62404, -69062, 18913, 46545, 20757, 13805, 24717, -18461, -47009, -25779, 68834, 64824, 34473, 39576, 31570, 14861, -15114, -41233, 95509, 68232, 67846, 84902, -83060, 17642, -18422, 73688, 77671, -26930, 64484, -99637, 73875, 6428, 21034, -73471, 19664, -68031, 15922, -27028, 48137, 54955, -82793, -41144, -10218, -24921, -28299, -2288, 68518, -54452, 15686, -41814, 66165, -72207, -61986, 80020, 50544, -99500, 16244, 78998, 40989, 14525, -56061, -24692, -94790, 21111, 37296, -90794, 72100, 70550, -31757, 17708, -74290, 61910, 78039, -78629, -25033, 73172, -91953, 10052, 64502, 99585, -1741, 90324, -73723, 68942, 28149, 30218, 24422, 16659, 10710, -62594, 94249, 96588, 46192, 34251, 73500, -65995, -81168, 41412, -98724, -63710, -54696, -52407, 19746, 45869, 27821, -94866, -76705, -13417, -61995, -71560, 43450, 67384, -8838, -80293, -28937, 23330, -89694, -40586, 46918, 80429, -5475, 78013, 25309, -34162, 37236, -77577, 86744, 26281, -29033, -91813, 35347, 13033, -13631, -24459, 3325, -71078, -75359, 81311, 19700, 47678, -74680, -84113, 45192, 35502, 37675, 19553, 76522, -51098, -18211, 89717, 4508, -82946, 27749, 85995, 89912, -53678, -64727, -14778, 32075, -63412, -40524, 86440, -2707, -36821, 63850, -30883, 67294, -99468, -23708, 34932, 34386, 98899, 29239, -23385, 5897, 54882, 98660, 49098, 70275, 17718, 88533, 52161, 63340, 50061, -89457, 19491, -99156, 24873, -17008, 64610, -55543, 50495, 17056, -10400, -56678, -29073, -42960, -76418, 98562, -88104, -96255, 10159, -90724, 54011, 12052, 45871, -90933, -69420, 67039, 37202, 78051, -52197, -40278, -58425, 65414, -23394, -1415, 6912, -53447, 7352, 17307, -78147, 63727, 98905, 55412, -57658, -32884, -44878, 22755, 39730, 3638, 35111, 39777, 74193, 38736, -11829, -61188, -92757, 55946, -71232, -63032, -83947, 39147, -96684, -99233, 25131, -32197, 24406, -55428, -61941, 25874, -69453, 64483, -19644, -68441, 12783, 87338, -48676, 66451, -447, -61590, 50932, -11270, 29035, 65698, -63544, 10029, 80499, -9461, 86368, 91365, -81810, -71914, -52056, -13782, 44240, -30093, -2437, 24007, 67581, -17365, -69164, -8420, -69289, -29370, 48010, 90439, 13141, 69243, 50668, 39328, 61731, 78266, -81313, 17921, -38196, 55261, 9948, -24970, 75712, -72106, 28696, 7461, 31621, 61047, 51476, 56512, 11839, -96916, -82739, 28924, -99927, 58449, 37280, 69357, 11219, -32119, -62050, -48745, -83486, -52376, 42668, 82659, 68882, 38773, 46269, -96005, 97630, 25009, -2951, -67811, 99801, 81587, -79793, -18547, -83086, 69512, 33127, -92145, -88497, 47703, 59527, 1909, 88785, -88882, 69188, -46131, -5589, -15086, 36255, -53238, -33009, 82664, 53901, 35939, -42946, -25571, 33298, 69291, 53199, 74746, -40127, -39050, 91033, 51717, -98048, 87240, 36172, 65453, -94425, -63694, -30027, 59004, 88660, 3649, -20267, -52565, -67321, 34037, 4320, 91515, -56753, 60115, 27134, 68617, -61395, -26503, -98929, -8849, -63318, 10709, -16151, 61905, -95785, 5262, 23670, -25277, 90206, -19391, 45735, 37208, -31992, -92450, 18516, -90452, -58870, -58602, 93383, 14333, 17994, 82411, -54126, -32576, 35440, -60526, -78764, -25069, -9022, -394, 92186, -38057, 55328, -61569, 67780, 77169, 19546, -92664, -94948, 44484, -13439, 83529, 27518, -48333, 72998, 38342, -90553, -98578, -76906, 81515, -16464, 78439, 92529, 35225, -39968, -10130, -7845, -32245, -74955, -74996, 67731, -13897, -82493, 33407, 93619, 59560, -24404, -57553, 19486, -45341, 34098, -24978, -33612, 79058, 71847, 76713, -95422, 6421, -96075, -59130, -28976, -16922, -62203, 69970, 68331, 21874, 40551, 89650, 51908, 58181, 66480, -68177, 34323, -3046, -49656, -59758, 43564, -10960, -30796, 15473, -20216, 46085, -85355, 41515, -30669, -87498, 57711, 56067, 63199, -83805, 62042, 91213, -14606, 4394, -562, 74913, 10406, 96810, -61595, 32564, 31640, -9732, 42058, 98052, -7908, -72330, 1558, -80301, 34878, 32900, 3939, -8824, 88316, 20937, 21566, -3218, -66080, -31620, 86859, 54289, 90476, -42889, -15016, -18838, 75456, 30159, -67101, 42328, -92703, 85850, -5475, 23470, -80806, 68206, 17764, 88235, 46421, -41578, 74005, -81142, 80545, 20868, -1560, 64017, 83784, 68863, -97516, -13016, -72223, 79630, -55692, 82255, 88467, 28007, -34686, -69049, -41677, 88535, -8217, 68060, -51280, 28971, 49088, 49235, 26905, -81117, -44888, 40623, 74337, -24662, 97476, 79542, -72082, -35093, 98175, -61761, -68169, 59697, -62542, -72965, 59883, -64026, -37656, -92392, -12113, -73495, 98258, 68379, -21545, 64607, -70957, -92254, -97460, -63436, -8853, -19357, -51965, -76582, 12687, -49712, 45413, -60043, 33496, 31539, -57347, 41837, 67280, -68813, 52088, -13155, -86430, -15239, -45030, 96041, 18749, -23992, 46048, 35243, -79450, 85425, -58524, 88781, -39454, 53073, -48864, -82289, 39086, 82540, -11555, 25014, -5431, -39585, -89526, 2705, 31953, -81611, 36985, -56022, 68684, -27101, 11422, 64655, -26965, -63081, -13840, -91003, -78147, -8966, 41488, 1988, 99021, -61575, -47060, 65260, -23844, -21781, -91865, -19607, 44808, 2890, 63692, -88663, -58272, 15970, -65195, -45416, -48444, -78226, -65332, -24568, 42833, -1806, -71595, 80002, -52250, 30952, 48452, -90106, 31015, -22073, 62339, 63318, 78391, 28699, 77900, -4026, -76870, -45943, 33665, 9174, -84360, -22684, -16832, -67949, -38077, -38987, -32847, 51443, -53580, -13505, 9344, -92337, 26585, 70458, -52764, -67471, -68411, -1119, -2072, -93476, 67981, 40887, -89304, -12235, 41488, 1454, 5355, -34855, -72080, 24514, -58305, 3340, 34331, 8731, 77451, -64983, -57876, 82874, 62481, -32754, -39902, 22451, -79095, -23904, 78409, -7418, 77916}; +// Assert.compareListList(expect, threeSum(nums), nums); - int[] nums5 = new int[]{0, -4, -1, -4, -2, -3, 2}; - System.out.println(JSON.toJSONString(threeSum(nums5))); + nums = new int[]{0, -4, -1, -4, -2, -3, 2}; + expect = Arrays.asList(Arrays.asList(-2,0,2)); + AssertUtils.compareListList(expect, threeSum(nums), nums); + nums = new int[]{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1}; + expect = Arrays.asList(Arrays.asList(-1,0,1), Arrays.asList(0,0,0)); + AssertUtils.compareListList(expect, threeSum(nums), nums); + + nums = new int[]{-2, 0, 1, 1, 2}; + expect = Arrays.asList(Arrays.asList(-2,0,2), Arrays.asList(-2,1,1)); + AssertUtils.compareListList(expect, threeSum(nums), nums); + + } + + public List> threeSum(int[] nums) { + List> result = new ArrayList(); + if (nums == null || nums.length < 3) { + return result; + } + + Arrays.sort(nums); + + for (int i = 0; i < nums.length; i++) { + int p1 = i + 1; + int p2 = nums.length - 1; + + while (p1 < p2) { + int sum = nums[i] + nums[p1] + nums[p2]; + + if (sum == 0) { + List ans = Arrays.asList(nums[i], nums[p1], nums[p2]).stream().sorted().collect(Collectors.toList()); + if (!result.contains(ans)) { + result.add(ans); + } + + do { + p1++; + } while (p1 < p2 && nums[p1] == nums[p2]); + } else if (sum > 0) { + p2--; + } else { + p1++; + } + } + } + + return result; } /* @@ -58,13 +105,9 @@ public void testCase() { sum < 0, p1++ 优化:加几个可以提前跳出for循环的条件 - if nums[i] > 0: break; // sum不可能==0了 - if i > 0 && nums[i] == nums[i-1]: continue; // 去重 - 当找到sum==0时, - while (p1> threeSum(int[] nums) { + public List> threeSum3(int[] nums) { List> result = new ArrayList<>(); if (nums == null || nums.length < 3) { return result; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" new file mode 100644 index 00000000..a85c6362 --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" @@ -0,0 +1,59 @@ +package algorithm_practice.LeetCode.code000; + +import com.google.common.collect.Lists; +import common.util.AssertUtils; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.List; + +/** + * Created by nibnait on 2023/01/19 + */ +public class M017_电话号码的字母组合 { + + @Test + public void test() { + String digits = "23"; + List result = letterCombinations(digits); + List expect = Lists.newArrayList("ad", "ae", "af", "bd", "be", "bf", "cd", "ce", "cf"); + AssertUtils.compareStringList(expect, result); + } + + + private static final char[][] phone = new char[][]{ + {'.'}, + {'.'}, + {'a', 'b', 'c'}, + {'d', 'e', 'f'}, + {'g', 'h', 'i'}, + {'j', 'k', 'l'}, + {'m', 'n', 'o'}, + {'p', 'q', 'r', 's'}, + {'t', 'u', 'v'}, + {'w', 'x', 'y', 'z'} + }; + + public List letterCombinations(String digits) { + if (digits == null || digits.length() == 0) { + return new ArrayList(); + } + + char[] str = digits.toCharArray(); + List ans = new ArrayList<>(); + process(ans, str, 0, ""); + return ans; + } + + private void process(List ans, char[] str, int index, String path) { + if (index == str.length) { + ans.add(path); + return; + } + + for (char c : phone[str[index] - '0']) { + process(ans, str, index + 1, path + c); + } + } + +} diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" index 198d81aa..46efdeda 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" @@ -1,5 +1,6 @@ package algorithm_practice.LeetCode.code000; +import common.util.AssertUtils; import junit.framework.TestCase; import org.junit.Test; @@ -31,19 +32,109 @@ public class M043_字符串相乘 extends TestCase { public void testCase() { String num1 = "123"; String num2 = "456"; - System.out.println(multiply(num1, num2)); + AssertUtils.compareString("56088", multiply(num1, num2)); + AssertUtils.compareString("56088", multiply2(num1, num2)); + + num1 = "123"; + num2 = "0"; + AssertUtils.compareString("0", multiply(num1, num2)); + AssertUtils.compareString("0", multiply2(num1, num2)); + + num1 = "123456789"; + num2 = "987654321"; + AssertUtils.compareString("121932631112635269", multiply(num1, num2)); + AssertUtils.compareString("121932631112635269", multiply2(num1, num2)); + + num1 = "999"; + num2 = "999"; + AssertUtils.compareString("998001", multiply(num1, num2)); + AssertUtils.compareString("998001", multiply2(num1, num2)); + } + + public String multiply2(String num1, String num2) { + if ("0".equals(num1) || "0".equals(num2)) { + return "0"; + } + + // 长的数字 + char[] n1 = num1.length() >= num2.length() ? num1.toCharArray() : num2.toCharArray(); + // 短的数字 + char[] n2 = num1.length() >= num2.length() ? num2.toCharArray() : num1.toCharArray(); - String num3 = "123"; - String num4 = "0"; - System.out.println(multiply(num3, num4)); + int p2 = n2.length - 1; + int carry = 0; + String product = ""; + while (p2 >= 0) { + StringBuilder curSum = new StringBuilder(); + int p1 = n1.length - 1; + while (p1 >= 0) { + int val = (carry + (intVal(n1[p1]) * intVal(n2[p2]))) % 10; + carry = (carry + (intVal(n1[p1]) * intVal(n2[p2]))) / 10; + + curSum.append(val); + p1--; + } - String num5 = "123456789"; - String num6 = "987654321"; - // "121932631112635269" - System.out.println(multiply(num5, num6)); + if (carry != 0) { + curSum.append(carry); + } + curSum = curSum.reverse(); + for (int i = 0; i < n2.length - 1 - p2; i++) { + curSum.append("0"); + } + product = sum(product, curSum.toString()); + + p2--; + carry = 0; + } + + return product; } + private String sum(String s1, String s2) { + int p1 = s1.length() - 1; + int p2 = s2.length() - 1; + + StringBuilder sum = new StringBuilder(); + int carry = 0; + while (p1 >= 0 && p2 >= 0) { + int val = (carry + intVal(s1.charAt(p1)) + intVal(s2.charAt(p2))) % 10; + carry = (carry + intVal(s1.charAt(p1)) + intVal(s2.charAt(p2))) / 10; + + sum.append(val); + p1--; + p2--; + } + + while (p1 >= 0) { + int val = (carry + intVal(s1.charAt(p1))) % 10; + carry = (carry + intVal(s1.charAt(p1))) / 10; + + sum.append(val); + p1--; + } + + while (p2 >= 0) { + int val = (carry + intVal(s2.charAt(p2))) % 10; + carry = (carry + intVal(s2.charAt(p2))) / 10; + + sum.append(val); + p2--; + } + + if (carry != 0) { + sum.append(carry); + } + + return sum.reverse().toString(); + } + + private int intVal(char c) { + return c - '0'; + } + + public String multiply(String num1, String num2) { char[] charsA = num1.toCharArray(); char[] charsB = num2.toCharArray(); diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" index 42fdb4a1..9b343c94 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" @@ -4,7 +4,10 @@ import org.junit.Assert; import org.junit.Test; -import java.util.*; +import java.util.ArrayList; +import java.util.Deque; +import java.util.LinkedList; +import java.util.List; /* 给定一个 没有重复 数字的序列,返回其所有可能的全排列。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" index 75bdd4fd..55d5ab64 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" @@ -40,6 +40,46 @@ public void testCase() { } public List> permuteUnique(int[] nums) { + if (nums == null || nums.length == 0) { + return new ArrayList(); + } + + List> result = new ArrayList(); + process(nums, 0, result); + return result; + } + + private void process(int[] nums, int index, List> result) { + if (index == nums.length) { + List e = toArrayList(nums); + if (!result.contains(e)) { + result.add(e); + } + return; + } + + for (int i = index; i < nums.length; i++) { + swap(nums, i, index); + process(nums, index + 1, result); + swap(nums, i, index); + } + } + + private void swap(int[] nums, int a, int b) { + int tmp = nums[a]; + nums[a] = nums[b]; + nums[b] = tmp; + } + + private List toArrayList(int[] nums) { + List ans = new ArrayList(nums.length); + for (int i = 0; i < nums.length; i++) { + ans.add(nums[i]); + } + return ans; + } + + public List> permuteUnique2(int[] nums) { List> result = new ArrayList<>(); Deque path = new LinkedList<>(); boolean[] used = new boolean[nums.length]; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index d89ba5ab..ff5cb74f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -33,7 +33,6 @@ public void testCase() { ListNode actual = reverseList(head); SysOut.printLinkedNode(actual); Assert.assertTrue(CompareUtils.compareSingleListNode(excepted, actual)); - } /** @@ -59,7 +58,7 @@ public ListNode reverseList3(ListNode head) { return head; } - ListNode prev = reverseList(head.next); + ListNode prev = reverseList3(head.next); ListNode p = prev; while (p.next != null) { p = p.next; diff --git a/src/main/java/algorithm_practice/README.md b/src/main/java/algorithm_practice/README.md index 7d029138..e5b82ca9 100644 --- a/src/main/java/algorithm_practice/README.md +++ b/src/main/java/algorithm_practice/README.md @@ -119,4 +119,11 @@ dfs - [M210_课程表2](./LeetCode/code200/M210_课程表2.java) ## 无向图 检测是否有环 并查集 - - []() \ No newline at end of file + - []() + +## 多线程相关 + + - [1114. 按序打印](https://leetcode.cn/problems/print-in-order/description/) + - [1115. 交替打印 FooBar](https://leetcode.cn/problems/print-foobar-alternately/description/) + - [1116. 打印零与奇偶数](https://leetcode.cn/problems/print-zero-even-odd/description/) + - [1195. 交替打印字符串](https://leetcode.cn/problems/fizz-buzz-multithreaded/) diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/README.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/README.md" new file mode 100644 index 00000000..e69de29b diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/thread_demo/README.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/thread_demo/README.md" new file mode 100644 index 00000000..61677046 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/thread_demo/README.md" @@ -0,0 +1,2 @@ + + diff --git a/src/main/java/common/util/AssertUtils.java b/src/main/java/common/util/AssertUtils.java new file mode 100644 index 00000000..85533a61 --- /dev/null +++ b/src/main/java/common/util/AssertUtils.java @@ -0,0 +1,55 @@ +package common.util; + +import common.datastruct.ListNode; +import io.github.nibnait.common.utils.DataUtils; +import io.github.nibnait.common.utils.compare.CompareUtils; + +import java.util.List; + +/** + * @see org.junit.Assert + * Created by nibnait on 2022/12/26 + */ +public class AssertUtils { + + private AssertUtils() { + throw new AssertionError("工具类不允许被实例化"); + } + + public static void compareListList(List> expect, List> actual, int[] nums) { + if (!common.util.CompareUtils.compareListList(expect, actual)) { + LogUtil.log("nums: {}", nums); + LogUtil.log("except: {}", DataUtils.toJsonStringArray(expect)); + LogUtil.log("actual: {}", DataUtils.toJsonStringArray(actual)); + throw new AssertionError(); + } + } + + public static void compareListNode(ListNode expect, ListNode actual) { + if (!common.util.CompareUtils.compareSingleListNode(expect, actual)) { + LogUtil.print("except: "); SysOut.printLinkedNode(expect); + LogUtil.print("actual: "); SysOut.printLinkedNode(actual); + throw new AssertionError(); + } + } + + public static void compareString(String expect, String actual) { + if (!CompareUtils.matchObject(expect, actual)) { + LogUtil.log("except: {}", DataUtils.toJsonStringArray(expect)); + LogUtil.log("actual: {}", DataUtils.toJsonStringArray(actual)); + throw new AssertionError(); + } + } + + public static void compareStringList(List expect, List actual) { + if (actual.size() != expect.size()) { + LogUtil.log("except: {}", DataUtils.toJsonStringArray(expect)); + LogUtil.log("actual: {}", DataUtils.toJsonStringArray(actual)); + throw new AssertionError(); + } + + for (int i = 0; i < expect.size(); i++) { + compareString(expect.get(i), actual.get(i)); + } + } +} diff --git a/src/main/java/common/util/CompareUtils.java b/src/main/java/common/util/CompareUtils.java index 17911914..0b1b7d88 100644 --- a/src/main/java/common/util/CompareUtils.java +++ b/src/main/java/common/util/CompareUtils.java @@ -3,6 +3,9 @@ import common.datastruct.ListNode; import common.datastruct.TreeNode; +import java.util.*; +import java.util.stream.Collectors; + /** * Created by nibnait on 2022/04/11 */ @@ -83,4 +86,75 @@ public static int max(int a, int b, int c) { public static int min(int a, int b, int c) { return Math.min(a, Math.min(b, c)); } + + /** + * 比较两个数组 + */ + public static boolean compareArray(int[] arr1, int[] arr2) { + if (arr1.length != arr2.length) { + return false; + } + for (int i = 0; i < arr1.length; i++) { + if (arr1[i] != arr2[i]) { + return false; + } + } + return true; + } + + public static boolean compareArrayIgnoreOrder(int[] arr1, int[] arr2) { + if (arr1.length != arr2.length) { + return false; + } + + Arrays.sort(arr1); + Arrays.sort(arr2); + for (int i = 0; i < arr1.length; i++) { + if (arr1[i] != arr2[i]) { + return false; + } + } + return true; + } + + public static boolean compareListList(List> expect, List> actual) { + if (expect.size() != actual.size()) { + return false; + } + + expect = expect.stream().sorted(comparator).collect(Collectors.toList()); + actual = actual.stream().sorted(comparator).collect(Collectors.toList()); + + for (int i = 0; i < expect.size(); i++) { + List expectList = expect.get(i).stream().sorted().collect(Collectors.toList()); + if (!compareList(expectList, actual.get(i))) { + return false; + } + } + + return true; + } + + private static Comparator> comparator = new Comparator>() { + @Override + public int compare(List o1, List o2) { + return o1.hashCode() - o2.hashCode(); + } + }; + + public static boolean compareList(List expectList, List actualList) { + if (expectList.size() != actualList.size()) { + return false; + } + + expectList = expectList.stream().sorted().collect(Collectors.toList()); + actualList = actualList.stream().sorted().collect(Collectors.toList()); + + for (int i = 0; i < expectList.size(); i++) { + if (!Objects.equals(expectList.get(i), actualList.get(i))) { + return false; + } + } + return true; + } } diff --git a/src/main/java/common/util/ConstructLinkedNode.java b/src/main/java/common/util/ConstructLinkedNode.java index b74d2192..8a206dfe 100644 --- a/src/main/java/common/util/ConstructLinkedNode.java +++ b/src/main/java/common/util/ConstructLinkedNode.java @@ -2,12 +2,27 @@ import common.datastruct.ListNode; +import java.util.List; + /** * 构造链表 * Created by nibnait on 2019-08-08 */ public class ConstructLinkedNode { + public static ListNode constructSingleLinkedNode(List nums) { + ListNode head = new ListNode(); + ListNode curNode = head; + for (int i = 0; i < nums.size(); i++) { + curNode.val = nums.get(i); + if (i != nums.size() - 1) { + curNode.next = new ListNode(); + curNode = curNode.next; + } + } + return head; + } + public static ListNode constructSingleLinkedNode(int[] nums) { ListNode head = new ListNode(); ListNode curNode = head; diff --git a/src/main/java/common/util/LogUtil.java b/src/main/java/common/util/LogUtil.java new file mode 100644 index 00000000..47d6b9ca --- /dev/null +++ b/src/main/java/common/util/LogUtil.java @@ -0,0 +1,33 @@ +package common.util; + +import io.github.nibnait.common.utils.DataUtils; + +import java.util.function.Function; + +/** + * Created by nibnait on 2022/12/26 + */ +public class LogUtil { + + private LogUtil() { + throw new AssertionError("工具类不允许被实例化"); + } + + public static void printf(String format, Object... args) { + System.out.println(String.format(format, args)); + } + + public static void print(Object obj) { + System.out.print(obj); + } + + public static void println(Object obj, Function function, T t) { + System.out.println(obj); + function.apply(t); + } + + public static void log(String format, Object... args) { + System.out.println(DataUtils.format(format, args)); + } + +} diff --git a/src/main/test/UnitTestDemo.java b/src/main/test/UnitTestDemo.java index b7eeaa3e..dc0d52ee 100644 --- a/src/main/test/UnitTestDemo.java +++ b/src/main/test/UnitTestDemo.java @@ -81,7 +81,6 @@ public void testCase1() { } } - @Test public int test(Object... args) { boolean f1 = true; boolean f2 = false; @@ -92,4 +91,830 @@ public int test(Object... args) { return 0; } + @Test + public void t() { + String s = "第一章 业务架构知识学习\n" + + "\n" + + "\n" + + "1.01-SpringCloud Alibaba云商城大纲介绍\n" + + "7分钟\n" + + "\n" + + "2.02-SpringCloud Alibaba云商城课程目标介绍\n" + + "2分钟\n" + + "\n" + + "3.03-电商知识学习\n" + + "4分钟\n" + + "\n" + + "4.04-云商城业务功能介绍\n" + + "6分钟\n" + + "\n" + + "5.05-前后端分离开发模式讲解\n" + + "6分钟\n" + + "\n" + + "6.06-前后端分离-swagger使用\n" + + "13分钟\n" + + "\n" + + "7.07-云商城技术架构讲解\n" + + "10分钟\n" + + "\n" + + "8.08-云商城表结构分析\n" + + "17分钟\n" + + "\n" + + "9.09-项目开发环境准备\n" + + "6分钟\n" + + "\n" + + "10.10-项目结构讲解\n" + + "9分钟\n" + + "\n" + + "11.11-工程搭建-顶级父工程搭建\n" + + "6分钟\n" + + "\n" + + "12.12-工程搭建-各个模块父工程搭建\n" + + "6分钟\n" + + "\n" + + "13.13-工程搭建-公共工程搭建\n" + + "9分钟\n" + + "\n" + + "14.14-MyBatisPlus集成-MyBatisPlus介绍\n" + + "5分钟\n" + + "\n" + + "15.15-MyBatisPlus集成-集成配置\n" + + "17分钟\n" + + "\n" + + "16.16-MyBatisPlus集成-增删改实现\n" + + "15分钟\n" + + "\n" + + "17.17-MyBatisPlus集成-多条件 分页搜索\n" + + "16分钟\n" + + "第二章 基础数据处理和分布式文件存储\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "7分钟\n" + + "\n" + + "2.02-Ceph特性介绍\n" + + "8分钟\n" + + "\n" + + "3.03-Ceph架构图讲解\n" + + "6分钟\n" + + "\n" + + "4.04-集群环境准备\n" + + "18分钟\n" + + "\n" + + "5.05-Ceph集群搭建-Ceph安装\n" + + "5分钟\n" + + "\n" + + "6.06-Ceph集群-OSD安装\n" + + "5分钟\n" + + "\n" + + "7.07-Ceph集群-Dashboard安装\n" + + "5分钟\n" + + "\n" + + "8.08-Ceph集群-CephFS安装\n" + + "3分钟\n" + + "\n" + + "9.09-Ceph Swift Api开发准备工作\n" + + "6分钟\n" + + "\n" + + "10.10-SpringBoot集成Ceph实现文件上传和下载\n" + + "17分钟\n" + + "\n" + + "11.11-Spu和Sku关系讲解\n" + + "12分钟\n" + + "\n" + + "12.12-Spu和Sku表结构介绍\n" + + "4分钟\n" + + "\n" + + "13.13-产品发布流程分析\n" + + "6分钟\n" + + "\n" + + "14.14-产品发布-分类查询\n" + + "11分钟\n" + + "\n" + + "15.15-产品发布-品牌加载\n" + + "11分钟\n" + + "\n" + + "16.16-产品发布-属性加载\n" + + "8分钟\n" + + "\n" + + "17.17-产品发布-组合数据分析\n" + + "8分钟\n" + + "\n" + + "18.18-产品发布-保存功能\n" + + "16分钟\n" + + "\n" + + "19.19-产品发布-保存功能演示\n" + + "7分钟\n" + + "\n" + + "20.20-产品修改-代码实现\n" + + "3分钟\n" + + "\n" + + "21.21-MyBatisPlus代码生成器讲解\n" + + "11分钟\n" + + "第三章 高性能门户网构建\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "4分钟\n" + + "\n" + + "2.02-OpenResty学习和安装讲解\n" + + "14分钟\n" + + "\n" + + "3.03-OpenResty发布静态网站\n" + + "14分钟\n" + + "\n" + + "4.04-Lua脚本介绍\n" + + "2分钟\n" + + "\n" + + "5.05-Lua脚本常用操作讲解\n" + + "9分钟\n" + + "\n" + + "6.06-Lua脚本编程学习\n" + + "4分钟\n" + + "\n" + + "7.07-多级缓存架构设计\n" + + "6分钟\n" + + "\n" + + "8.08-门户首页推广产品加载实现\n" + + "13分钟\n" + + "\n" + + "9.09-缓存操作注解讲解\n" + + "3分钟\n" + + "\n" + + "10.10-缓存注解实现缓存加载和删除\n" + + "9分钟\n" + + "\n" + + "11.11-缓存注解操作缓存修改\n" + + "3分钟\n" + + "\n" + + "12.12-注解缓存操作-缓存操作优化\n" + + "4分钟\n" + + "\n" + + "13.13-缓存操作-feign接口编写\n" + + "3分钟\n" + + "\n" + + "14.14-Lua Redis缓存操作\n" + + "13分钟\n" + + "\n" + + "15.15-Nginx代理缓存实现\n" + + "12分钟\n" + + "\n" + + "16.16-Nginx代理缓存讲解\n" + + "7分钟\n" + + "\n" + + "17.17-缓存一致性-Canal原理讲解\n" + + "12分钟\n" + + "\n" + + "18.18-缓存一致性-Canal安装\n" + + "7分钟\n" + + "\n" + + "19.19-缓存一致性-Canal监听数据库增量日志消费\n" + + "8分钟\n" + + "\n" + + "20.20-缓存一致性-实时更新Redis缓存实现\n" + + "5分钟\n" + + "第四章 海量数据搜索实现\n" + + "\n" + + "\n" + + "1.01-学习目标介绍\n" + + "6分钟\n" + + "\n" + + "2.02-搜索工程搭建实现\n" + + "12分钟\n" + + "\n" + + "3.03-ES索引增加和删除功能实现\n" + + "11分钟\n" + + "\n" + + "4.04-ES索引库数据实时更新操作实现\n" + + "20分钟\n" + + "\n" + + "5.05-ES实现关键词搜索\n" + + "11分钟\n" + + "\n" + + "6.06-ES商品搜索-分组数据条件回显查询\n" + + "19分钟\n" + + "\n" + + "7.07-ES商品搜索-动态属性条件回显查询\n" + + "18分钟\n" + + "\n" + + "8.08-ES搜索-分类、品牌、价格区间搜索\n" + + "9分钟\n" + + "\n" + + "9.09-ES搜索-动态属性搜索实现\n" + + "4分钟\n" + + "\n" + + "10.10-ES搜索-分页实现\n" + + "3分钟\n" + + "\n" + + "11.11-ES搜索-多条件查询测试和问题讲解\n" + + "9分钟\n" + + "\n" + + "12.12-ES搜索-多种排序实现\n" + + "5分钟\n" + + "\n" + + "13.13-ES搜索-高亮功能配置\n" + + "5分钟\n" + + "\n" + + "14.14-ES搜索-高亮数据映射转换实现\n" + + "16分钟\n" + + "第五章 商品详情页实战\n" + + "\n" + + "\n" + + "1.01-学习目标介绍\n" + + "3分钟\n" + + "\n" + + "2.02-Thymeleaf集成SpringBoot讲解\n" + + "11分钟\n" + + "\n" + + "3.03-搜索渲染-结果集展示实现\n" + + "11分钟\n" + + "\n" + + "4.04-搜索渲染-关键词回显\n" + + "7分钟\n" + + "\n" + + "5.05-搜索渲染-品牌和分类搜索条件回显实现\n" + + "7分钟\n" + + "\n" + + "6.06-搜索渲染-动态条件处理\n" + + "7分钟\n" + + "\n" + + "7.07-搜索渲染-搜索条件记录并回显\n" + + "11分钟\n" + + "\n" + + "8.08-搜索渲染-条件操作和URL地址关系分析\n" + + "7分钟\n" + + "\n" + + "9.09-搜索渲染-条件动态添加和移除操作实现\n" + + "10分钟\n" + + "\n" + + "10.10-搜索渲染-分页实现\n" + + "14分钟\n" + + "\n" + + "11.11-搜索渲染-排序实现\n" + + "5分钟\n" + + "\n" + + "12.12-商品详情页生成-工程搭建\n" + + "5分钟\n" + + "\n" + + "13.13-商品详情页-页面数据查询\n" + + "9分钟\n" + + "\n" + + "14.14-详情页静态页生成实现\n" + + "5分钟\n" + + "\n" + + "15.15-详情页生成数据加载实现\n" + + "11分钟\n" + + "\n" + + "16.16-详情页生成-静态页生成测试\n" + + "5分钟\n" + + "\n" + + "17.17-详情页生成-分类填充\n" + + "3分钟\n" + + "\n" + + "18.18-静态页生成-图片和属性填充\n" + + "4分钟\n" + + "\n" + + "19.19-静态页生成-默认Sku选中实现\n" + + "7分钟\n" + + "\n" + + "20.20-静态页-属性选中实现\n" + + "6分钟\n" + + "\n" + + "21.21-静态页-动态选中Sku实现\n" + + "9分钟\n" + + "\n" + + "22.22-静态页实时更新实现\n" + + "7分钟\n" + + "第六章 购物车、订单\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "2分钟\n" + + "\n" + + "2.02-MongoDB介绍\n" + + "6分钟\n" + + "\n" + + "3.03-MongoDB安装\n" + + "7分钟\n" + + "\n" + + "4.04-MongoDB常用操作讲解\n" + + "16分钟\n" + + "\n" + + "5.05-购物车功能分析\n" + + "5分钟\n" + + "\n" + + "6.06-SpringData MongoDB特点介绍\n" + + "5分钟\n" + + "\n" + + "7.07-购物车工程搭建\n" + + "9分钟\n" + + "\n" + + "8.08-添加购物车功能\n" + + "18分钟\n" + + "\n" + + "9.09-商品加入购物车流程测试\n" + + "5分钟\n" + + "\n" + + "10.10-购物车列表实现\n" + + "7分钟\n" + + "\n" + + "11.11-购物车页面对接\n" + + "3分钟\n" + + "\n" + + "12.12-订单功能分析\n" + + "2分钟\n" + + "\n" + + "13.13-收件地址加载\n" + + "9分钟\n" + + "\n" + + "14.14-选中购物车列表查询\n" + + "7分钟\n" + + "\n" + + "15.15-选中购物车删除操作实现\n" + + "5分钟\n" + + "\n" + + "16.16-订单工程搭建\n" + + "9分钟\n" + + "\n" + + "17.17-库存递减实现\n" + + "7分钟\n" + + "\n" + + "18.18-下单功能实现\n" + + "16分钟\n" + + "\n" + + "19.19-页面操作购物车、下单流程测试\n" + + "10分钟\n" + + "第七章 分布式事务解决方案\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "3分钟\n" + + "\n" + + "2.02-分布式事务介绍\n" + + "11分钟\n" + + "\n" + + "3.03-CAP原理\n" + + "5分钟\n" + + "\n" + + "4.04-BASE理论讲解\n" + + "6分钟\n" + + "\n" + + "5.05-2PC和3PC事务模型讲解\n" + + "8分钟\n" + + "\n" + + "6.06-TCC事务模型讲解\n" + + "6分钟\n" + + "\n" + + "7.07-MQ分布式事务方案讲解\n" + + "4分钟\n" + + "\n" + + "8.08-下单分布式事务问题分析\n" + + "4分钟\n" + + "\n" + + "9.09-Seata介绍\n" + + "6分钟\n" + + "\n" + + "10.10-Seata-AT模式讲解\n" + + "16分钟\n" + + "\n" + + "11.11-Seata 分布式事务实战\n" + + "19分钟\n" + + "\n" + + "12.12-Seata控制下单分布式事务测试\n" + + "7分钟\n" + + "\n" + + "13.13-RocketMQ安装\n" + + "8分钟\n" + + "\n" + + "14.14-RocketMQ事务消息运行流程讲解\n" + + "9分钟\n" + + "\n" + + "15.15-支付微服务搭建\n" + + "6分钟\n" + + "\n" + + "16.16-RocketMQ事务消息案例准备工作\n" + + "11分钟\n" + + "\n" + + "17.17-RocketMQ事务消息绑定本地事务业务操作\n" + + "7分钟\n" + + "\n" + + "18.18-RocketMQ事务消息监听实现\n" + + "5分钟\n" + + "\n" + + "19.19-RocketMQ事务消息消费实现\n" + + "3分钟\n" + + "第八章 云商城 微信支付\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "5分钟\n" + + "\n" + + "2.02-摘要加密-MD5讲解\n" + + "15分钟\n" + + "\n" + + "3.03-验签流程讲解\n" + + "7分钟\n" + + "\n" + + "4.04-Base64编码讲解\n" + + "7分钟\n" + + "\n" + + "5.05-AES加密算法讲解\n" + + "7分钟\n" + + "\n" + + "6.06-AES算法库下载并安装\n" + + "3分钟\n" + + "\n" + + "7.07-AES加密解密实现\n" + + "9分钟\n" + + "\n" + + "8.08-AES加密算法测试\n" + + "5分钟\n" + + "\n" + + "9.09-微信支付模式二实现流程分析\n" + + "19分钟\n" + + "\n" + + "10.10-微信支付SDK安装\n" + + "9分钟\n" + + "\n" + + "11.11-微信支付统一下单实现\n" + + "10分钟\n" + + "\n" + + "12.12-微信扫码支付测试\n" + + "3分钟\n" + + "\n" + + "13.13-扫码支付安全验签流程讲解\n" + + "5分钟\n" + + "\n" + + "14.14-支付数据加密验签实现\n" + + "17分钟\n" + + "\n" + + "15.15-内网穿透工具介绍\n" + + "4分钟\n" + + "\n" + + "16.16-支付通知数据获取实现\n" + + "11分钟\n" + + "\n" + + "17.17-支付成功状态变更\n" + + "5分钟\n" + + "\n" + + "18.18-支付状态主动查询实现\n" + + "14分钟\n" + + "\n" + + "19.19-订单支付流程测试\n" + + "4分钟\n" + + "\n" + + "20.20-退款实现流程分析\n" + + "4分钟\n" + + "\n" + + "21.21- 微信退款申请记录操作\n" + + "11分钟\n" + + "\n" + + "22.22-取消订单申请消息发送\n" + + "16分钟\n" + + "\n" + + "23.23-退款申请实现\n" + + "6分钟\n" + + "\n" + + "24.24-退款结果解密讲解\n" + + "10分钟\n" + + "\n" + + "25.25-退款结果解析测试\n" + + "5分钟\n" + + "\n" + + "26.26-作业说明\n" + + "1分钟\n" + + "第九章 商品秒杀-数据处理\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "3分钟\n" + + "\n" + + "2.02-秒杀业务设计和表结构设计讲解\n" + + "7分钟\n" + + "\n" + + "3.03-秒杀业务特点讲解\n" + + "3分钟\n" + + "\n" + + "4.04-秒杀架构设计讲解\n" + + "5分钟\n" + + "\n" + + "5.05秒杀工程搭建\n" + + "5分钟\n" + + "\n" + + "6.06-活动列表查询实现\n" + + "10分钟\n" + + "\n" + + "7.07-秒杀商品导入索引库实现\n" + + "12分钟\n" + + "\n" + + "8.08-秒杀商品导入索引库测试\n" + + "5分钟\n" + + "\n" + + "9.09-秒杀商品详情页生成后台代码实现\n" + + "13分钟\n" + + "\n" + + "10.10-秒杀商品详情页数据填充\n" + + "4分钟\n" + + "\n" + + "11.11-秒杀商品详情页发布\n" + + "11分钟\n" + + "\n" + + "12.12-详情页和索引实时更新操作\n" + + "8分钟\n" + + "\n" + + "13.13-详情页和索引实时更新操作\n" + + "2分钟\n" + + "\n" + + "14.14-动态定时任务对比\n" + + "9分钟\n" + + "\n" + + "15.15-elasticjob静态定时任务实现\n" + + "7分钟\n" + + "\n" + + "16.16-elasticjob动态定时任务操作\n" + + "15分钟\n" + + "\n" + + "17.17-动态创建定时任务案例\n" + + "8分钟\n" + + "\n" + + "18.18-动态定时任务测试\n" + + "5分钟\n" + + "\n" + + "19.19-定时删除页面实现\n" + + "23分钟\n" + + "第一十章 商品秒杀-热门数据实时收集\n" + + "\n" + + "\n" + + "1.01-课程目标\n" + + "5分钟\n" + + "\n" + + "2.02-热门数据收集流程实现\n" + + "6分钟\n" + + "\n" + + "3.03-Lua高级指令执行流程讲解\n" + + "6分钟\n" + + "\n" + + "4.04-Kafka常用操作讲解\n" + + "10分钟\n" + + "\n" + + "5.05-秒杀商品详情页发布\n" + + "7分钟\n" + + "\n" + + "6.06-Lua操作Kafka组件安装\n" + + "5分钟\n" + + "\n" + + "7.07-Lua收集日志实现\n" + + "10分钟\n" + + "\n" + + "8.08-Apache Druid介绍\n" + + "9分钟\n" + + "\n" + + "9.09-Apache Druid架构讲解\n" + + "4分钟\n" + + "\n" + + "10.10-Apache Druid安装\n" + + "9分钟\n" + + "\n" + + "11.11-Apache Druid批量数据导入\n" + + "10分钟\n" + + "\n" + + "12.12-Apache Druid垂直日志收集实时数据流摄入\n" + + "16分钟\n" + + "\n" + + "13.13-DruidSQL语法讲解\n" + + "8分钟\n" + + "\n" + + "14.14-DruidSQL查询实战\n" + + "9分钟\n" + + "第一十一章 商品秒杀-程序隔离解决方案\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "6分钟\n" + + "\n" + + "2.02-查询Druid工程搭建\n" + + "13分钟\n" + + "\n" + + "3.03-MyBatis查询Apache Druid-查询所有\n" + + "4分钟\n" + + "\n" + + "4.04-MyBatis查询Apache Druid-查询前N条记录\n" + + "5分钟\n" + + "\n" + + "5.05-MyBatis查询Apache Druid-分页查询\n" + + "14分钟\n" + + "\n" + + "6.06-MyBatis查询Apache Druid分页 排序\n" + + "5分钟\n" + + "\n" + + "7.07-MyBatis查询Apache Druid-时间查询操作\n" + + "9分钟\n" + + "\n" + + "8.08-MyBatis查询Apache Druid-排除指定数据\n" + + "10分钟\n" + + "\n" + + "9.09-热门商品分析实现\n" + + "14分钟\n" + + "\n" + + "10.10-热门数据定时分析\n" + + "12分钟\n" + + "\n" + + "11.11-热门商品分离操作\n" + + "12分钟\n" + + "\n" + + "12.12-微服务网关搭建\n" + + "9分钟\n" + + "\n" + + "13.13-热门商品抢单排队实现\n" + + "21分钟\n" + + "\n" + + "14.14-热门商品抢单和非热门商品抢单程序分离实现\n" + + "6分钟\n" + + "\n" + + "15.15-抢单监听实现\n" + + "5分钟\n" + + "\n" + + "16.16-热门商品抢单下单实现\n" + + "18分钟\n" + + "\n" + + "17.17-抢单过程问题分析\n" + + "4分钟\n" + + "\n" + + "18.18-分布式锁控制抢单超卖现象\n" + + "18分钟\n" + + "第一十二章 网关鉴权\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "4分钟\n" + + "\n" + + "2.02-权限校验流程分析\n" + + "7分钟\n" + + "\n" + + "3.03-权限表结构分析\n" + + "7分钟\n" + + "\n" + + "4.04-JWT令牌介绍\n" + + "7分钟\n" + + "\n" + + "5.05-JWT令牌结构\n" + + "5分钟\n" + + "\n" + + "6.06-JWT令牌创建和解析\n" + + "13分钟\n" + + "\n" + + "7.07-登录创建令牌实现\n" + + "10分钟\n" + + "\n" + + "8.08-JWT令牌IP安全校验封装\n" + + "6分钟\n" + + "\n" + + "9.09-JWT令牌基于IP校验\n" + + "23分钟\n" + + "\n" + + "10.10-权限校验流程分析\n" + + "11分钟\n" + + "\n" + + "11.11-鉴权工程搭建X\n" + + "5分钟\n" + + "\n" + + "12.12-权限初始化加载实现\n" + + "23分钟\n" + + "\n" + + "13.13-权限初始化测试\n" + + "3分钟\n" + + "\n" + + "14.14-Gateway过滤器顺序调整\n" + + "5分钟\n" + + "\n" + + "15.15-是否进行权限拦截控制\n" + + "20分钟\n" + + "\n" + + "16.16-令牌校验抽取\n" + + "2分钟\n" + + "\n" + + "17.17-角色权限匹配\n" + + "7分钟\n" + + "\n" + + "18.18-角色权限测试\n" + + "5分钟\n" + + "第一十三章 服务安全控制\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "3分钟\n" + + "\n" + + "2.02-常见限流方案\n" + + "8分钟\n" + + "\n" + + "3.03-微服务网关限流操作\n" + + "15分钟\n" + + "\n" + + "4.04-Nginx速率限流讲解\n" + + "9分钟\n" + + "\n" + + "5.05-Nginx并发量限流实现\n" + + "12分钟\n" + + "\n" + + "6.06-Nginx黑白名单操作\n" + + "4分钟\n" + + "\n" + + "7.07-Redis集群原理分析\n" + + "6分钟\n" + + "\n" + + "8.08-Redis集群搭建\n" + + "12分钟\n" + + "\n" + + "9.09-SpringBoot链接Redis集群\n" + + "2分钟\n" + + "\n" + + "10.10-Redis集群扩容和收容\n" + + "16分钟\n" + + "\n" + + "11.11-缓存灾难问题介绍\n" + + "6分钟\n" + + "\n" + + "12.12-布隆过滤器原理\n" + + "7分钟\n" + + "\n" + + "13.13-Gava布隆过滤器学习\n" + + "6分钟\n" + + "\n" + + "14.14-Redis布隆过滤器无效请求路径过滤功能分析\n" + + "4分钟\n" + + "\n" + + "15.15-Redis布隆过滤器数据初始化\n" + + "6分钟\n" + + "\n" + + "16.16-基于Redis布隆过滤器实现无效路径过滤\n" + + "7分钟\n" + + "\n" + + "17.17-无效路径过滤思考问题\n" + + "1分钟\n" + + "第一十四章 百万并发站点构建\n" + + "\n" + + "\n" + + "1.01-课程目标介绍\n" + + "5分钟\n" + + "\n" + + "2.02-Sentinel介绍\n" + + "6分钟\n" + + "\n" + + "3.03-Sentinel功能介绍\n" + + "6分钟\n" + + "\n" + + "4.04-Sentinel集成Gateway介绍\n" + + "8分钟\n" + + "\n" + + "5.05-Sentinel集成Gateway\n" + + "5分钟\n" + + "\n" + + "6.06-Sentinel集成Gateway-Api创建\n" + + "9分钟\n" + + "\n" + + "7.07Sentinel集成Gateway-规则创建\n" + + "7分钟\n" + + "\n" + + "8.08-Sentinel规则属性讲解\n" + + "14分钟\n" + + "\n" + + "9.09-Sentinel控制台安装\n" + + "3分钟\n" + + "\n" + + "10.10-SpringCloud Gateway对接Sentinel控制台\n" + + "4分钟\n" + + "\n" + + "11.11-Sentinel控制台使用\n" + + "8分钟\n" + + "\n" + + "12.12-Lvs介绍\n" + + "6分钟\n" + + "\n" + + "13.13-Lvs负载均衡模式介绍\n" + + "6分钟\n" + + "\n" + + "14.14-Vip配置\n" + + "9分钟\n" + + "\n" + + "15.15-Lvs地址解析配置\n" + + "7分钟\n" + + "\n" + + "16.16-Lvs Nginx集群创建\n" + + "5分钟\n" + + "\n" + + "17.17-Lvs Nginx集群测试\n" + + "1分钟"; + + String[] split = s.split("\n"); + int sum = 0; + for (String s1 : split) { + if (s1.contains("分钟")) { + String 分钟 = s1.substring(0, s1.indexOf("分钟")); + sum += Integer.valueOf(分钟); + } + } + + System.out.println(sum); + } + } From f2415774dc6cc76c908cb6c618baa298375d9156 Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 1 Mar 2023 12:07:35 +0800 Subject: [PATCH 29/36] =?UTF-8?q?feat=20=E5=B0=8F=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\347\232\204\347\237\251\345\275\242.java" | 98 ++++++++++- ...\345\244\247\347\237\251\345\275\242.java" | 120 +++++++++++++ ...\346\257\215\347\273\204\345\220\210.java" | 2 +- ...\345\205\250\346\216\222\345\210\227.java" | 39 ++++- ...345\205\250\346\216\222\345\210\2272.java" | 35 ++-- ...\346\226\207\351\223\276\350\241\250.java" | 91 ++++++++++ .../LockAndAqs.java" | 25 +++ ...1_\345\205\254\345\271\263\351\224\201.md" | 1 - .../JUC/JUC_AQS/mylock/MyLock.java" | 93 ++++++++++ .../JUC/JUC_AQS/mylock/MyLockTest.java" | 55 ++++++ ...\345\217\257\350\247\201\346\200\247.java" | 8 + .../OddEvenPrint.java" | 57 ++++++ .../aThreadJoinDemo.java" | 2 +- .../cThreadWaitNotifyDemo.java" | 2 +- .../dThreadAwaitSingalDemo.java" | 2 +- .../Map\347\261\273.java" | 164 ++---------------- .../cc/tianbin/java/mybatis/MybatisTest.java | 1 - 17 files changed, 606 insertions(+), 189 deletions(-) create mode 100644 "src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" create mode 100644 "src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" index 599227da..72f71eb9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" @@ -1,21 +1,23 @@ package algorithm_practice.LeetCode.code000; +import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Test; +import java.util.List; import java.util.Stack; /** - * 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 - * 求在该柱状图中,能够勾勒出来的矩形的最大面积。 - * + * 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 + * 求在该柱状图中,能够勾勒出来的矩形的最大面积。 + *

* 输入:heights = [2,1,5,6,2,3] * 输出:10 - * 解释:最大的矩形为图中红色区域,面积为 10 - * + * 解释:最大的矩形为图中红色区域,面积为 10 + *

* 输入: heights = [2,4] * 输出: 4 - * + *

* https://leetcode.cn/problems/largest-rectangle-in-histogram/ * Created by nibnait on 2022/11/16 */ @@ -23,15 +25,95 @@ public class H084_柱状图中最大的矩形 { @Test public void test() { - int[] heights = new int[]{2,1,5,6,2,3}; + int[] heights = new int[]{2, 1, 5, 6, 2, 3}; int ans = largestRectangleArea(heights); Assert.assertEquals(10, ans); - heights = new int[]{2,4}; + heights = new int[]{2, 4}; ans = largestRectangleArea(heights); Assert.assertEquals(4, ans); + + heights = new int[]{1, 1}; + ans = largestRectangleArea(heights); + Assert.assertEquals(2, ans); + + heights = new int[]{1, 2, 3, 3, 4, 3, 3, 5, 1}; + ans = largestRectangleArea(heights); + Assert.assertEquals(18, ans); + } + + /** + * 法1: + * 1. 单调栈,找到每个元素,最近的 左、右 两边的第一个比他小的index + * 2. 再遍历一遍数组,求以每个元素为高时,其对应的矩形的面积 + */ + public int largestRectangleArea1(int[] heights) { + + int[][] nearestSmallIndex = nearestSmallIndex(heights); + int[] nearLeftSmall = new int[heights.length]; + int[] nearRightSmall = new int[heights.length]; + for (int i = 0; i < nearestSmallIndex.length; i++) { + nearLeftSmall[i] = nearestSmallIndex[i][0]; + nearRightSmall[i] = nearestSmallIndex[i][1]; + } + + int maxArea = heights[0] * getWidth(-1, nearRightSmall[0], heights.length); + for (int i = 1; i < heights.length; i++) { + maxArea = Math.max(maxArea, heights[i] * getWidth(nearLeftSmall[i], nearRightSmall[i], heights.length)); + } + return maxArea; + } + + private int getWidth(int left, int right, int length) { + if (left == -1 && right == -1) { + return length; + } + if (left == -1) { + return right; + } + if (right == -1) { + return length - left - 1; + } + return right - left - 1; + } + + private int[][] nearestSmallIndex(int[] heights) { + int[][] result = new int[heights.length][2]; + Stack> stack = new Stack<>(); + + for (int i = 0; i < heights.length; i++) { + while (!stack.isEmpty() && heights[stack.peek().get(0)] > heights[i]) { + List popIndexs = stack.pop(); + int leftLessIndex = stack.isEmpty() ? -1 : stack.peek().get(stack.peek().size() - 1); + for (Integer popIndex : popIndexs) { + result[popIndex][0] = leftLessIndex; + result[popIndex][1] = i; + } + } + + if (!stack.isEmpty() && heights[stack.peek().get(0)] == heights[i]) { + stack.peek().add(i); + } else { + stack.add(Lists.newArrayList(i)); + } + } + + while (!stack.isEmpty()) { + List popIndexs = stack.pop(); + int leftLessIndex = stack.isEmpty() ? -1 : stack.peek().get(stack.peek().size() - 1); + for (Integer popIndex : popIndexs) { + result[popIndex][0] = leftLessIndex; + result[popIndex][1] = -1; + } + } + + return result; } + /** + * 法2: + * + */ public int largestRectangleArea(int[] heights) { if (heights == null || heights.length == 0) { return 0; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" new file mode 100644 index 00000000..6332c4a2 --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" @@ -0,0 +1,120 @@ +package algorithm_practice.LeetCode.code000; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Stack; + +/* + * 给定一个仅包含 0 和 1 、大小为 rows x cols 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。 + * 示例 1: + * 输入:matrix = [["1","0","1","0","0"], + * ["1","0","1","1","1"], + * ["1","1","1","1","1"], + * ["1","0","0","1","0"]] + * 输出:6 + * + * 示例 2: + * 输入:matrix = [] + * 输出:0 + * + * 示例 3: + * 输入:matrix = [["0"]] + * 输出:0 + * + * 示例 4: + * 输入:matrix = [["1"]] + * 输出:1 + * + * 示例 5: + * 输入:matrix = [["0","0"]] + * 输出:0 + * + * https://leetcode.cn/problems/maximal-rectangle/?favorite=2cktkvj + */ +public class H085_最大矩形 { + + + @Test + public void test() { + char[][] matrix = new char[][]{ + {'1', '0', '1', '0', '0'}, + {'1', '0', '1', '1', '1'}, + {'1', '1', '1', '1', '1'}, + {'0', '0', '0', '1', '0'}, + }; + int ans = maximalRectangle(matrix); + Assert.assertEquals(6, ans); + + matrix = new char[][]{}; + ans = maximalRectangle(matrix); + Assert.assertEquals(0, ans); + + matrix = new char[][]{{'0'}}; + ans = maximalRectangle(matrix); + Assert.assertEquals(0, ans); + + matrix = new char[][]{{'1'}}; + ans = maximalRectangle(matrix); + Assert.assertEquals(1, ans); + + matrix = new char[][]{{'0', '0'}}; + ans = maximalRectangle(matrix); + Assert.assertEquals(0, ans); + + } + + /** + * 跟上一题一样。单调栈。 + * 1. 求出第1层的最大矩形 + * 2. 再求第2层的最大矩形,遍历第2层的时候,遇到0则直接高度归0,非0则高度累加 + * 3. 重复步骤2,遍历3、4、5... 层, + * 4. 循环结束。得到最大的矩形面积 + * + */ + public int maximalRectangle(char[][] matrix) { + if (matrix.length == 0 || matrix[0].length == 0) { + return 0; + } + + int[][] m = new int[matrix.length][matrix[0].length]; + + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[0].length; j++) { + m[i][j] = matrix[i][j] == '0' ? 0 : 1; + } + } + int maxArea = 0; + for (int i = 0; i < m.length; i++) { + if (i >= 1) { + for (int k = 0; k < m[0].length; k++) { + m[i][k] = m[i][k] == 0 ? 0 : m[i-1][k] + m[i][k]; + } + } + + Stack stack = new Stack<>(); + for (int j = 0; j < m[0].length; j++) { + while (!stack.isEmpty() && m[i][j] <= m[i][stack.peek()]) { + int pop = stack.pop(); + int leftIndex = stack.isEmpty() ? -1 : stack.peek(); + int curArea = m[i][pop] * (j - leftIndex - 1); + maxArea = Math.max(maxArea, curArea); + } + + stack.push(j); + } + + while (!stack.isEmpty()) { + int pop = stack.pop(); + int leftIndex = stack.isEmpty() ? -1 : stack.peek(); + int curArea = m[i][pop] * (m[0].length - leftIndex - 1); + maxArea = Math.max(maxArea, curArea); + } + } + + return maxArea; + } + + + +} diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" index a85c6362..6276a55b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" @@ -21,7 +21,7 @@ public void test() { } - private static final char[][] phone = new char[][]{ + private static final char[][] phone = new char[][] { {'.'}, {'.'}, {'a', 'b', 'c'}, diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" index 9b343c94..a3f89bdd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import org.junit.Assert; +import common.util.AssertUtils; import org.junit.Test; import java.util.ArrayList; @@ -35,7 +35,7 @@ public class M046_全排列 { @Test public void testCase() { int[] nums = new int[]{1,2,3}; - List> excepted = Lists.newArrayList( + List> except = Lists.newArrayList( Lists.newArrayList(1,2,3), Lists.newArrayList(1,3,2), Lists.newArrayList(2,1,3), @@ -43,8 +43,39 @@ public void testCase() { Lists.newArrayList(3,1,2), Lists.newArrayList(3,2,1)); List> result = permute(nums); - Assert.assertEquals(excepted, result); + AssertUtils.compareListList(except, result, nums); + } + + public List> permute(int[] nums) { + if (nums == null || nums.length == 0) { + return new ArrayList<>(); + } + + List> ans = new ArrayList<>(); + process(nums, 0, ans); + return ans; + } + private void process(int[] nums, int index, List> ans) { + if (index == nums.length) { + List path = new ArrayList<>(); + for (int num : nums) { + path.add(num); + } + ans.add(path); + } else { + for (int i = index; i < nums.length; i++) { + swap(nums, i, index); + process(nums, index + 1, ans); + swap(nums, i, index); + } + } + } + + private void swap(int[] nums, int a, int b) { + int tmp = nums[a]; + nums[a] = nums[b]; + nums[b] = tmp; } /* @@ -69,7 +100,7 @@ def backtrack(路径,选择列表) { */ - public List> permute(int[] nums) { + public List> permute2(int[] nums) { List> result = new ArrayList<>(); Deque path = new LinkedList<>(); diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" index 55d5ab64..f98f6061 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import org.junit.Assert; +import common.util.AssertUtils; import org.junit.Test; import java.util.*; @@ -28,15 +28,13 @@ public class M047_全排列2 { @Test public void testCase() { - int[] nums = new int[]{1,1,2}; - List> excepted = Lists.newArrayList( - Lists.newArrayList(1,1,2), - Lists.newArrayList(1,2,1), - Lists.newArrayList(2,1,1)); + int[] nums = new int[]{1, 1, 2}; + List> except = Lists.newArrayList( + Lists.newArrayList(1, 1, 2), + Lists.newArrayList(1, 2, 1), + Lists.newArrayList(2, 1, 1)); List> result = permuteUnique(nums); - Assert.assertEquals(excepted, result); - - + AssertUtils.compareListList(except, result, nums); } public List> permuteUnique(int[] nums) { @@ -52,16 +50,17 @@ public List> permuteUnique(int[] nums) { private void process(int[] nums, int index, List> result) { if (index == nums.length) { List e = toArrayList(nums); - if (!result.contains(e)) { - result.add(e); + result.add(e); + } else { + HashSet set = new HashSet<>(); + for (int i = index; i < nums.length; i++) { + if (!set.contains(nums[i])) { + set.add(nums[i]); + swap(nums, i, index); + process(nums, index + 1, result); + swap(nums, i, index); + } } - return; - } - - for (int i = index; i < nums.length; i++) { - swap(nums, i, index); - process(nums, index + 1, result); - swap(nums, i, index); } } diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" new file mode 100644 index 00000000..d02fce61 --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" @@ -0,0 +1,91 @@ +package algorithm_practice.LeetCode.code200; + +import cn.hutool.core.lang.Assert; +import common.datastruct.ListNode; +import common.util.ConstructLinkedNode; +import org.junit.Test; + +/** + * 给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false 。 + * + * 输入:head = [1,2,2,1] + * 输出:true + * + * 输入:head = [1,2] + * 输出:false + * + * Created by nibnait on 2023/03/01 + */ +public class E234_回文链表 { + + @Test + public void test() { + int[] nums = new int[]{1,2,2,1}; + boolean result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(true, result); + + nums = new int[]{1}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(true, result); + + nums = new int[]{1, 2}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(false, result); + + nums = new int[]{1, 2, 1}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(true, result); + + nums = new int[]{1,1,0,0,1}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(false, result); + + } + + public boolean isPalindrome(ListNode head) { + if (head == null) { + return false; + } + + ListNode p1 = head; + ListNode p2 = head; + int count = 1; + while (p2.next != null && p2.next.next != null) { + ListNode cur = p1.next; + p2 = p2.next.next; + count++; + } + + ListNode reverseStart = p1; + if (count % 2 == 0) { + reverseStart = p1.next; + } + + // 翻转链表 + ListNode dummyHead = new ListNode(); + dummyHead.next = reverseStart; + + ListNode cur = reverseStart.next; + reverseStart.next = null; + while (cur != null) { + ListNode next = cur.next; + + cur.next = dummyHead.next; + dummyHead.next = cur; + + cur = next; + } + + // 一一对比 + dummyHead = dummyHead.next; + while (head != null && dummyHead != null) { + if (head.val != dummyHead.val) { + return false; + } + head = head.next; + dummyHead = dummyHead.next; + } + return true; + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" new file mode 100644 index 00000000..249082a6 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" @@ -0,0 +1,25 @@ +package cc.tianbin.java.并发.AQS源码阅读; + +import java.util.concurrent.locks.ReentrantLock; + +/** + * Created by nibnait on 2023/02/01 + */ +public class LockAndAqs { + + private static ReentrantLock lock = new ReentrantLock(); + + public static void main(String[] args) { + + + try { + lock.lock(); + } finally { + lock.unlock(); + } + + + + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" index eb4a9840..1c6f5bbc 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" @@ -1,4 +1,3 @@ - ## lock (sync.lock()) ```java diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" new file mode 100644 index 00000000..0c7469f2 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" @@ -0,0 +1,93 @@ +package cc.tianbin.java.并发.JUC.JUC_AQS.mylock; + +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.AbstractQueuedSynchronizer; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; + +/** + * Created by nibnait on 2023/02/01 + */ +public class MyLock implements Lock { + + protected static final String MY_LOCK_NAME = "myLock"; + + /** + * tryAcquire 加锁 + * tryRelease 解锁 + */ + private static class Sync extends AbstractQueuedSynchronizer { + + /** + * 加锁 + */ + protected boolean tryAcquire(int arg) { + if (!Thread.currentThread().getName().startsWith(MY_LOCK_NAME)) { + // 加锁失败 + return false; + } + + if (compareAndSetState(0, arg)) { + setExclusiveOwnerThread(Thread.currentThread()); + // 加锁成功 + return true; + } + + return false; + } + + /** + * 解锁 + */ + protected boolean tryRelease(int arg) { + if (getState() == 0) { + throw new IllegalMonitorStateException(); + } + setState(0); + + setExclusiveOwnerThread(null); + return true; + } + + protected Condition getCondition() { + return new ConditionObject(); + } + } + + // 内部类 + Sync sync = new Sync(); + + @Override + public void lock() { + sync.acquire(1); + } + + @Override + public boolean tryLock() { + return sync.tryAcquire(1); + } + + @Override + public boolean tryLock(long time, @NotNull TimeUnit unit) throws InterruptedException { + return sync.tryAcquireNanos(1, unit.toNanos(time)); + } + + @Override + public void lockInterruptibly() throws InterruptedException { + sync.acquireInterruptibly(1); + } + + @Override + public void unlock() { + sync.release(1); + } + + @NotNull + @Override + public Condition newCondition() { + return sync.getCondition(); + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" new file mode 100644 index 00000000..2f172d39 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" @@ -0,0 +1,55 @@ +package cc.tianbin.java.并发.JUC.JUC_AQS.mylock; + +import common.util.LogUtil; + +import static cc.tianbin.java.并发.JUC.JUC_AQS.mylock.MyLock.MY_LOCK_NAME; + +/** + * Created by nibnait on 2023/02/01 + */ +public class MyLockTest { + + private static MyLock lock = new MyLock(); + + /** + * 自定义一把锁 + * 设计一把自定义的锁你高要多久?需求如下: + * 1.排它锁,只有线程 name 以"myLock”开头的才能获取剑 + * 2.不支持重入,喜欢一次藏够了。 + * 3.支持尝试加锁 + * 4,支持超时尝试加锁 + * 5.支持可中衙加锁 + * 6.支wait notify功能 + * 7.其他不以“myLock”开头的线程名称,一律拒之门外。 + */ + public static void main(String[] args) { + + Thread t1 = new Thread(() -> { + testLock(); + }); + + Thread t2 = new Thread(() -> { + testLock(); + }); + + t1.setName(MY_LOCK_NAME); +// t1.setName("xx" + MY_LOCK_NAME); + t2.setName("xxx"); + + t1.start(); + t2.start(); + + } + + private static void testLock() { + lock.lock(); + + try { + LogUtil.log("{} 拿到了锁", Thread.currentThread().getName()); + } finally { + lock.unlock(); + } + } + + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" index e7361bcb..fa3086c1 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" @@ -16,6 +16,14 @@ public class 可见性 { private Number number = new Number(); private int loopCount = 100000; + private volatile Integer count = 0; + + @Test + public void testVolatile() { + count = count + 1; + System.out.println(count); + } + @Test public void test可见性() { diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" new file mode 100644 index 00000000..3f7d3068 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" @@ -0,0 +1,57 @@ +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; + +import lombok.SneakyThrows; +import org.junit.Test; + +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.Semaphore; + +/** + * 两个线程,依次打印奇数、偶数 + * Created by nibnait on 2023/02/01 + */ +public class OddEvenPrint { + + @Test + public void test2() { + + CyclicBarrier c = new CyclicBarrier(2); + + } + + @Test + public void test1() { + + Semaphore s1 = new Semaphore(1); + Semaphore s2 = new Semaphore(0); + + Thread oddThread = new Thread(new Runnable() { + @SneakyThrows + @Override + public void run() { + for (int i = 1; i <= 100; i += 2) { + s1.acquire(); + System.out.println(i); + s2.release(); + } + } + }); + + Thread evenThread = new Thread(new Runnable() { + @SneakyThrows + @Override + public void run() { + for (int i = 2; i <= 100; i += 2) { + s2.acquire(); + System.out.println(i); + s1.release(); + } + } + }); + + evenThread.start(); + oddThread.start(); + + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" index e3479cc0..9cab497a 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" @@ -9,7 +9,7 @@ public class aThreadJoinDemo { /** - * join():是Theard的方法,作用是调用线程需等待该join()线程执行完成后,才能继续用下运行。 + * join():是 Thread 的方法,作用是调用线程需等待该join()线程执行完成后,才能继续用下运行。 * * 应用场景:当一个线程必须等待另一个线程执行完毕才能执行时可以使用join方法。 */ diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" index 2e4c2624..f2a73d46 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" @@ -10,7 +10,7 @@ public class cThreadWaitNotifyDemo { /** - * wait():是Object的方法,作用是让当前线程进入等待状态,同时,wait()也会让当前线程释放它所持有的锁。“直到其他线程调用此对象的 notify() 方法或 notifyAll() 方法”,当前线程被唤醒(进入“就绪状态”) + * wait():是 Object 的方法,作用是让当前线程进入等待状态,同时,wait()也会让当前线程释放它所持有的锁。“直到其他线程调用此对象的 notify() 方法或 notifyAll() 方法”,当前线程被唤醒(进入“就绪状态”) *

* notify()和notifyAll():是Object的方法,作用则是唤醒当前对象上的等待线程;notify()是唤醒单个线程,而notifyAll()是唤醒所有的线程。 *

diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" index 888d1d8d..b95fe0da 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" @@ -13,7 +13,7 @@ public class dThreadAwaitSingalDemo { /** - * Condition(条件变量):通常与一个锁关联。需要在多个Contidion中共享一个锁时,可以传递一个Lock/RLock实例给构造方法,否则它将自己生成一个RLock实例。 + * Condition(条件变量):通常与一个锁关联。需要在多个Condition中共享一个锁时,可以传递一个Lock/RLock实例给构造方法,否则它将自己生成一个RLock实例。 * * Condition中await()方法类似于Object类中的wait()方法。 * diff --git "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" index 50b8d017..6b8be08b 100644 --- "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" @@ -29,163 +29,21 @@ public static void main(String[] args) { } @Test - public void test01() { - // ParameterizedType + public void hashMap() { + HashMap map = new HashMap(); - } + map.put(1, 1); + map.put(2, 2); -/* putVal - ** - * Implements Map.put and related methods. - * - * @param hash hash for key - * @param key the key - * @param value the value to put - * @param onlyIfAbsent if true, don't change existing value - * @param evict if false, the table is in creation mode. - * @return previous value, or null if none - * - final V putVal(int hash, K key, V value, boolean onlyIfAbsent, - boolean evict) { - HashMap.Node[] tab; HashMap.Node p; int n, i; - if ((tab = table) == null || (n = tab.length) == 0) - n = (tab = resize()).length; - if ((p = tab[i = (n - 1) & hash]) == null) - tab[i] = newNode(hash, key, value, null); - else { - HashMap.Node e; K k; - if (p.hash == hash && - ((k = p.key) == key || (key != null && key.equals(k)))) - e = p; - else if (p instanceof HashMap.TreeNode) - e = ((HashMap.TreeNode)p).putTreeVal(this, tab, hash, key, value); - else { - for (int binCount = 0; ; ++binCount) { - if ((e = p.next) == null) { - p.next = newNode(hash, key, value, null); - if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st - treeifyBin(tab, hash); - break; - } - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) - break; - p = e; - } - } - if (e != null) { // existing mapping for key - V oldValue = e.value; - if (!onlyIfAbsent || oldValue == null) - e.value = value; - afterNodeAccess(e); - return oldValue; - } - } - ++modCount; - if (++size > threshold) - resize(); - afterNodeInsertion(evict); - return null; - } + map.get(1); + map.remove(1); - //如果一个hashmap.里边有1g00个元素。 - //我们可以通过ut方法的返回值,进行一个是否有数值覆盖的判断、 - //如果有的业务逻辑从上层业务需求上,就可以肯定歌ey绝对是唯一的。那么这个时候,如果我们使跳ashmap - //进行数据的维护添加的话,好的代码需要使用到这个特性来保证我们的业务的伽y确实是唯一的 - //如果发现我们的put方法的返回值有值的话。擦,那说明业务伽y不唯一了,可以根据业务需求,直接抛出异常 - //通过代码,进行二次的校验。 + } - //这时候己经写入了。那么我想问下一下,我们的的返回值是什么? - //返回值是oldvalue。请问返回值丢失了吗? - //没有丢失啊,你可以再set回去啊,或者直接把这个事情当成了纯异常,再次从新oad数据 -*/ + @Test + public void concurrentHashMap() { + ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap(); -/* resize - ** - * Initializes or doubles table size. If null, allocates in - * accord with initial capacity target held in field threshold. - * Otherwise, because we are using power-of-two expansion, the - * elements from each bin must either stay at same index, or move - * with a power of two offset in the new table. - * - * @return the table - * - final HashMap.Node[] resize() { - // old 16 - HashMap.Node[] oldTab = table; - // 16 - int oldCap = (oldTab == null) ? 0 : oldTab.length; - // 12 - int oldThr = threshold; - int newCap, newThr = 0; - if (oldCap > 0) { - if (oldCap >= MAXIMUM_CAPACITY) { - // 放弃扩容 - threshold = Integer.MAX_VALUE; - return oldTab; - } - else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY && - oldCap >= DEFAULT_INITIAL_CAPACITY) - newThr = oldThr << 1; // double threshold - } - else if (oldThr > 0) // initial capacity was placed in threshold - newCap = oldThr; - else { // zero initial threshold signifies using defaults - newCap = DEFAULT_INITIAL_CAPACITY; - newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); - } - if (newThr == 0) { - float ft = (float)newCap * loadFactor; - newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? - (int)ft : Integer.MAX_VALUE); - } - threshold = newThr; - @SuppressWarnings({"rawtypes","unchecked"}) - HashMap.Node[] newTab = (HashMap.Node[])new HashMap.Node[newCap]; - table = newTab; - if (oldTab != null) { - for (int j = 0; j < oldCap; ++j) { - HashMap.Node e; - if ((e = oldTab[j]) != null) { - oldTab[j] = null; - if (e.next == null) - newTab[e.hash & (newCap - 1)] = e; - else if (e instanceof HashMap.TreeNode) - ((HashMap.TreeNode)e).split(this, newTab, j, oldCap); - else { // preserve order - HashMap.Node loHead = null, loTail = null; - HashMap.Node hiHead = null, hiTail = null; - HashMap.Node next; - do { - next = e.next; - if ((e.hash & oldCap) == 0) { - if (loTail == null) - loHead = e; - else - loTail.next = e; - loTail = e; - } - else { - if (hiTail == null) - hiHead = e; - else - hiTail.next = e; - hiTail = e; - } - } while ((e = next) != null); - if (loTail != null) { - loTail.next = null; - newTab[j] = loHead; - } - if (hiTail != null) { - hiTail.next = null; - newTab[j + oldCap] = hiHead; - } - } - } - } - } - return newTab; + concurrentHashMap.put(1, 1); } - */ } \ No newline at end of file diff --git a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java index 9a135fb4..8133043f 100644 --- a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java +++ b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java @@ -1,6 +1,5 @@ package cc.tianbin.java.mybatis; -import org.apache.ibatis.binding.MapperMethod; import org.junit.Test; /** From d7546a7eaa5bbb67f6d498af285ef44dc0d292a5 Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 1 Mar 2023 12:38:40 +0800 Subject: [PATCH 30/36] update --- .../P01_GetMinStack.java" | 2 +- ...\347\232\204\351\230\237\345\210\227.java" | 2 +- ...\344\270\200\344\270\252\346\240\210.java" | 6 +- ...\347\213\227\351\230\237\345\210\227.java" | 2 +- ...\347\232\204\346\216\222\345\272\217.java" | 6 +- ...\345\241\224\351\227\256\351\242\230.java" | 4 +- ...\345\200\274\346\225\260\347\273\204.java" | 4 +- ...\346\240\210\347\273\223\346\236\204.java" | 4 +- ...\347\232\204\345\244\247\345\260\217.java" | 4 +- ...\347\273\204\346\225\260\351\207\217.java" | 4 +- ...\345\257\271\346\225\260\351\207\217.java" | 4 +- ...\345\245\221\346\225\260\345\210\227.java" | 2 +- ...\350\267\257\345\276\204\345\222\214.java" | 2 +- ...\346\226\271\346\263\225\346\225\260.java" | 2 +- .../README.md | 0 ...\346\225\260\344\271\213\345\222\214.java" | 4 +- ...\345\205\245\344\275\215\347\275\256.java" | 2 +- ...\345\271\263\346\226\271\346\240\271.java" | 2 +- ...\345\244\215\345\205\203\347\264\240.java" | 8 +- ...\344\270\255\344\275\215\346\225\260.java" | 2 +- ...\346\216\245\351\233\250\346\260\264.java" | 2 +- .../H051_N\347\232\207\345\220\216.java" | 2 +- ...\345\205\245\345\214\272\351\227\264.java" | 2 +- ...\350\276\221\350\267\235\347\246\273.java" | 2 +- ...\347\232\204\347\237\251\345\275\242.java" | 2 +- ...\345\244\247\347\237\251\345\275\242.java" | 2 +- ...\346\225\260\347\233\270\345\212\240.java" | 8 +- ...\351\225\277\345\255\220\344\270\262.java" | 4 +- ...\346\226\207\345\255\220\344\270\262.java" | 2 +- ...\345\275\242\345\217\230\346\215\242.java" | 2 +- ...\347\232\204\345\256\271\345\231\250.java" | 2 +- ...\345\205\261\345\211\215\347\274\200.java" | 2 +- ...\346\225\260\344\271\213\345\222\214.java" | 4 +- ...\346\225\260\344\271\213\345\222\214.java" | 2 +- ...\346\257\215\347\273\204\345\220\210.java" | 4 +- ...\344\270\252\350\212\202\347\202\271.java" | 8 +- ...\347\232\204\350\212\202\347\202\271.java" | 8 +- ...\344\270\252\346\216\222\345\210\227.java" | 2 +- ...\345\272\217\346\225\260\347\273\204.java" | 4 +- ...\344\270\252\344\275\215\347\275\256.java" | 2 +- ...\345\220\210\346\200\273\345\222\214.java" | 2 +- ...345\220\210\346\200\273\345\222\2142.java" | 2 +- ...\344\270\262\347\233\270\344\271\230.java" | 4 +- ...\345\205\250\346\216\222\345\210\227.java" | 4 +- ...345\205\250\346\216\222\345\210\2272.java" | 4 +- ...\345\271\266\345\214\272\351\227\264.java" | 4 +- ...\344\270\252\346\216\222\345\210\227.java" | 4 +- ...\350\275\254\351\223\276\350\241\250.java" | 8 +- ...\345\220\214\350\267\257\345\276\204.java" | 2 +- ...345\220\214\350\267\257\345\276\2042.java" | 2 +- ...\345\214\226\350\267\257\345\276\204.java" | 2 +- ...\347\273\264\347\237\251\351\230\265.java" | 2 +- ...350\275\254\351\223\276\350\241\2502.java" | 10 +- ...45\216\237IP\345\234\260\345\235\200.java" | 2 +- ...\345\272\217\351\201\215\345\216\206.java" | 6 +- ...\347\232\204\346\225\260\351\207\217.java" | 2 +- ...\346\220\234\347\264\242\346\240\221.java" | 6 +- ...\344\272\214\345\217\211\346\240\221.java" | 6 +- ...\345\244\247\346\267\261\345\272\246.java" | 6 +- ...\344\272\214\345\217\211\346\240\221.java" | 6 +- ...\345\260\217\346\267\261\345\272\246.java" | 6 +- ...\344\275\263\346\227\266\346\234\272.java" | 2 +- ...344\275\263\346\227\266\346\234\2722.java" | 2 +- ...\345\256\266\345\212\253\350\210\215.java" | 2 +- ...344\275\263\346\227\266\346\234\2723.java" | 2 +- ...\350\267\257\345\276\204\345\222\214.java" | 6 +- ...\347\273\255\345\272\217\345\210\227.java" | 2 +- ...350\257\215\346\213\206\345\210\2062.java" | 2 +- ...\345\244\247\351\227\264\350\267\235.java" | 2 +- ...344\275\263\346\227\266\346\234\2724.java" | 2 +- ...\346\254\241\351\201\215\345\216\206.java" | 6 +- ...\350\257\215\346\216\245\351\276\231.java" | 2 +- ...\345\212\240\346\262\271\347\253\231.java" | 2 +- ...\350\257\215\346\213\206\345\210\206.java" | 2 +- ...\345\272\217\351\201\215\345\216\206.java" | 6 +- ...\345\272\217\351\201\215\345\216\206.java" | 6 +- ...\345\255\230\346\234\272\345\210\266.java" | 2 +- ...\345\205\245\346\216\222\345\272\217.java" | 10 +- ...\345\272\217\351\223\276\350\241\250.java" | 10 +- ...\347\232\204\345\215\225\350\257\215.java" | 2 +- ...\346\234\200\345\260\217\345\200\274.java" | 2 +- ...\345\217\263\350\247\206\345\233\276.java" | 6 +- ...\345\215\225\345\205\203\346\240\274.java" | 4 +- ...\345\205\254\345\233\240\345\255\220.java" | 2 +- ...\345\257\271\346\216\222\345\272\217.java" | 2 +- ...\345\206\231\345\215\225\350\257\215.java" | 2 +- ...\350\275\254\351\223\276\350\241\250.java" | 10 +- ...\344\272\214\345\217\211\346\240\221.java" | 8 +- ...\346\226\207\351\223\276\350\241\250.java" | 6 +- ...\347\232\204\347\273\223\347\202\271.java" | 8 +- ...\345\274\202\344\275\215\350\257\215.java" | 2 +- ...\347\247\273\345\212\250\351\233\266.java" | 4 +- ...\345\272\217\345\210\227\345\214\226.java" | 8 +- ...\350\257\276\347\250\213\350\241\250.java" | 2 +- ...350\257\276\347\250\213\350\241\2502.java" | 4 +- ...345\256\266\345\212\253\350\210\2152.java" | 2 +- ...\345\244\247\345\205\203\347\264\240.java" | 2 +- ...345\220\210\346\200\273\345\222\2143.java" | 2 +- ...\347\202\271\344\270\252\346\225\260.java" | 6 +- ...\347\232\204\344\270\252\346\225\260.java" | 2 +- ...\345\242\236\350\267\257\345\276\204.java" | 2 +- ...\345\255\220\345\272\217\345\210\227.java" | 2 +- ...\345\206\267\345\206\273\346\234\237.java" | 2 +- ...\351\222\261\345\205\221\346\215\242.java" | 2 +- ...\345\201\266\351\223\276\350\241\250.java" | 10 +- ...345\256\266\345\212\253\350\210\2153.java" | 6 +- ...\345\243\266\351\227\256\351\242\230.java" | 2 +- ...345\220\210\346\200\273\345\222\2144.java" | 2 +- ...\345\233\236\346\226\207\344\270\262.java" | 2 +- ...345\244\247\345\205\203\347\264\2401.java" | 2 +- .../H460_LFU\347\274\223\345\255\230.java" | 2 +- ...\344\275\215\346\225\260\345\255\227.java" | 2 +- ...\345\273\272\351\230\237\345\210\227.java" | 4 +- ...\345\222\214\345\255\220\351\233\206.java" | 2 +- ...\347\210\206\346\260\224\347\220\203.java" | 2 +- ...\344\270\200\345\222\214\351\233\266.java" | 2 +- ...\347\233\256\346\240\207\345\222\214.java" | 2 +- ...\347\224\261\344\271\213\350\267\257.java" | 2 +- ...345\244\247\345\205\203\347\264\2402.java" | 2 +- ...\345\255\220\345\272\217\345\210\227.java" | 2 +- ...351\222\261\345\205\221\346\215\2422.java" | 2 +- ...\346\234\213\345\217\213\345\234\210.java" | 2 +- ...\347\232\204\346\216\222\345\210\227.java" | 2 +- ...\345\242\236\345\272\217\345\210\227.java" | 2 +- ...\345\244\247\351\235\242\347\247\257.java" | 2 +- ...\345\210\206\346\237\245\346\211\276.java" | 2 +- ...\346\211\213\347\273\255\350\264\271.java" | 2 +- ...\345\275\242\351\207\215\345\217\240.java" | 2 +- ...\351\227\264\347\273\223\347\202\271.java" | 8 +- ...\350\233\213\346\216\211\350\220\275.java" | 2 +- ...\345\272\217\346\225\260\347\273\204.java" | 2 +- ...345\272\217\346\225\260\347\273\2042.java" | 2 +- ...345\220\214\350\267\257\345\276\2043.java" | 2 +- ...\345\272\217\346\225\260\347\273\204.java" | 2 +- ...\345\260\217\345\242\236\351\207\217.java" | 2 +- ...347\232\204K\344\270\252\347\202\271.java" | 4 +- ...60\345\215\226\351\227\256\351\242\230.md" | 0 ...14\345\214\205\351\227\256\351\242\230.md" | 0 .../tianbin}/algorithm_practice/README.md | 0 .../algorithm_practice/SwordOffer/README.md | 0 ...\344\276\213\346\250\241\345\274\217.java" | 2 +- ...\345\210\206\346\237\245\346\211\276.java" | 2 +- ...\346\215\242\347\251\272\346\240\274.java" | 2 +- ...\345\215\260\351\223\276\350\241\250.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 6 +- ...\347\216\260\351\230\237\345\210\227.java" | 2 +- ...\345\260\217\346\225\260\345\255\227.java" | 2 +- ...\345\245\221\346\225\260\345\210\227.java" | 2 +- ...\347\232\204\344\270\252\346\225\260.java" | 2 +- ...\346\225\260\346\254\241\346\226\271.java" | 2 +- ...347\232\204n\344\275\215\346\225\260.java" | 2 +- ...\350\241\250\347\273\223\347\202\271.java" | 8 +- ...\346\225\260\345\211\215\351\235\242.java" | 6 +- ...\344\270\252\347\273\223\347\202\271.java" | 4 +- ...\350\275\254\351\223\276\350\241\250.java" | 6 +- ...\347\232\204\351\223\276\350\241\250.java" | 6 +- ...\345\255\220\347\273\223\346\236\204.java" | 4 +- ...\347\232\204\351\225\234\345\203\217.java" | 6 +- ...\345\215\260\347\237\251\351\230\265.java" | 2 +- ...\346\225\260\347\232\204\346\240\210.java" | 2 +- ...\345\207\272\345\272\217\345\210\227.java" | 2 +- ...\344\272\214\345\217\211\346\240\221.java" | 4 +- ...\345\216\206\345\272\217\345\210\227.java" | 2 +- ...\347\232\204\350\267\257\345\276\204.java" | 4 +- ...\347\232\204\345\244\215\345\210\266.java" | 2 +- ...\345\220\221\351\223\276\350\241\250.java" | 8 +- ...\347\232\204\346\216\222\345\210\227.java" | 4 +- ...\347\232\204\347\273\204\345\220\210.java" | 2 +- ...\347\232\204\346\225\260\345\255\227.java" | 4 +- ...347\232\204k\344\270\252\346\225\260.java" | 8 +- ...\346\234\200\345\244\247\345\222\214.java" | 2 +- ...\347\232\204\346\254\241\346\225\260.java" | 2 +- ...\345\260\217\347\232\204\346\225\260.java" | 4 +- .../old/e34_\344\270\221\346\225\260.java" | 2 +- ...\347\232\204\345\255\227\347\254\246.java" | 2 +- ...\351\200\206\345\272\217\345\257\271.java" | 2 +- ...\345\205\261\347\273\223\347\202\271.java" | 4 +- ...\347\232\204\346\254\241\346\225\260.java" | 2 +- ...\347\232\204\346\267\261\345\272\246.java" | 4 +- ...\345\220\246\345\271\263\350\241\241.java" | 6 +- ...\347\232\204\346\225\260\345\255\227.java" | 2 +- ...\344\270\252\346\225\260\345\255\227.java" | 4 +- ...\346\225\260\345\272\217\345\210\227.java" | 2 +- ...\350\257\215\351\241\272\345\272\217.java" | 2 +- ...\345\255\227\347\254\246\344\270\262.java" | 4 +- ...\347\232\204\347\202\271\346\225\260.java" | 2 +- ...\347\232\204\351\241\272\345\255\220.java" | 2 +- ...\347\216\257\346\235\200\344\272\272.java" | 2 +- ...345\210\260n\347\232\204\345\222\214.java" | 2 +- ...\345\201\232\345\212\240\346\263\225.java" | 2 +- ...\346\211\277\347\232\204\347\261\273.java" | 2 +- ...\346\210\220\346\225\264\346\225\260.java" | 2 +- ...\345\205\261\347\245\226\345\205\210.java" | 2 +- ...\347\232\204\346\225\260\345\255\227.java" | 4 +- ...\347\247\257\346\225\260\347\273\204.java" | 2 +- ...\345\274\217\345\214\271\351\205\215.java" | 2 +- ...\345\255\227\347\254\246\344\270\262.java" | 2 +- ...\347\232\204\345\255\227\347\254\246.java" | 2 +- ...\345\217\243\347\273\223\347\202\271.java" | 4 +- ...\347\232\204\347\273\223\347\202\271.java" | 6 +- ...\344\270\252\347\273\223\347\202\271.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 4 +- ...\346\210\220\345\244\232\350\241\214.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 4 +- ...\344\272\214\345\217\211\346\240\221.java" | 6 +- ...\344\270\252\347\273\223\347\202\271.java" | 6 +- ...\344\270\255\344\275\215\346\225\260.java" | 2 +- ...\346\234\200\345\244\247\345\200\274.java" | 4 +- ...\347\232\204\350\267\257\345\276\204.java" | 2 +- ...\345\212\250\350\214\203\345\233\264.java" | 2 +- .../\346\240\221/MorrisTraversal.java" | 8 +- ...\344\272\214\345\217\211\346\240\221.java" | 6 +- ...\344\272\214\345\217\211\346\240\221.java" | 6 +- .../algorithm_practice/a_Sorting/README.md | 0 .../a_Sorting/a_Bubble.java | 4 +- .../a_Sorting/a_Selection.java | 8 +- .../a_Sorting/b_Insertion.java | 8 +- .../algorithm_practice/a_Sorting/c_Shell.java | 6 +- .../algorithm_practice/a_Sorting/d_Merge.java | 6 +- .../algorithm_practice/a_Sorting/e_Quick.java | 6 +- .../algorithm_practice/a_Sorting/f_Heap.java | 6 +- ...\346\225\260\346\216\222\345\272\217.java" | 2 +- ...\346\241\266\346\216\222\345\272\217.java" | 2 +- .../SlidingWindowMaxValue.java | 4 +- .../AlgorithmPrototype/SubArrayMaxSum.java | 2 +- .../aa_Manacher_bfprt_KMP/KMP.java | 2 +- .../KMP\347\256\227\346\263\225.md" | 0 .../aa_Manacher_bfprt_KMP/Manacher.java | 2 +- .../Manacher\347\256\227\346\263\225.md" | 0 .../aa_Manacher_bfprt_KMP/README.md | 0 .../nowcoder/b_2nd_Season/ba160720/README.md | 0 .../ba160720/RussianDollEnvelopes.java | 2 +- .../ba160720/TrappingRainWater.java | 2 +- .../nowcoder/b_2nd_Season/ba160720/arrUp.java | 2 +- .../nowcoder/b_2nd_Season/bb160727/README.md | 0 .../bb160727/a_SubArrayMaxSum.java | 2 +- .../bb160727/b_TwoSubArrayMaxSum.java | 2 +- .../b_2nd_Season/bb160727/c_MaxLength.java | 4 +- .../nowcoder/b_2nd_Season/bc160803/README.md | 0 .../bc160803/src/CompleteTreeNodeNumber.java | 2 +- .../src/LongestLessSumSubArrayLength.java | 4 +- .../bc160803/src/MaxSubMatrixSumLessK.java | 4 +- .../bc160803/src/MaximalRectangle.java | 2 +- .../bc160803/src/PrefixCheck.java | 2 +- .../bc160803/src/SubArrayMaxSum.java | 2 +- .../bc160803/src/SubMatrixMaxSum.java | 2 +- .../nowcoder/b_2nd_Season/bd160810/README.md | 0 .../bd160810}/SlidingWindowMaxValue.java | 4 +- .../bd160810/src/ExpressionCompute.java | 2 +- .../bd160810/src/GetMinStack.java | 2 +- .../src/ReverseStackUsingRecursive.java | 2 +- .../bd160810/src/SlidingWindowMaxArray.java | 2 +- .../bd160810/src/TwoQueuesImplementStack.java | 2 +- .../bd160810/src/TwoStacksImplementQueue.java | 2 +- .../nowcoder/b_2nd_Season/be160817/README.md | 0 .../be160817/src/AllLessNumSubArray.java | 2 +- .../b_2nd_Season/be160817/src/DogCat.java | 2 +- .../b_2nd_Season/be160817/src/Hanoi.java | 2 +- .../b_2nd_Season/be160817/src/MaxTree.java | 2 +- .../nowcoder/b_2nd_Season/bf160824/README.md | 0 .../bf160824/src/CopyListWithRandom.java | 2 +- .../bf160824/src/FindFirstIntersectNode.java | 2 +- .../bf160824/src/IsPalindromeList.java | 2 +- .../b_2nd_Season/bf160824/src/Josephus.java | 2 +- .../bf160824/src/RemoveNodeWired.java | 2 +- .../nowcoder/b_2nd_Season/bg160831/README.md | 0 .../bg160831/src/BSTtoDoubleLinkedList.java | 2 +- .../bg160831/src/KMPAlgorithm.java | 2 +- ...LongestSubarrayLessSumAwesomeSolution.java | 4 +- .../bh160907/BiggestSubBSTInTree.java | 6 +- .../bh160907/PreInPosTraversal.java | 6 +- .../nowcoder/b_2nd_Season/bh160907/README.md | 0 .../src/Problem_01_PreInPosTraversal.java | 2 +- .../src/Problem_03_PrintBinaryTree.java | 2 +- .../src/Problem_06_LongestPathSum.java | 2 +- .../src/Problem_07_BiggestSubBSTInTree.java | 2 +- .../src/Problem_20_MaxDistanceInTree.java | 2 +- .../bi160914/BiggestBSTTopologyInTree.java | 6 +- .../bi160914/MorrisTraversal.java | 6 +- .../nowcoder/b_2nd_Season/bi160914/README.md | 0 .../src/Problem_05_MorrisTraversal.java | 2 +- .../Problem_08_BiggestBSTTopologyInTree.java | 2 +- .../src/Problem_17_DescendantNode.java | 2 +- .../bj160928/IsBalancedBinaryTree.java | 4 +- .../bj160928/IsCompleteBinaryTree.java | 4 +- .../bj160928/IsSearchBinaryTree.java | 4 +- .../nowcoder/b_2nd_Season/bj160928/README.md | 0 .../b_2nd_Season/bj160928/RecoverBST.java | 4 +- ...em_09_PrintBinaryTreeByLevelAndZigZag.java | 2 +- .../bj160928/src/Problem_10_RecoverBST.java | 2 +- .../src/Problem_13_IsBalancedTree.java | 2 +- .../bj160928/src/Problem_15_IsBSTAndCBT.java | 2 +- .../b_2nd_Season/bj160928/testRecoverBST.java | 10 +- .../nowcoder/b_2nd_Season/bk161012/README.md | 0 .../nowcoder/book/BinaryTree/getPosArray.java | 4 +- .../nowcoder/image/KMP-1.png | Bin .../Manacher\347\256\227\346\263\225-1.png" | Bin .../Manacher\347\256\227\346\263\225-2.png" | Bin .../nowcoder/image/nowcoderbb16072701.png | Bin .../nowcoder/image/nowcoderbb16072702.png | Bin .../nowcoder/image/nowcoderbc16080301.png | Bin .../nowcoder/image/nowcoderbc16080302.png | Bin .../nowcoder/image/nowcoderbc16080303.png | Bin .../nowcoder/image/nowcoderbd16081001.png | Bin .../nowcoder/image/nowcoderbf16082401.png | Bin .../nowcoder/image/nowcoderbf16082402.png | Bin .../nowcoder/image/nowcoderbi16091401.png | Bin .../nowcoder/image/nowcoderbj16092801.png | Bin .../nowcoder/image/nowcoderbj16092802.png | Bin .../nowcoder/image/nowcoderbk16101201.png | Bin .../nowcoder/image/nowcoderbk16101202.png | Bin .../nowcoder/image/nowcoderbk16101203.png | Bin .../nowcoder/image/nowcoderbk16101204.png | Bin .../tianbin}/common/CommonConstants.java | 2 +- .../context/ApplicationContextHelper.java | 2 +- .../common/datastruct/BinarySearch.java | 2 +- .../common/datastruct/BinaryTreeNode.java | 2 +- .../datastruct/BinaryTreeNodeWithParent.java | 2 +- .../tianbin}/common/datastruct/ListNode.java | 2 +- .../tianbin}/common/datastruct/Node.java | 2 +- .../tianbin}/common/datastruct/TreeNode.java | 2 +- .../tianbin}/common/enums/ErrorCode.java | 2 +- .../{ => cc/tianbin}/common/model/Person.java | 2 +- .../tianbin}/common/model/PersonDTO.java | 2 +- .../tianbin}/common/util/AssertUtils.java | 11 +- .../tianbin}/common/util/CommonBeanUtil.java | 2 +- .../tianbin}/common/util/CompareUtils.java | 6 +- .../common/util/ConstructLinkedNode.java | 4 +- .../tianbin}/common/util/CopyUtil.java | 2 +- .../tianbin}/common/util/DownloadUtil.java | 2 +- .../tianbin}/common/util/GenerateUUID.java | 2 +- .../{ => cc/tianbin}/common/util/LogUtil.java | 2 +- .../{ => cc/tianbin}/common/util/README.md | 0 .../tianbin}/common/util/StandardInit.java | 2 +- .../tianbin}/common/util/SwapUtil.java | 2 +- .../{ => cc/tianbin}/common/util/SysOut.java | 6 +- .../tianbin}/common/util/SysRandom.java | 2 +- .../tianbin}/common/util/SystemUtil.java | 2 +- .../common/util/batchInsert/NameUtil.java | 2 +- .../common/util/batchInsert/RandomValue.java | 2 +- .../util/binaryTree/ConstructBinaryTree.java | 4 +- .../util/binaryTree/PrintBinaryTree.java | 8 +- .../SerializeAndReConstructTree.java | 4 +- .../SerializeAndReConstructTreeImpl.java | 12 +- .../SerializeAndReConstructTreeUtils.java | 6 +- .../common/util/validate/FluentValidator.java | 12 +- .../common/util/validate/Validator.java | 4 +- .../validate/context/ValidateContext.java | 2 +- .../context/ValidateContextAttrKey.java | 2 +- .../validate/context/ValidateElement.java | 2 +- .../util/validate/context/ValidateResult.java | 2 +- .../validate/validator/OperatorValidator.java | 8 +- .../{ => cc/tianbin}/data_struct/Node.java | 2 +- .../{ => cc/tianbin}/data_struct/README.md | 0 .../data_struct/ds1_\345\240\206/Heap.java" | 8 +- .../ds1_\345\240\206/HeapGreater.java" | 10 +- .../data_struct/ds1_\345\240\206/MyHeap.java" | 2 +- .../BinarySearchTree.java" | 2 +- .../BinarySearchTreeImpl.java" | 2 +- .../BinarySearchTreeNode.java" | 2 +- .../BinarySearchTreeTest.java" | 4 +- .../AVLNode.java" | 4 +- .../AVLTree.java" | 2 +- .../AVLTreeImpl.java" | 2 +- .../AVLTreeTest.java" | 2 +- .../RedBlackNode.java" | 2 +- .../RedBlackTree.java" | 2 +- .../RedBlackTreeImpl.java" | 2 +- .../RedBlackTreeTest.java" | 2 +- .../MyUnionFind.java" | 2 +- .../UnionFind.java" | 4 +- .../data_struct/ds4_\345\233\276/Edge.java" | 2 +- .../data_struct/ds4_\345\233\276/Graph.java" | 2 +- .../ds4_\345\233\276/GraphGenerator.java" | 2 +- .../data_struct/ds4_\345\233\276/Node.java" | 2 +- .../ds4_\345\233\276/adjoin_map/BFS.java" | 4 +- .../ds4_\345\233\276/adjoin_map/DFS.java" | 4 +- .../ds4_\345\233\276/adjoin_map/Graph.java" | 2 +- .../{ => demo}/hessian/HessianDemo.java | 2 +- .../cc/tianbin/{ => demo}/hessian/README.md | 0 .../Main.java" | 2 +- .../Student.java" | 2 +- .../java/cc/tianbin/{ => demo}/java/IO/1.txt | 0 .../{ => demo}/java/IO/FileReaderTest.java | 2 +- .../{ => demo}/java/IO/classpath/Main.java | 4 +- .../IO/classpath/ResourcesReaderUtil.java | 2 +- .../java/IO/classpath/RpcConfig.java | 2 +- .../tianbin/{ => demo}/java/proxy/README.md | 0 .../{ => demo}/java/proxy/cglib/Main.java | 2 +- .../{ => demo}/java/proxy/cglib/Person.java | 2 +- .../java/proxy/cglib/TargetInterceptor.java | 2 +- .../cglib/TargetMethodCallbackFilter.java | 2 +- .../java/proxy/cglib/TargetResultFixed.java | 2 +- .../lazyloader/ConcreteClassDispatcher.java | 4 +- .../lazyloader/ConcreteClassLazyLoader.java | 4 +- .../java/proxy/cglib/lazyloader/LazyBean.java | 2 +- .../proxy/cglib/lazyloader/PropertyBean.java | 2 +- .../{ => demo}/java/proxy/jdk/Calculator.java | 2 +- .../java/proxy/jdk/CalculatorImpl.java | 2 +- .../java/proxy/jdk/HelloService.java | 2 +- .../java/proxy/jdk/HelloServiceImpl.java | 2 +- .../DynamicProxy.java" | 8 +- .../Main.java" | 8 +- .../handler/LogHandler.java" | 2 +- .../handler/MyInvocationHandler.java" | 2 +- .../HelloServiceProxy.java" | 4 +- .../Main.java" | 4 +- .../CompareUtil.java" | 2 +- .../java/\345\217\215\345\260\204/Main.java" | 4 +- .../BigDecimalTest.java" | 2 +- .../BooleanTest.java" | 2 +- .../ByteTest.java" | 2 +- .../DoubleTest.java" | 2 +- .../IntegerTest.java" | 2 +- .../MathTest.java" | 2 +- .../StringTest.java" | 2 +- .../LockAndAqs.java" | 2 +- ...1_\345\205\254\345\271\263\351\224\201.md" | 0 ...36\345\205\254\345\271\263\351\224\201.md" | 0 ...36\345\205\254\345\271\263\351\224\201.md" | 0 .../JUC/JUC_AQS/CountdownLatchExample.java" | 2 +- .../JUC/JUC_AQS/CyclicBarrierExample.java" | 2 +- .../JUC/JUC_AQS/README.md" | 0 .../JUC/JUC_AQS/SemaphoreExample.java" | 2 +- .../JUC/JUC_AQS/mylock/MyLock.java" | 2 +- .../JUC/JUC_AQS/mylock/MyLockTest.java" | 6 +- .../JUC/JUC_demo/BlockedQueue.java" | 2 +- .../JUC/JUC_demo/Cache.java" | 2 +- .../JUC/JUC_demo/DisruptorDemo.java" | 2 +- .../JUC/JUC_demo/ObjectPool.java" | 2 +- .../JUC/JUC_demo/Point.java" | 2 +- .../JUC/JUC_other/ForkJoinExample.java" | 2 +- .../JUC/JUC_other/FutureTaskExample.java" | 2 +- .../JUC/JUC_other/Main.java" | 2 +- .../JUC/JUC_other/ProducerConsumer.java" | 2 +- .../JUC/JUC_other/README.md" | 0 ...\345\217\257\350\247\201\346\200\247.java" | 2 +- .../java/\345\271\266\345\217\221/Main.java" | 2 +- .../java/\345\271\266\345\217\221/README.md" | 0 .../thread_demo/README.md" | 0 .../threadpool/ExecutorsExceptionTest.java" | 2 +- ...\347\250\213\345\220\214\346\255\245.java" | 2 +- .../threadpool/a1_MyThreadPool.java" | 2 +- .../threadpool/a2_FutureTask.java" | 2 +- .../threadpool/b1_FutureTaskDemo.java" | 2 +- .../threadpool/b2_CompletableFutureDemo.java" | 5 +- .../b2_CompletableFutureDemo2.java" | 4 +- .../threadpool/b3_CompletionServiceDemo.java" | 4 +- .../threadpool/c1_FockJoinDemo.java" | 2 +- .../threadpool/c2_FockJoinDemo2.java" | 2 +- .../OddEvenPrint.java" | 2 +- .../aThreadJoinDemo.java" | 2 +- .../bThreadMainJoinDemo.java" | 2 +- .../cThreadWaitNotifyDemo.java" | 2 +- .../dThreadAwaitSingalDemo.java" | 2 +- .../eSingleThreadPoolDemo.java" | 2 +- .../fCountDownLatchDemo.java" | 2 +- .../gCyclicBarrierDemo.java" | 2 +- .../CAS/AtomicIntegerExample.java" | 2 +- .../CAS/AtomicReferenceExample.java" | 4 +- .../README.md" | 0 .../reentrantLock/LockExample.java" | 2 +- .../reentrantLock/Main.java" | 2 +- .../AwaitSignalExample.java" | 2 +- .../JoinExample.java" | 2 +- .../Main.java" | 2 +- .../README.md" | 0 .../WaitNotifyExample.java" | 2 +- .../synchronize/Main.java" | 2 +- .../synchronize/SynchronizedExample.java" | 2 +- .../java/\345\274\202\345\270\270/Main.java" | 2 +- .../List\347\261\273.java" | 2 +- .../Map\347\261\273.java" | 2 +- .../Set\347\261\273.java" | 2 +- .../{ => demo}/jvm/GCRoots/GCRootsTest01.java | 2 +- .../{ => demo}/jvm/GCRoots/GCRootsTest02.java | 2 +- .../{ => demo}/jvm/GCRoots/GCRootsTest03.java | 2 +- .../{ => demo}/jvm/GCRoots/GCRootsTest04.java | 2 +- .../tianbin/{ => demo}/jvm/GCRoots/README.md | 0 .../GC\344\274\230\345\214\226/HeapOOM.java" | 2 +- .../jvm/classloader/ClassLoaderDemo.java | 2 +- .../jvm/classloader/LoadStringDemo.java | 2 +- .../LoadDemo.java" | 2 +- .../Main.java" | 2 +- .../MyClassLoader.java" | 2 +- .../\345\274\225\347\224\250/Reference.java" | 2 +- .../cc/tianbin/{ => demo}/netty/Main.java | 2 +- .../cc/tianbin/{ => demo}/netty/README.md | 0 .../cc/tianbin/{ => demo}/netty/http/App.java | 2 +- .../{ => demo}/netty/http/HttpServer.java | 2 +- .../{ => demo}/netty/http/ServerHandler.java | 2 +- .../netty/http/ServerInitializer.java | 2 +- .../{ => demo}/netty/rpc/ClientApp.java | 10 +- .../{ => demo}/netty/rpc/ServerApp.java | 10 +- .../netty/rpc/client/RPCClient.java | 8 +- .../rpc/client/request/RPCException.java | 2 +- .../netty/rpc/client/request/RPCRequest.java | 2 +- .../netty/rpc/client/request/RPCResponse.java | 2 +- .../netty/rpc/client/request/RequestId.java | 2 +- .../rpc/client/request/ResponseRegistry.java | 2 +- .../netty/rpc/customHandler/ExpRequest.java | 2 +- .../rpc/customHandler/ExpRequestHandler.java | 6 +- .../netty/rpc/customHandler/ExpResponse.java | 2 +- .../rpc/customHandler/FibRequestHandler.java | 6 +- .../netty/rpc/server/RPCServer.java | 8 +- .../netty/rpc/server/ServerHandler.java | 10 +- .../rpc/server/message/DefaultHandler.java | 2 +- .../rpc/server/message/IMessageHandler.java | 2 +- .../rpc/server/message/MessageHandlers.java | 2 +- .../rpc/server/message/MessageInput.java | 2 +- .../rpc/server/message/MessageOutput.java | 2 +- .../rpc/server/message/MessageRegistry.java | 2 +- .../netty/webSocket/client/ClientApp.java | 2 +- .../netty/webSocket/client/ClientHandler.java | 2 +- .../webSocket/client/ClientInitializer.java | 2 +- .../netty/webSocket/client/SocketClient.java | 2 +- .../netty/webSocket/server/ServerApp.java | 2 +- .../netty/webSocket/server/ServerHandler.java | 2 +- .../webSocket/server/ServerInitializer.java | 2 +- .../netty/webSocket/server/SocketServer.java | 2 +- .../HyperLogLog/HyperLogLogCounting.java | 2 +- .../HyperLogLog/HyperLogLogCountingDemo.java | 2 +- .../{ => demo}/redis/RateLimiter/README.md | 0 .../redis/RateLimiter/RedisRateLimiter.java | 4 +- .../test/{ => cc/tianbin}/UnitTestDemo.java | 8 +- .../tianbin}/algorithm_practice/TempTest.java | 4 +- ...\345\210\206\346\237\245\346\211\276.java" | 0 ...\345\240\206\346\216\222\345\272\217.java" | 2 +- ...\351\200\237\346\216\222\345\272\217.java" | 4 +- .../{ => cc/tianbin}/algorithmzuo/README.md | 0 .../README.md" | 0 .../Code01_SelectionSort.java" | 10 +- .../Code02_BubbleSort.java" | 10 +- .../Code03_InsertionSort.java" | 10 +- .../Code04_1_MergeSort_Recursion.java" | 8 +- .../Code04_2_MergeSort_Non_Recursion.java" | 8 +- .../Code04_3_SmallSum.java" | 6 +- .../Code04_4_ReversePair.java" | 6 +- .../Code04_5_BiggerThanRightTwice.java" | 6 +- .../Code04_6_CountOfRangeSum.java" | 2 +- .../Code05_1_PartitionAndQuickSort.java" | 10 +- ...5_2_QuickSortRecursionAndUnrecursion.java" | 10 +- .../Code06_1_HeapSort.java" | 10 +- .../Code06_2_SortArrayDistanceLessK.java" | 8 +- .../Code06_3_CoverMax.java" | 4 +- .../Code07_CountSort.java" | 8 +- .../Code08_RadixSort.java" | 8 +- .../Code01_BSExist.java" | 8 +- .../Code02_BSNearLeft.java" | 8 +- .../Code03_BSNearRight.java" | 8 +- .../Code04_BSAwesome.java" | 2 +- .../Code01_Swap.java" | 2 +- .../Code02_EvenTimesOddTimes.java" | 4 +- .../Code03_KM.java" | 10 +- ...ode03_DoubleEndsQueueToStackAndQueue.java" | 4 +- .../Code04_RingArray.java" | 2 +- .../Code05_GetMinStack.java" | 2 +- .../Code06_TwoStacksImplementQueue.java" | 2 +- .../Code07_TwoQueueImplementStack.java" | 2 +- ...00\347\232\204\347\256\227\346\263\225.md" | 0 .../Code01_1_ReverseListNode.java" | 12 +- .../Code01_2_ReverseDoubleListNode.java" | 12 +- .../Code02_DeleteGivenValue.java" | 10 +- .../Code03_LinkedListMid.java" | 4 +- .../Code04_IsPalindromeList.java" | 4 +- .../Code05_SmallerEqualBigger.java" | 4 +- .../Code06_CopyListWithRandom.java" | 2 +- .../Code07_FindFirstIntersectListNode.java" | 6 +- .../Code01_TrieTree.java" | 2 +- .../Code01_RecursiveTraversalBT.java" | 6 +- .../Code02_UnRecursiveTraversalBT.java" | 6 +- .../Code03_LevelTraversalBT.java" | 6 +- .../Code05_EncodeNaryTreeToBinaryTree.java" | 2 +- .../Code06_TreeMaxWidth.java" | 14 +-- .../Code01_IsBalanced.java" | 10 +- .../Code02_IsBST.java" | 10 +- .../Code03_MaxDistance.java" | 11 +- .../Code04_IsFull.java" | 16 +-- .../Code05_MaxSubBSTSize.java" | 14 +-- .../Code06_IsCBT.java" | 10 +- .../Code07_MaxSubBSTHead.java" | 14 +-- .../Code08_lowestAncestor.java" | 16 +-- .../Code09_MaxHappy.java" | 6 +- ...76\350\241\250\345\222\214\346\240\221.md" | 0 .../Code01_Light.java" | 6 +- .../Code02_LessMoneySplitGold.java" | 6 +- .../Code03_BestArrange.java" | 6 +- .../Code04_IPO.java" | 2 +- ...52\345\277\203\347\256\227\346\263\225.md" | 0 .../Code01_FriendCircles.java" | 2 +- .../Code02_NumberOfIslands.java" | 6 +- .../Code03_NumberOfIslandsII.java" | 2 +- ...x_\345\271\266\346\237\245\351\233\206.md" | 0 .../c0500_\345\233\276.md" | 0 .../c0500_\345\233\276/Code01_BFS.java" | 4 +- .../c0500_\345\233\276/Code02_DFS.java" | 4 +- .../Code03_1_TopologySort.java" | 6 +- .../Code03_2_TopologicalOrderBFS.java" | 2 +- .../Code03_3_TopologicalOrderDFS.java" | 2 +- .../c0500_\345\233\276/Code04_Kruskal.java" | 8 +- .../c0500_\345\233\276/Code05_Prim.java" | 8 +- .../Code06_1_Dijkstra.java" | 6 +- .../Code06_2_Dijkstra.java" | 6 +- .../Code07_NetworkDelayTime.java" | 2 +- ...01\347\232\204\351\200\222\345\275\222.md" | 0 .../Code01_Hanoi.java" | 8 +- .../Code02_PrintAllSubSequences.java" | 4 +- .../Code03_PrintAllPermutations.java" | 6 +- .../Code04_ReverseStackUsingRecursive.java" | 2 +- ...50\346\200\201\350\247\204\345\210\222.md" | 0 .../Code01_RobotWalk.java" | 2 +- .../Code02_CardsInLine.java" | 8 +- .../Code03_Knapsack.java" | 2 +- .../Code04_ConvertToLetterString.java" | 8 +- .../Code05_StickersToSpellWord.java" | 4 +- .../Code06_LongestCommonSubsequence.java" | 2 +- .../Code07_PalindromeSubsequence.java" | 4 +- .../Code08_HorseJump.java" | 4 +- .../Code09_Coffee.java" | 8 +- .../Code10_MinPathSum.java" | 6 +- .../Code11_CoinsWayEveryPaperDifferent.java" | 8 +- .../Code12_CoinsWayNoLimit.java" | 8 +- .../Code13_CoinsWaySameValueSamePapper.java" | 8 +- .../Code14_MinCoinsNoLimit.java" | 8 +- .../Code15_BobDie.java" | 4 +- .../Code16_KillMonster.java" | 8 +- .../Code17_SplitNumber.java" | 6 +- .../Code18_SplitSumClosed.java" | 8 +- .../Code19_SplitSumClosedSizeHalf.java" | 8 +- .../Code20_NQueens.java" | 2 +- .../README.md" | 0 .../common/util/DateTimeUtilTest.java | 0 .../common/util/ExcelReadUtilsTest.java | 0 .../util/validate/FluentValidatorTest.java | 0 src/main/test/cc/tianbin/{ => demo}/Main.java | 0 .../test/cc/tianbin/demo/java/ObjectTest.java | 19 ++++ .../tianbin/{ => demo}/java/OptionalTest.java | 2 +- .../{ => demo}/java/SwitchCaseTest.java | 2 +- .../{ => demo}/java/spring/SpringTest.java | 2 +- .../CommonBeanUtilTest.java" | 8 +- ...\350\203\275\346\265\213\350\257\225.java" | 8 +- .../java/\345\217\215\345\260\204/README.md" | 0 .../ReflectTest.java" | 2 +- .../ListStreamTest.java" | 4 +- .../\351\233\206\345\220\210/ListTest.java" | 4 +- .../\351\233\206\345\220\210/MapTest.java" | 4 +- .../\351\233\206\345\220\210/SetTest.java" | 2 +- .../RateLimiter/RedisRateLimiterTest.java | 91 ++++++++++++++++ .../cc/tianbin/demo/temp/JsonParseTest.java | 29 +++++ src/main/test/cc/tianbin/excel/ExcelGen.java | 65 ----------- src/main/test/cc/tianbin/excel/ParseJson.java | 30 ----- src/main/test/cc/tianbin/excel/StockDTO.java | 80 -------------- src/main/test/cc/tianbin/java/ObjectTest.java | 19 ---- .../tianbin}/java/lang/test/String.class | Bin .../tianbin}/java/lang/test/String_.java | 0 .../cc/tianbin/java/mybatis/MybatisTest.java | 13 --- .../tianbin}/javalang/test/FinallyTest.java | 2 +- .../tianbin}/javalang/test/IfTest.java | 2 +- .../RateLimiter/RedisRateLimiterTest.java | 103 ------------------ src/main/test/cc/tianbin/temp/DataGen.java | 24 ---- .../test/cc/tianbin/temp/JsonParseTest.java | 35 ------ .../{ => cc/tianbin}/tmp/interview/Main.java | 2 +- 662 files changed, 1208 insertions(+), 1439 deletions(-) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" (87%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" (93%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" (87%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" (95%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" (92%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" (98%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" (95%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" (96%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" (95%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" (95%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" (97%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" (89%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" (96%) rename "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" (94%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/Coding_Interview_Guide_2ndEdition/README.md (100%) rename "src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" (95%) rename "src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" (91%) rename "src/main/java/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" (91%) rename "src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" (91%) rename "src/main/java/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" (92%) rename "src/main/java/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" (92%) rename "src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" (91%) rename "src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" (94%) rename "src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" (91%) rename "src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" (92%) rename "src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" (94%) rename "src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" (92%) rename "src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" (92%) rename "src/main/java/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" (94%) rename "src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" (90%) rename "src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" (94%) rename "src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" (93%) rename "src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" (90%) rename "src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" (95%) rename "src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" (94%) rename "src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" (95%) rename "src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" (89%) rename "src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" (95%) rename "src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" (94%) rename "src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" (99%) rename "src/main/java/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" (90%) rename "src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" (95%) rename "src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" (98%) rename "src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" (92%) rename "src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" (96%) rename "src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" (97%) rename "src/main/java/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\202\241\347\245\250\344\271\260\345\215\226\351\227\256\351\242\230.md" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\202\241\347\245\250\344\271\260\345\215\226\351\227\256\351\242\230.md" (100%) rename "src/main/java/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\203\214\345\214\205\351\227\256\351\242\230.md" => "src/main/java/cc/tianbin/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\203\214\345\214\205\351\227\256\351\242\230.md" (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/SwordOffer/README.md (100%) rename "src/main/java/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" (93%) rename "src/main/java/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" (94%) rename "src/main/java/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" (94%) rename "src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" (94%) rename "src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" (92%) rename "src/main/java/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" (84%) rename "src/main/java/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" (94%) rename "src/main/java/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" (91%) rename "src/main/java/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" (99%) rename "src/main/java/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" (99%) rename "src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" (97%) rename "src/main/java/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" (94%) rename "src/main/java/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" (99%) rename "src/main/java/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" (99%) rename "src/main/java/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" (98%) rename "src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" (95%) rename "src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" (96%) rename "src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" => "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/a_Bubble.java (91%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/a_Selection.java (84%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/b_Insertion.java (78%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/c_Shell.java (89%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/d_Merge.java (90%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/e_Quick.java (91%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/a_Sorting/f_Heap.java (92%) rename "src/main/java/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" => "src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" (98%) rename "src/main/java/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" => "src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" (96%) rename src/main/java/{algorithm_practice/nowcoder/b_2nd_Season/bd160810 => cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype}/SlidingWindowMaxValue.java (90%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java (91%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java (95%) rename "src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP\347\256\227\346\263\225.md" => "src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP\347\256\227\346\263\225.md" (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java (95%) rename "src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher\347\256\227\346\263\225.md" => "src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher\347\256\227\346\263\225.md" (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/ba160720/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bb160727/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java (91%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java (93%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java (93%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java (92%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java (89%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java (94%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java (92%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java (91%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java (90%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/README.md (100%) rename src/main/java/{algorithm_practice/nowcoder/AlgorithmPrototype => cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810}/SlidingWindowMaxValue.java (90%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java (90%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java (92%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java (94%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/be160817/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java (95%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java (98%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bf160824/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java (98%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java (98%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java (94%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bg160831/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java (98%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java (93%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java (94%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java (87%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java (95%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java (95%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java (95%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bi160914/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java (98%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java (98%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java (83%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java (90%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java (89%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java (64%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java (99%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java (92%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java (97%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java (96%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/b_2nd_Season/bk161012/README.md (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java (95%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/KMP-1.png (100%) rename "src/main/java/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-1.png" => "src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-1.png" (100%) rename "src/main/java/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-2.png" => "src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-2.png" (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbb16072701.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbb16072702.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbc16080301.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbc16080302.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbc16080303.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbd16081001.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbf16082401.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbf16082402.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbi16091401.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbj16092801.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbj16092802.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbk16101201.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbk16101202.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbk16101203.png (100%) rename src/main/java/{ => cc/tianbin}/algorithm_practice/nowcoder/image/nowcoderbk16101204.png (100%) rename src/main/java/{ => cc/tianbin}/common/CommonConstants.java (88%) rename src/main/java/{ => cc/tianbin}/common/context/ApplicationContextHelper.java (98%) rename src/main/java/{ => cc/tianbin}/common/datastruct/BinarySearch.java (94%) rename src/main/java/{ => cc/tianbin}/common/datastruct/BinaryTreeNode.java (91%) rename src/main/java/{ => cc/tianbin}/common/datastruct/BinaryTreeNodeWithParent.java (92%) rename src/main/java/{ => cc/tianbin}/common/datastruct/ListNode.java (93%) rename src/main/java/{ => cc/tianbin}/common/datastruct/Node.java (90%) rename src/main/java/{ => cc/tianbin}/common/datastruct/TreeNode.java (92%) rename src/main/java/{ => cc/tianbin}/common/enums/ErrorCode.java (89%) rename src/main/java/{ => cc/tianbin}/common/model/Person.java (97%) rename src/main/java/{ => cc/tianbin}/common/model/PersonDTO.java (89%) rename src/main/java/{ => cc/tianbin}/common/util/AssertUtils.java (83%) rename src/main/java/{ => cc/tianbin}/common/util/CommonBeanUtil.java (99%) rename src/main/java/{ => cc/tianbin}/common/util/CompareUtils.java (97%) rename src/main/java/{ => cc/tianbin}/common/util/ConstructLinkedNode.java (96%) rename src/main/java/{ => cc/tianbin}/common/util/CopyUtil.java (94%) rename src/main/java/{ => cc/tianbin}/common/util/DownloadUtil.java (99%) rename src/main/java/{ => cc/tianbin}/common/util/GenerateUUID.java (89%) rename src/main/java/{ => cc/tianbin}/common/util/LogUtil.java (95%) rename src/main/java/{ => cc/tianbin}/common/util/README.md (100%) rename src/main/java/{ => cc/tianbin}/common/util/StandardInit.java (91%) rename src/main/java/{ => cc/tianbin}/common/util/SwapUtil.java (94%) rename src/main/java/{ => cc/tianbin}/common/util/SysOut.java (97%) rename src/main/java/{ => cc/tianbin}/common/util/SysRandom.java (99%) rename src/main/java/{ => cc/tianbin}/common/util/SystemUtil.java (96%) rename src/main/java/{ => cc/tianbin}/common/util/batchInsert/NameUtil.java (99%) rename src/main/java/{ => cc/tianbin}/common/util/batchInsert/RandomValue.java (99%) rename src/main/java/{ => cc/tianbin}/common/util/binaryTree/ConstructBinaryTree.java (98%) rename src/main/java/{ => cc/tianbin}/common/util/binaryTree/PrintBinaryTree.java (91%) rename src/main/java/{ => cc/tianbin}/common/util/binaryTree/SerializeAndReConstructTree.java (82%) rename src/main/java/{ => cc/tianbin}/common/util/binaryTree/SerializeAndReConstructTreeImpl.java (95%) rename src/main/java/{ => cc/tianbin}/common/util/binaryTree/SerializeAndReConstructTreeUtils.java (93%) rename src/main/java/{ => cc/tianbin}/common/util/validate/FluentValidator.java (90%) rename src/main/java/{ => cc/tianbin}/common/util/validate/Validator.java (84%) rename src/main/java/{ => cc/tianbin}/common/util/validate/context/ValidateContext.java (98%) rename src/main/java/{ => cc/tianbin}/common/util/validate/context/ValidateContextAttrKey.java (86%) rename src/main/java/{ => cc/tianbin}/common/util/validate/context/ValidateElement.java (86%) rename src/main/java/{ => cc/tianbin}/common/util/validate/context/ValidateResult.java (91%) rename src/main/java/{ => cc/tianbin}/common/util/validate/validator/OperatorValidator.java (80%) rename src/main/java/{ => cc/tianbin}/data_struct/Node.java (86%) rename src/main/java/{ => cc/tianbin}/data_struct/README.md (100%) rename "src/main/java/data_struct/ds1_\345\240\206/Heap.java" => "src/main/java/cc/tianbin/data_struct/ds1_\345\240\206/Heap.java" (95%) rename "src/main/java/data_struct/ds1_\345\240\206/HeapGreater.java" => "src/main/java/cc/tianbin/data_struct/ds1_\345\240\206/HeapGreater.java" (95%) rename "src/main/java/data_struct/ds1_\345\240\206/MyHeap.java" => "src/main/java/cc/tianbin/data_struct/ds1_\345\240\206/MyHeap.java" (93%) rename "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTree.java" (97%) rename "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeImpl.java" (99%) rename "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeNode.java" (92%) rename "src/main/java/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\344\272\214\345\217\211\346\237\245\346\211\276\346\240\221/BinarySearchTreeTest.java" (97%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLNode.java" (71%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTree.java" (95%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeImpl.java" (94%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/AVLTreeTest.java" (80%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackNode.java" (93%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTree.java" (98%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeImpl.java" (98%) rename "src/main/java/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" => "src/main/java/cc/tianbin/data_struct/ds2_\346\240\221/\345\271\263\350\241\241\346\237\245\346\211\276\346\240\221/RedBlackTreeTest.java" (92%) rename "src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/MyUnionFind.java" => "src/main/java/cc/tianbin/data_struct/ds3_\345\271\266\346\237\245\351\233\206/MyUnionFind.java" (90%) rename "src/main/java/data_struct/ds3_\345\271\266\346\237\245\351\233\206/UnionFind.java" => "src/main/java/cc/tianbin/data_struct/ds3_\345\271\266\346\237\245\351\233\206/UnionFind.java" (97%) rename "src/main/java/data_struct/ds4_\345\233\276/Edge.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/Edge.java" (87%) rename "src/main/java/data_struct/ds4_\345\233\276/Graph.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/Graph.java" (89%) rename "src/main/java/data_struct/ds4_\345\233\276/GraphGenerator.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/GraphGenerator.java" (96%) rename "src/main/java/data_struct/ds4_\345\233\276/Node.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/Node.java" (93%) rename "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/BFS.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/adjoin_map/BFS.java" (97%) rename "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/DFS.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/adjoin_map/DFS.java" (96%) rename "src/main/java/data_struct/ds4_\345\233\276/adjoin_map/Graph.java" => "src/main/java/cc/tianbin/data_struct/ds4_\345\233\276/adjoin_map/Graph.java" (97%) rename src/main/java/cc/tianbin/{ => demo}/hessian/HessianDemo.java (98%) rename src/main/java/cc/tianbin/{ => demo}/hessian/README.md (100%) rename "src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" => "src/main/java/cc/tianbin/demo/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Main.java" (98%) rename "src/main/java/cc/tianbin/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" => "src/main/java/cc/tianbin/demo/hessian/\345\272\217\345\210\227\345\214\226\347\273\223\346\236\234\345\257\271\346\257\224/Student.java" (87%) rename src/main/java/cc/tianbin/{ => demo}/java/IO/1.txt (100%) rename src/main/java/cc/tianbin/{ => demo}/java/IO/FileReaderTest.java (98%) rename src/main/java/cc/tianbin/{ => demo}/java/IO/classpath/Main.java (94%) rename src/main/java/cc/tianbin/{ => demo}/java/IO/classpath/ResourcesReaderUtil.java (86%) rename src/main/java/cc/tianbin/{ => demo}/java/IO/classpath/RpcConfig.java (77%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/README.md (100%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/Main.java (99%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/Person.java (95%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/TargetInterceptor.java (96%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/TargetMethodCallbackFilter.java (95%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/TargetResultFixed.java (94%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/lazyloader/ConcreteClassDispatcher.java (85%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/lazyloader/ConcreteClassLazyLoader.java (91%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/lazyloader/LazyBean.java (97%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/cglib/lazyloader/PropertyBean.java (82%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/jdk/Calculator.java (72%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/jdk/CalculatorImpl.java (81%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/jdk/HelloService.java (82%) rename src/main/java/cc/tianbin/{ => demo}/java/proxy/jdk/HelloServiceImpl.java (90%) rename "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" => "src/main/java/cc/tianbin/demo/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/DynamicProxy.java" (70%) rename "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" => "src/main/java/cc/tianbin/demo/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/Main.java" (90%) rename "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" => "src/main/java/cc/tianbin/demo/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/LogHandler.java" (93%) rename "src/main/java/cc/tianbin/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" => "src/main/java/cc/tianbin/demo/java/proxy/jdk/\345\212\250\346\200\201\344\273\243\347\220\206/handler/MyInvocationHandler.java" (94%) rename "src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" => "src/main/java/cc/tianbin/demo/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/HelloServiceProxy.java" (80%) rename "src/main/java/cc/tianbin/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" => "src/main/java/cc/tianbin/demo/java/proxy/jdk/\351\235\231\346\200\201\344\273\243\347\220\206/Main.java" (71%) rename "src/main/java/cc/tianbin/java/\345\217\215\345\260\204/CompareUtil.java" => "src/main/java/cc/tianbin/demo/java/\345\217\215\345\260\204/CompareUtil.java" (99%) rename "src/main/java/cc/tianbin/java/\345\217\215\345\260\204/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\217\215\345\260\204/Main.java" (97%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BigDecimalTest.java" (97%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/BooleanTest.java" (82%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/ByteTest.java" (82%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/DoubleTest.java" (94%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/IntegerTest.java" (96%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/MathTest.java" (81%) rename "src/main/java/cc/tianbin/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" => "src/main/java/cc/tianbin/demo/java/\345\237\272\346\234\254\346\225\260\346\215\256\347\261\273\345\236\213/StringTest.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" (86%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/synchronized\344\270\215\345\217\257\351\207\215\345\205\245\351\224\201_\351\235\236\345\205\254\345\271\263\351\224\201.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_AQS/CountdownLatchExample.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_AQS/CyclicBarrierExample.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_AQS/README.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_AQS/SemaphoreExample.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" (86%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_demo/BlockedQueue.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_demo/Cache.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_demo/DisruptorDemo.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_demo/ObjectPool.java" (98%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_demo/Point.java" (98%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_other/ForkJoinExample.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_other/FutureTaskExample.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_other/Main.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_other/ProducerConsumer.java" (94%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/JUC_other/README.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" (99%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/Main.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/README.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/README.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/thread_demo/README.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/thread_demo/README.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/ExecutorsExceptionTest.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/a0_\345\244\232\347\272\277\347\250\213\345\220\214\346\255\245.java" (99%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/a1_MyThreadPool.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/a2_FutureTask.java" (92%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/b1_FutureTaskDemo.java" (98%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo.java" (94%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/b2_CompletableFutureDemo2.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/b3_CompletionServiceDemo.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/c1_FockJoinDemo.java" (96%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/c2_FockJoinDemo2.java" (98%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" (94%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/bThreadMainJoinDemo.java" (91%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/eSingleThreadPoolDemo.java" (92%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/fCountDownLatchDemo.java" (94%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/gCyclicBarrierDemo.java" (94%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicIntegerExample.java" (78%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/CAS/AtomicReferenceExample.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/README.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/LockExample.java" (85%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/Main.java" (93%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/AwaitSignalExample.java" (94%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/JoinExample.java" (85%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/Main.java" (95%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/README.md" (100%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/reentrantLock/\347\272\277\347\250\213\351\227\264\347\232\204\345\215\217\344\275\234/WaitNotifyExample.java" (83%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/Main.java" (97%) rename "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" => "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/\346\202\262\350\247\202\351\224\201vs\344\271\220\350\247\202\351\224\201/synchronize/SynchronizedExample.java" (94%) rename "src/main/java/cc/tianbin/java/\345\274\202\345\270\270/Main.java" => "src/main/java/cc/tianbin/demo/java/\345\274\202\345\270\270/Main.java" (90%) rename "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/List\347\261\273.java" => "src/main/java/cc/tianbin/demo/java/\351\233\206\345\220\210/List\347\261\273.java" (97%) rename "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" => "src/main/java/cc/tianbin/demo/java/\351\233\206\345\220\210/Map\347\261\273.java" (96%) rename "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Set\347\261\273.java" => "src/main/java/cc/tianbin/demo/java/\351\233\206\345\220\210/Set\347\261\273.java" (93%) rename src/main/java/cc/tianbin/{ => demo}/jvm/GCRoots/GCRootsTest01.java (98%) rename src/main/java/cc/tianbin/{ => demo}/jvm/GCRoots/GCRootsTest02.java (97%) rename src/main/java/cc/tianbin/{ => demo}/jvm/GCRoots/GCRootsTest03.java (97%) rename src/main/java/cc/tianbin/{ => demo}/jvm/GCRoots/GCRootsTest04.java (97%) rename src/main/java/cc/tianbin/{ => demo}/jvm/GCRoots/README.md (100%) rename "src/main/java/cc/tianbin/jvm/GC\344\274\230\345\214\226/HeapOOM.java" => "src/main/java/cc/tianbin/demo/jvm/GC\344\274\230\345\214\226/HeapOOM.java" (96%) rename src/main/java/cc/tianbin/{ => demo}/jvm/classloader/ClassLoaderDemo.java (92%) rename src/main/java/cc/tianbin/{ => demo}/jvm/classloader/LoadStringDemo.java (94%) rename "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" => "src/main/java/cc/tianbin/demo/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/LoadDemo.java" (71%) rename "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" => "src/main/java/cc/tianbin/demo/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/Main.java" (97%) rename "src/main/java/cc/tianbin/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" => "src/main/java/cc/tianbin/demo/jvm/classloader/\350\207\252\345\256\232\344\271\211\347\261\273\345\212\240\350\275\275\345\231\250/MyClassLoader.java" (95%) rename "src/main/java/cc/tianbin/jvm/\345\274\225\347\224\250/Reference.java" => "src/main/java/cc/tianbin/demo/jvm/\345\274\225\347\224\250/Reference.java" (98%) rename src/main/java/cc/tianbin/{ => demo}/netty/Main.java (84%) rename src/main/java/cc/tianbin/{ => demo}/netty/README.md (100%) rename src/main/java/cc/tianbin/{ => demo}/netty/http/App.java (87%) rename src/main/java/cc/tianbin/{ => demo}/netty/http/HttpServer.java (98%) rename src/main/java/cc/tianbin/{ => demo}/netty/http/ServerHandler.java (98%) rename src/main/java/cc/tianbin/{ => demo}/netty/http/ServerInitializer.java (95%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/ClientApp.java (82%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/ServerApp.java (56%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/client/RPCClient.java (94%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/client/request/RPCException.java (90%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/client/request/RPCRequest.java (83%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/client/request/RPCResponse.java (83%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/client/request/RequestId.java (80%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/client/request/ResponseRegistry.java (89%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/customHandler/ExpRequest.java (84%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/customHandler/ExpRequestHandler.java (78%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/customHandler/ExpResponse.java (85%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/customHandler/FibRequestHandler.java (79%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/RPCServer.java (94%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/ServerHandler.java (93%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/message/DefaultHandler.java (89%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/message/IMessageHandler.java (84%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/message/MessageHandlers.java (91%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/message/MessageInput.java (91%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/message/MessageOutput.java (82%) rename src/main/java/cc/tianbin/{ => demo}/netty/rpc/server/message/MessageRegistry.java (88%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/client/ClientApp.java (76%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/client/ClientHandler.java (89%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/client/ClientInitializer.java (95%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/client/SocketClient.java (95%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/server/ServerApp.java (84%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/server/ServerHandler.java (98%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/server/ServerInitializer.java (95%) rename src/main/java/cc/tianbin/{ => demo}/netty/webSocket/server/SocketServer.java (94%) rename src/main/java/cc/tianbin/{ => demo}/redis/HyperLogLog/HyperLogLogCounting.java (98%) rename src/main/java/cc/tianbin/{ => demo}/redis/HyperLogLog/HyperLogLogCountingDemo.java (98%) rename src/main/java/cc/tianbin/{ => demo}/redis/RateLimiter/README.md (100%) rename src/main/java/cc/tianbin/{ => demo}/redis/RateLimiter/RedisRateLimiter.java (98%) rename src/main/test/{ => cc/tianbin}/UnitTestDemo.java (99%) rename src/main/test/{ => cc/tianbin}/algorithm_practice/TempTest.java (93%) rename "src/main/test/algorithm_practice/\344\272\214\345\210\206\346\237\245\346\211\276.java" => "src/main/test/cc/tianbin/algorithm_practice/\344\272\214\345\210\206\346\237\245\346\211\276.java" (100%) rename "src/main/test/algorithm_practice/\345\240\206\346\216\222\345\272\217.java" => "src/main/test/cc/tianbin/algorithm_practice/\345\240\206\346\216\222\345\272\217.java" (97%) rename "src/main/test/algorithm_practice/\345\277\253\351\200\237\346\216\222\345\272\217.java" => "src/main/test/cc/tianbin/algorithm_practice/\345\277\253\351\200\237\346\216\222\345\272\217.java" (91%) rename src/main/test/{ => cc/tianbin}/algorithmzuo/README.md (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/README.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code01_SelectionSort.java" (84%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code02_BubbleSort.java" (83%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code03_InsertionSort.java" (84%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_1_MergeSort_Recursion.java" (90%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_2_MergeSort_Non_Recursion.java" (89%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_3_SmallSum.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_4_ReversePair.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_5_BiggerThanRightTwice.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_6_CountOfRangeSum.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code04_6_CountOfRangeSum.java" (98%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_1_PartitionAndQuickSort.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code05_2_QuickSortRecursionAndUnrecursion.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_1_HeapSort.java" (90%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_2_SortArrayDistanceLessK.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code06_3_CoverMax.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code07_CountSort.java" (88%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0101_\346\216\222\345\272\217/Code08_RadixSort.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code01_BSExist.java" (89%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code02_BSNearLeft.java" (90%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code03_BSNearRight.java" (89%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code04_BSAwesome.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0102_\344\272\214\345\210\206\346\237\245\346\211\276/Code04_BSAwesome.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code01_Swap.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code01_Swap.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code02_EvenTimesOddTimes.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code02_EvenTimesOddTimes.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0103_\345\274\202\346\210\226\350\277\220\347\256\227/Code03_KM.java" (91%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code03_DoubleEndsQueueToStackAndQueue.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code03_DoubleEndsQueueToStackAndQueue.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code04_RingArray.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code04_RingArray.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code05_GetMinStack.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code05_GetMinStack.java" (85%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code06_TwoStacksImplementQueue.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code06_TwoStacksImplementQueue.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code07_TwoQueueImplementStack.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0105_\346\240\210\345\222\214\351\230\237\345\210\227/Code07_TwoQueueImplementStack.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c01xx_\344\270\200\344\272\233\350\266\205\347\272\247\345\237\272\347\241\200\347\232\204\347\256\227\346\263\225.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_1_ReverseListNode.java" (85%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code01_2_ReverseDoubleListNode.java" (86%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code02_DeleteGivenValue.java" (86%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code03_LinkedListMid.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code04_IsPalindromeList.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code04_IsPalindromeList.java" (98%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code05_SmallerEqualBigger.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code06_CopyListWithRandom.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0201_\351\223\276\350\241\250/Code07_FindFirstIntersectListNode.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0202_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0202_\345\211\215\347\274\200\346\240\221/Code01_TrieTree.java" (98%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code01_RecursiveTraversalBT.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code02_UnRecursiveTraversalBT.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code03_LevelTraversalBT.java" (91%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code05_EncodeNaryTreeToBinaryTree.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code05_EncodeNaryTreeToBinaryTree.java" (84%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0203_\346\240\221/Code06_TreeMaxWidth.java" (86%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code01_IsBalanced.java" (87%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code02_IsBST.java" (91%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code03_MaxDistance.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code04_IsFull.java" (86%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code05_MaxSubBSTSize.java" (85%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code06_IsCBT.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code07_MaxSubBSTHead.java" (85%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code08_lowestAncestor.java" (89%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0204_\346\240\221\345\236\213DP/Code09_MaxHappy.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c02xx_\351\223\276\350\241\250\345\222\214\346\240\221.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code01_Light.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code02_LessMoneySplitGold.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code03_BestArrange.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code04_IPO.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0300_\350\264\252\345\277\203/Code04_IPO.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c03xx_\350\264\252\345\277\203\347\256\227\346\263\225.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c03xx_\350\264\252\345\277\203\347\256\227\346\263\225.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code01_FriendCircles.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code02_NumberOfIslands.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code03_NumberOfIslandsII.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0400_\345\271\266\346\237\245\351\233\206/Code03_NumberOfIslandsII.java" (70%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c04xx_\345\271\266\346\237\245\351\233\206.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code01_BFS.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code01_BFS.java" (88%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code02_DFS.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code02_DFS.java" (89%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_1_TopologySort.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_1_TopologySort.java" (87%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_2_TopologicalOrderBFS.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_2_TopologicalOrderBFS.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_3_TopologicalOrderDFS.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code03_3_TopologicalOrderDFS.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code04_Kruskal.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code04_Kruskal.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code05_Prim.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code05_Prim.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_1_Dijkstra.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_1_Dijkstra.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_2_Dijkstra.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code06_2_Dijkstra.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code07_NetworkDelayTime.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0500_\345\233\276/Code07_NetworkDelayTime.java" (98%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code01_Hanoi.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code02_PrintAllSubSequences.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code02_PrintAllSubSequences.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code03_PrintAllPermutations.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0600_\345\270\270\350\247\201\347\232\204\351\200\222\345\275\222/Code04_ReverseStackUsingRecursive.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222.md" (100%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code01_RobotWalk.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code02_CardsInLine.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code02_CardsInLine.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code03_Knapsack.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code03_Knapsack.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code04_ConvertToLetterString.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code04_ConvertToLetterString.java" (91%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code05_StickersToSpellWord.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code05_StickersToSpellWord.java" (97%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code06_LongestCommonSubsequence.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code06_LongestCommonSubsequence.java" (99%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code07_PalindromeSubsequence.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code07_PalindromeSubsequence.java" (95%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code08_HorseJump.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code08_HorseJump.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code09_Coffee.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code09_Coffee.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code10_MinPathSum.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code10_MinPathSum.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code11_CoinsWayEveryPaperDifferent.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code11_CoinsWayEveryPaperDifferent.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code12_CoinsWayNoLimit.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code12_CoinsWayNoLimit.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code13_CoinsWaySameValueSamePapper.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code13_CoinsWaySameValueSamePapper.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code14_MinCoinsNoLimit.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code14_MinCoinsNoLimit.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code15_BobDie.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code15_BobDie.java" (96%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code16_KillMonster.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code16_KillMonster.java" (92%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code17_SplitNumber.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code17_SplitNumber.java" (94%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code18_SplitSumClosed.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code18_SplitSumClosed.java" (93%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code19_SplitSumClosedSizeHalf.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code19_SplitSumClosedSizeHalf.java" (90%) rename "src/main/test/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code20_NQueens.java" => "src/main/test/cc/tianbin/algorithmzuo/b_\344\275\223\347\263\273\345\255\246\344\271\240\347\217\255/c0700_\345\212\250\346\200\201\350\247\204\345\210\222/Code20_NQueens.java" (97%) rename "src/main/test/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" => "src/main/test/cc/tianbin/algorithmzuo/c_\345\244\247\345\216\202\345\210\267\351\242\230\347\217\255/README.md" (100%) rename src/main/test/{ => cc/tianbin}/common/util/DateTimeUtilTest.java (100%) rename src/main/test/{ => cc/tianbin}/common/util/ExcelReadUtilsTest.java (100%) rename src/main/test/{ => cc/tianbin}/common/util/validate/FluentValidatorTest.java (100%) rename src/main/test/cc/tianbin/{ => demo}/Main.java (100%) create mode 100644 src/main/test/cc/tianbin/demo/java/ObjectTest.java rename src/main/test/cc/tianbin/{ => demo}/java/OptionalTest.java (91%) rename src/main/test/cc/tianbin/{ => demo}/java/SwitchCaseTest.java (94%) rename src/main/test/cc/tianbin/{ => demo}/java/spring/SpringTest.java (79%) rename "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" => "src/main/test/cc/tianbin/demo/java/\345\217\215\345\260\204/CommonBeanUtilTest.java" (90%) rename "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" => "src/main/test/cc/tianbin/demo/java/\345\217\215\345\260\204/CopyProperties_\346\200\247\350\203\275\346\265\213\350\257\225.java" (95%) rename "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/README.md" => "src/main/test/cc/tianbin/demo/java/\345\217\215\345\260\204/README.md" (100%) rename "src/main/test/cc/tianbin/java/\345\217\215\345\260\204/ReflectTest.java" => "src/main/test/cc/tianbin/demo/java/\345\217\215\345\260\204/ReflectTest.java" (97%) rename "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListStreamTest.java" => "src/main/test/cc/tianbin/demo/java/\351\233\206\345\220\210/ListStreamTest.java" (95%) rename "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/ListTest.java" => "src/main/test/cc/tianbin/demo/java/\351\233\206\345\220\210/ListTest.java" (99%) rename "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/MapTest.java" => "src/main/test/cc/tianbin/demo/java/\351\233\206\345\220\210/MapTest.java" (94%) rename "src/main/test/cc/tianbin/java/\351\233\206\345\220\210/SetTest.java" => "src/main/test/cc/tianbin/demo/java/\351\233\206\345\220\210/SetTest.java" (97%) create mode 100644 src/main/test/cc/tianbin/demo/redis/RateLimiter/RedisRateLimiterTest.java create mode 100644 src/main/test/cc/tianbin/demo/temp/JsonParseTest.java delete mode 100644 src/main/test/cc/tianbin/excel/ExcelGen.java delete mode 100644 src/main/test/cc/tianbin/excel/ParseJson.java delete mode 100644 src/main/test/cc/tianbin/excel/StockDTO.java delete mode 100644 src/main/test/cc/tianbin/java/ObjectTest.java rename src/main/test/{ => cc/tianbin}/java/lang/test/String.class (100%) rename src/main/test/{ => cc/tianbin}/java/lang/test/String_.java (100%) delete mode 100644 src/main/test/cc/tianbin/java/mybatis/MybatisTest.java rename src/main/test/{ => cc/tianbin}/javalang/test/FinallyTest.java (96%) rename src/main/test/{ => cc/tianbin}/javalang/test/IfTest.java (97%) delete mode 100644 src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java delete mode 100644 src/main/test/cc/tianbin/temp/DataGen.java delete mode 100644 src/main/test/cc/tianbin/temp/JsonParseTest.java rename src/main/test/{ => cc/tianbin}/tmp/interview/Main.java (73%) diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" similarity index 87% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" index a657584a..8c3eeee1 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P01_GetMinStack.java" @@ -1,4 +1,4 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" similarity index 93% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" index d44255ad..82d8b962 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P02_\347\224\261\344\270\244\344\270\252\346\240\210\347\273\204\346\210\220\347\232\204\351\230\237\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" similarity index 87% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" index 967bf5ed..e75d482e 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P03_\344\275\277\347\224\250\351\200\222\345\275\222\351\200\206\345\272\217\344\270\200\344\270\252\346\240\210.java" @@ -1,7 +1,7 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; -import common.util.StandardInit; -import common.util.SysOut; +import cc.tianbin.common.util.StandardInit; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" similarity index 95% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" index b8353662..13031b2a 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P04_\347\214\253\347\213\227\351\230\237\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import junit.framework.TestCase; import lombok.AllArgsConstructor; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" similarity index 92% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" index dbc710e7..2accab5d 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P05_\347\224\250\344\270\200\344\270\252\346\240\210\345\256\236\347\216\260\345\217\246\344\270\200\344\270\252\346\240\210\347\232\204\346\216\222\345\272\217.java" @@ -1,7 +1,7 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; -import common.util.StandardInit; -import common.util.SysOut; +import cc.tianbin.common.util.StandardInit; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" similarity index 98% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" index d29d0beb..d701ec10 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P06_\347\224\250\346\240\210\346\235\245\350\247\243\345\206\263\346\261\211\350\257\272\345\241\224\351\227\256\351\242\230.java" @@ -1,6 +1,6 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import lombok.AllArgsConstructor; import lombok.Getter; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" similarity index 95% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" index aadedd8d..6cc5ed92 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P07_\347\224\237\346\210\220\347\252\227\345\217\243\346\234\200\345\244\247\345\200\274\346\225\260\347\273\204.java" @@ -1,6 +1,6 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" similarity index 96% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" index bc446f44..cbd0a8b3 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P08_\345\215\225\350\260\203\346\240\210\347\273\223\346\236\204.java" @@ -1,9 +1,9 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import com.google.common.collect.Lists; import junit.framework.TestCase; import org.junit.Test; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.List; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" similarity index 95% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" index 5bfcaea7..8b02a18b 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P09_\346\261\202\346\234\200\345\244\247\345\255\220\347\237\251\351\230\265\347\232\204\345\244\247\345\260\217.java" @@ -1,9 +1,9 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import com.google.common.collect.Lists; import junit.framework.TestCase; import org.junit.Test; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.List; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" similarity index 95% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" index 0ecb04c0..37e1a2bd 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P10_\346\234\200\345\244\247\345\200\274\345\207\217\345\216\273\346\234\200\345\260\217\345\200\274\345\260\217\344\272\216\346\210\226\347\255\211\344\272\216num\347\232\204\345\255\220\346\225\260\347\273\204\346\225\260\351\207\217.java" @@ -1,8 +1,8 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import junit.framework.TestCase; import org.junit.Test; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.LinkedList; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" similarity index 97% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" index 1a57f235..b95cd616 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_01_\346\240\210\345\222\214\351\230\237\345\210\227/P11_\345\217\257\350\247\201\347\232\204\345\261\261\345\263\260\345\257\271\346\225\260\351\207\217.java" @@ -1,9 +1,9 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_01_栈和队列; import junit.framework.TestCase; import lombok.Getter; import org.junit.Test; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" similarity index 89% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" index 12493ec9..18e3b3bc 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P01_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_04_递归和动态规划; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_04_递归和动态规划; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" similarity index 96% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" index 75d926e7..0b445d3e 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P02_\347\237\251\351\230\265\347\232\204\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" @@ -1,4 +1,4 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_04_递归和动态规划; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_04_递归和动态规划; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" similarity index 94% rename from "src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" index e114b852..d1dd0c8d 100644 --- "a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/Chapter_04_\351\200\222\345\275\222\345\222\214\345\212\250\346\200\201\350\247\204\345\210\222/P03_\346\234\272\345\231\250\344\272\272\350\276\276\345\210\260\346\214\207\345\256\232\344\275\215\347\275\256\346\226\271\346\263\225\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_04_递归和动态规划; +package cc.tianbin.algorithm_practice.Coding_Interview_Guide_2ndEdition.Chapter_04_递归和动态规划; import junit.framework.TestCase; import org.junit.Test; diff --git a/src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/README.md b/src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/README.md similarity index 100% rename from src/main/java/algorithm_practice/Coding_Interview_Guide_2ndEdition/README.md rename to src/main/java/cc/tianbin/algorithm_practice/Coding_Interview_Guide_2ndEdition/README.md diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" index 19512271..c1829a4c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E001_\344\270\244\346\225\260\344\271\213\345\222\214.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.CompareUtils; +import cc.tianbin.common.util.CompareUtils; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" index a7622598..8eaaffbe 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E035_\346\220\234\347\264\242\346\217\222\345\205\245\344\275\215\347\275\256.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" similarity index 95% rename from "src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" index 194a6eca..2dddce84 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E069_x\347\232\204\345\271\263\346\226\271\346\240\271.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" similarity index 91% rename from "src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" index ec9f8063..226e5932 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/E083_\345\210\240\351\231\244\346\216\222\345\272\217\351\223\276\350\241\250\344\270\255\347\232\204\351\207\215\345\244\215\345\205\203\347\264\240.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" index 1b49ab59..fa435f1e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H004_\345\257\273\346\211\276\344\270\244\344\270\252\346\234\211\345\272\217\346\225\260\347\273\204\347\232\204\344\270\255\344\275\215\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" index c5e8d3c9..296e217a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H042_\346\216\245\351\233\250\346\260\264.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import cn.hutool.core.lang.Assert; import junit.framework.TestCase; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" index 1c17fd4e..b47a0c69 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H051_N\347\232\207\345\220\216.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" index fd220e8d..f63085a6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H057_\346\217\222\345\205\245\345\214\272\351\227\264.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.alibaba.fastjson.JSON; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" index e09421ac..aee2d951 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H072_\347\274\226\350\276\221\350\267\235\347\246\273.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" index 72f71eb9..ff9a0242 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" index 6332c4a2..6978a55b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" index d4c73d98..b059f605 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M002_\344\270\244\346\225\260\347\233\270\345\212\240.java" @@ -1,9 +1,9 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import common.datastruct.ListNode; -import common.util.AssertUtils; -import common.util.ConstructLinkedNode; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.AssertUtils; +import cc.tianbin.common.util.ConstructLinkedNode; import org.junit.Test; /* diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" index b9e1ee3a..cac566ad 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M003_\346\227\240\351\207\215\345\244\215\345\255\227\347\254\246\347\232\204\346\234\200\351\225\277\345\255\220\344\270\262.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import io.github.nibnait.common.constants.CommonConstants; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" index 799e43e4..683c6c26 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M005_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\344\270\262.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" index ee09c438..596f5e36 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M006_Z\345\255\227\345\275\242\345\217\230\346\215\242.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" index 311cead3..e822e2db 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M011_\347\233\233\346\234\200\345\244\232\346\260\264\347\232\204\345\256\271\345\231\250.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" index 1b5f49f7..1676d50b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M014_\346\234\200\351\225\277\345\205\254\345\205\261\345\211\215\347\274\200.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" index 979caa28..f9b15c5a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M015_\344\270\211\346\225\260\344\271\213\345\222\214.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.AssertUtils; +import cc.tianbin.common.util.AssertUtils; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" index 97aa6e0e..f5f03f1f 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M016_\346\234\200\346\216\245\350\277\221\347\232\204\344\270\211\346\225\260\344\271\213\345\222\214.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" index 6276a55b..21617706 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import common.util.AssertUtils; +import cc.tianbin.common.util.AssertUtils; import org.junit.Test; import java.util.ArrayList; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" similarity index 91% rename from "src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" index 5e1190c2..fe035763 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M019_\345\210\240\351\231\244\351\223\276\350\241\250\347\232\204\345\200\222\346\225\260\347\254\254N\344\270\252\350\212\202\347\202\271.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" similarity index 91% rename from "src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" index f5d218b8..239eb96e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M024_\344\270\244\344\270\244\344\272\244\346\215\242\351\223\276\350\241\250\344\270\255\347\232\204\350\212\202\347\202\271.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" index d98dac9e..f2b32ae7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M031_\344\270\213\344\270\200\344\270\252\346\216\222\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" index ac978125..0e0acc77 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M033_\346\220\234\347\264\242\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" index 935c7ed7..63bbba2d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M034_\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\346\237\245\346\211\276\345\205\203\347\264\240\347\232\204\347\254\254\344\270\200\344\270\252\345\222\214\346\234\200\345\220\216\344\270\200\344\270\252\344\275\215\347\275\256.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.alibaba.fastjson.JSON; import junit.framework.TestCase; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" index b602648a..70898539 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M039_\347\273\204\345\220\210\346\200\273\345\222\214.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" index 33d99ef1..1116c262 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M040_\347\273\204\345\220\210\346\200\273\345\222\2142.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" index 46efdeda..03bf1988 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M043_\345\255\227\347\254\246\344\270\262\347\233\270\344\271\230.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.AssertUtils; +import cc.tianbin.common.util.AssertUtils; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" index a3f89bdd..591a7dee 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import common.util.AssertUtils; +import cc.tianbin.common.util.AssertUtils; import org.junit.Test; import java.util.ArrayList; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" index f98f6061..50a468cc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import common.util.AssertUtils; +import cc.tianbin.common.util.AssertUtils; import org.junit.Test; import java.util.*; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" index 30bc5150..3a2817f0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M056_\345\220\210\345\271\266\345\214\272\351\227\264.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" index 48d7d414..33eb687b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M060_\347\254\254k\344\270\252\346\216\222\345\210\227.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" index e0205500..26a97b33 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M061_\346\227\213\350\275\254\351\223\276\350\241\250.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" index 80ab4f30..6b16e525 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M062_\344\270\215\345\220\214\350\267\257\345\276\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" index 2e71e1de..767cb023 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M063_\344\270\215\345\220\214\350\267\257\345\276\2042.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" index 31799acb..8ecc49e2 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M071_\347\256\200\345\214\226\350\267\257\345\276\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" index 6bc9cdb2..26511f19 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M074_\346\220\234\347\264\242\344\272\214\347\273\264\347\237\251\351\230\265.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" similarity index 92% rename from "src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" index afecd71c..dc867a44 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M092_\345\217\215\350\275\254\351\223\276\350\241\2502.java" @@ -1,9 +1,9 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.ListNode; -import common.util.CompareUtils; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.CompareUtils; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" index e93adc9b..f70a2583 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M093_\345\244\215\345\216\237IP\345\234\260\345\235\200.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" index c3470a72..45e94468 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M094_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\255\345\272\217\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" index 013f6d0e..27385be1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M096_\344\270\215\345\220\214\347\232\204\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\346\225\260\351\207\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" similarity index 92% rename from "src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" index 8fc5bfbe..b59f13c6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M098_\351\252\214\350\257\201\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code000; +package cc.tianbin.algorithm_practice.LeetCode.code000; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" similarity index 91% rename from "src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" index 797a6842..25533406 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E101_\345\257\271\347\247\260\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" index 6fa8764c..ff1668f0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E104_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\244\247\346\267\261\345\272\246.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" index e4d88d6a..2370ee0d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E110_\345\271\263\350\241\241\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" similarity index 94% rename from "src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" index 9ab25409..ac22b3f3 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E111_\344\272\214\345\217\211\346\240\221\347\232\204\346\234\200\345\260\217\346\267\261\345\272\246.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" index 8d88b218..64954834 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E121_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" index 1453ea84..e2290d46 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E122_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2722.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" index c32b59ef..3b62deac 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/E198_\346\211\223\345\256\266\345\212\253\350\210\215.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" index 2810b18f..ec3c7e62 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H123_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2723.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" similarity index 91% rename from "src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" index eb4b7d00..603fe1a5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H124_\344\272\214\345\217\211\346\240\221\344\270\255\347\232\204\346\234\200\345\244\247\350\267\257\345\276\204\345\222\214.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" index d5349f16..cff8e1a7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H128_\346\234\200\351\225\277\350\277\236\347\273\255\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" index 4a8e1f5a..61a11a49 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H140_\345\215\225\350\257\215\346\213\206\345\210\2062.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import com.google.common.collect.Lists; import org.apache.commons.lang3.StringUtils; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" index 54b431a4..da2c4444 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H164_\346\234\200\345\244\247\351\227\264\350\267\235.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" index 8ef068fe..a6fd40d0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/H188_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\2724.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" similarity index 92% rename from "src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" index 4381c81e..95b5f422 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M102_\344\272\214\345\217\211\346\240\221\347\232\204\345\261\202\346\254\241\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" index bab22208..3579e842 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M127_\345\215\225\350\257\215\346\216\245\351\276\231.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" index 523e09fb..23571ed7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M134_\345\212\240\346\262\271\347\253\231.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" index 4a846672..c92b7b9a 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M139_\345\215\225\350\257\215\346\213\206\345\210\206.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" index 95aa4783..20c9534e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M144_\344\272\214\345\217\211\346\240\221\347\232\204\345\211\215\345\272\217\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" similarity index 94% rename from "src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" index 63e52e97..e58cbd6e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M145_\344\272\214\345\217\211\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" index 0f235e7a..ebfe9db6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M146_LRU\347\274\223\345\255\230\346\234\272\345\210\266.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" similarity index 92% rename from "src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" index f08c35ba..6118d598 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M147_\345\257\271\351\223\276\350\241\250\350\277\233\350\241\214\346\217\222\345\205\245\346\216\222\345\272\217.java" @@ -1,9 +1,9 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.ListNode; -import common.util.CompareUtils; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.CompareUtils; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" similarity index 92% rename from "src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" index 2f7607d9..9ec2170c 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M148_\346\216\222\345\272\217\351\223\276\350\241\250.java" @@ -1,9 +1,9 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.ListNode; -import common.util.CompareUtils; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.CompareUtils; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" index 8765c557..2144afa0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M151_\347\277\273\350\275\254\345\255\227\347\254\246\344\270\262\351\207\214\347\232\204\345\215\225\350\257\215.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" index 96bfeea1..4e3f0e37 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M153_\345\257\273\346\211\276\346\227\213\350\275\254\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\347\232\204\346\234\200\345\260\217\345\200\274.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" similarity index 94% rename from "src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" index b837870f..3501795d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code100/M199_\344\272\214\345\217\211\346\240\221\347\232\204\345\217\263\350\247\206\345\233\276.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code100; +package cc.tianbin.algorithm_practice.LeetCode.code100; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" index 9d604986..4800da92 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1030_\350\267\235\347\246\273\351\241\272\345\272\217\346\216\222\345\210\227\347\237\251\351\230\265\345\215\225\345\205\203\346\240\274.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code1000; +package cc.tianbin.algorithm_practice.LeetCode.code1000; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" index 25581c96..55cf943d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1000/E1071_\345\255\227\347\254\246\344\270\262\347\232\204\346\234\200\345\244\247\345\205\254\345\233\240\345\255\220.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code1000; +package cc.tianbin.algorithm_practice.LeetCode.code1000; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" index 1b4d5d7e..6d8d69e3 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1122_\346\225\260\347\273\204\347\232\204\347\233\270\345\257\271\346\216\222\345\272\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code1100; +package cc.tianbin.algorithm_practice.LeetCode.code1100; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" index dbe5d7a0..ba82ef78 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code1100/E1160_\346\213\274\345\206\231\345\215\225\350\257\215.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code1100; +package cc.tianbin.algorithm_practice.LeetCode.code1100; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" similarity index 90% rename from "src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" index ff5cb74f..eb8e6be8 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E206_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,9 +1,9 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.datastruct.ListNode; -import common.util.CompareUtils; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.CompareUtils; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" similarity index 94% rename from "src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" index 6f3173d5..c03077aa 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E226_\347\277\273\350\275\254\344\272\214\345\217\211\346\240\221.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" similarity index 93% rename from "src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" index d02fce61..42220dd6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; import cn.hutool.core.lang.Assert; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; import org.junit.Test; /** diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" similarity index 90% rename from "src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" index a2cc7dc6..9879f3f5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E237_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\347\232\204\347\273\223\347\202\271.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" index 1c402d94..cb5286b4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E242_\346\234\211\346\225\210\347\232\204\345\255\227\346\257\215\345\274\202\344\275\215\350\257\215.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" similarity index 95% rename from "src/main/java/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" index 721b032f..745125c7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E283_\347\247\273\345\212\250\351\233\266.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" similarity index 94% rename from "src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" index c3391231..3b403388 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/H297_\344\272\214\345\217\211\346\240\221\347\232\204\345\272\217\345\210\227\345\214\226\344\270\216\345\217\215\345\272\217\345\210\227\345\214\226.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" index c13747c7..e2df2817 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M207_\350\257\276\347\250\213\350\241\250.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" index 11dda101..b1ab59bf 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M210_\350\257\276\347\250\213\350\241\2502.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" index b14d3d3a..180de44e 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M213_\346\211\223\345\256\266\345\212\253\350\210\2152.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" similarity index 95% rename from "src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" index be663cc6..90177f5b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M215_\346\225\260\347\273\204\344\270\255\347\232\204\347\254\254K\344\270\252\346\234\200\345\244\247\345\205\203\347\264\240.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" index 4239b64b..f66fa8d0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M216_\347\273\204\345\220\210\346\200\273\345\222\2143.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; import com.google.common.collect.Lists; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" similarity index 89% rename from "src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" index 778550d0..43e45b88 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/M222_\345\256\214\345\205\250\344\272\214\345\217\211\346\240\221\347\232\204\350\212\202\347\202\271\344\270\252\346\225\260.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code200; +package cc.tianbin.algorithm_practice.LeetCode.code200; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" index eceb860b..53a3bb4b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H327_\345\214\272\351\227\264\345\222\214\347\232\204\344\270\252\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" index 69deffcf..050afe27 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/H329_\347\237\251\351\230\265\344\270\255\347\232\204\346\234\200\351\225\277\351\200\222\345\242\236\350\267\257\345\276\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" index ed8873ff..70831aa8 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M300_\346\234\200\351\225\277\344\270\212\345\215\207\345\255\220\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import junit.framework.TestCase; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" index 328a5409..ae5d9fda 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M309_\346\234\200\344\275\263\344\271\260\345\215\226\350\202\241\347\245\250\346\227\266\346\234\272\345\220\253\345\206\267\345\206\273\346\234\237.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" index a0ba02a1..d4af2383 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M322_\351\233\266\351\222\261\345\205\221\346\215\242.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import junit.framework.TestCase; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" similarity index 95% rename from "src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" index 33039fbc..a81190f0 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M328_\345\245\207\345\201\266\351\223\276\350\241\250.java" @@ -1,9 +1,9 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; -import common.datastruct.ListNode; -import common.util.CompareUtils; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.CompareUtils; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" similarity index 94% rename from "src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" index 0fdff871..7c37ace9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M337_\346\211\223\345\256\266\345\212\253\350\210\2153.java" @@ -1,7 +1,7 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" index 8051edb2..23f1a0b3 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M365_\346\260\264\345\243\266\351\227\256\351\242\230.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" index 7e2a1c12..268eb1f4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code300/M377_\347\273\204\345\220\210\346\200\273\345\222\2144.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code300; +package cc.tianbin.algorithm_practice.LeetCode.code300; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" index a86470bd..fd037dae 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E409_\346\234\200\351\225\277\345\233\236\346\226\207\344\270\262.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" index 7decc500..dfa75083 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/E496_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2401.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" index 57daca41..85f6e001 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/H460_LFU\347\274\223\345\255\230.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" index bc0010d4..fc6bbea7 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M402_\347\247\273\346\216\211K\344\275\215\346\225\260\345\255\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" index 0c3b8ccd..b1cd6e32 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M406_\346\240\271\346\215\256\350\272\253\351\253\230\351\207\215\345\273\272\351\230\237\345\210\227.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" index 459c5331..e99baca4 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M416_\345\210\206\345\211\262\347\255\211\345\222\214\345\255\220\351\233\206.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import junit.framework.TestCase; import org.junit.Assert; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" index 9fcd836f..4d751e04 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M452_\347\224\250\346\234\200\345\260\221\346\225\260\351\207\217\347\232\204\347\256\255\345\274\225\347\210\206\346\260\224\347\220\203.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" index 33941b25..43d229e8 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M474_\344\270\200\345\222\214\351\233\266.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" index 172063cc..1341b71d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code400/M494_\347\233\256\346\240\207\345\222\214.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code400; +package cc.tianbin.algorithm_practice.LeetCode.code400; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" index dd5b6981..6c2a22a5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/H514_\350\207\252\347\224\261\344\271\213\350\267\257.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code500; +package cc.tianbin.algorithm_practice.LeetCode.code500; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" index 43aaab88..c3decb9d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M503_\344\270\213\344\270\200\344\270\252\346\233\264\345\244\247\345\205\203\347\264\2402.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code500; +package cc.tianbin.algorithm_practice.LeetCode.code500; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" index 7ede6420..159ec3e1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M516_\346\234\200\351\225\277\345\233\236\346\226\207\345\255\220\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code500; +package cc.tianbin.algorithm_practice.LeetCode.code500; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" index 7e831bb7..1989fb7b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M518_\351\233\266\351\222\261\345\205\221\346\215\2422.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code500; +package cc.tianbin.algorithm_practice.LeetCode.code500; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" index 93385f27..ba49b23d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M547_\346\234\213\345\217\213\345\234\210.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code500; +package cc.tianbin.algorithm_practice.LeetCode.code500; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" similarity index 99% rename from "src/main/java/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" index 426c00d1..b959f2c6 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M567_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code500; +package cc.tianbin.algorithm_practice.LeetCode.code500; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" index d295f534..02ad8a62 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/E674_\346\234\200\351\225\277\350\277\236\347\273\255\351\200\222\345\242\236\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code600; +package cc.tianbin.algorithm_practice.LeetCode.code600; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" index 040c59c6..1f7232d5 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/M695_\345\262\233\345\261\277\347\232\204\346\234\200\345\244\247\351\235\242\347\247\257.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code600; +package cc.tianbin.algorithm_practice.LeetCode.code600; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" index 7199372e..e7424f09 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/E704_\344\272\214\345\210\206\346\237\245\346\211\276.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code700; +package cc.tianbin.algorithm_practice.LeetCode.code700; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" index 5c63e89b..163e4ae1 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code700/M714_\344\271\260\345\215\226\350\202\241\347\245\250\347\232\204\346\234\200\344\275\263\346\227\266\346\234\272\345\220\253\346\211\213\347\273\255\350\264\271.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code700; +package cc.tianbin.algorithm_practice.LeetCode.code700; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" index a9a5a9b6..5153fc70 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E836_\347\237\251\345\275\242\351\207\215\345\217\240.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code800; +package cc.tianbin.algorithm_practice.LeetCode.code800; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" similarity index 90% rename from "src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" index 9c2e07c5..2d8b67da 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/E876_\351\223\276\350\241\250\347\232\204\344\270\255\351\227\264\347\273\223\347\202\271.java" @@ -1,8 +1,8 @@ -package algorithm_practice.LeetCode.code800; +package cc.tianbin.algorithm_practice.LeetCode.code800; -import common.datastruct.ListNode; -import common.util.ConstructLinkedNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.ConstructLinkedNode; +import cc.tianbin.common.util.SysOut; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" index 29281202..94d0d451 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code800/H887_\351\270\241\350\233\213\346\216\211\350\220\275.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code800; +package cc.tianbin.algorithm_practice.LeetCode.code800; /* 你将获得 K 个鸡蛋,并可以使用一栋从 1 到 N 共有 N 层楼的建筑。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" similarity index 95% rename from "src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" index b8736ae4..59f6f2cc 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E905_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code900; +package cc.tianbin.algorithm_practice.LeetCode.code900; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" index fa1bfbe0..513aa1aa 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/E922_\346\214\211\345\245\207\345\201\266\346\216\222\345\272\217\346\225\260\347\273\2042.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code900; +package cc.tianbin.algorithm_practice.LeetCode.code900; /* 给定一个非负整数数组 A, A 中一半整数是奇数,一半整数是偶数。 diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" similarity index 98% rename from "src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" index ee22c0e7..1795db63 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/H980_\344\270\215\345\220\214\350\267\257\345\276\2043.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code900; +package cc.tianbin.algorithm_practice.LeetCode.code900; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" similarity index 92% rename from "src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" index 46359c9f..1893213d 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M912_\346\216\222\345\272\217\346\225\260\347\273\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code900; +package cc.tianbin.algorithm_practice.LeetCode.code900; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" similarity index 96% rename from "src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" index 877c0203..ce920dba 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M945_\344\275\277\346\225\260\347\273\204\345\224\257\344\270\200\347\232\204\346\234\200\345\260\217\345\242\236\351\207\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.LeetCode.code900; +package cc.tianbin.algorithm_practice.LeetCode.code900; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" similarity index 97% rename from "src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" index 478f2061..d34e74de 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code900/M973_\346\234\200\346\216\245\350\277\221\345\216\237\347\202\271\347\232\204K\344\270\252\347\202\271.java" @@ -1,6 +1,6 @@ -package algorithm_practice.LeetCode.code900; +package cc.tianbin.algorithm_practice.LeetCode.code900; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import org.junit.Assert; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\202\241\347\245\250\344\271\260\345\215\226\351\227\256\351\242\230.md" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\202\241\347\245\250\344\271\260\345\215\226\351\227\256\351\242\230.md" similarity index 100% rename from "src/main/java/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\202\241\347\245\250\344\271\260\345\215\226\351\227\256\351\242\230.md" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\202\241\347\245\250\344\271\260\345\215\226\351\227\256\351\242\230.md" diff --git "a/src/main/java/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\203\214\345\214\205\351\227\256\351\242\230.md" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\203\214\345\214\205\351\227\256\351\242\230.md" similarity index 100% rename from "src/main/java/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\203\214\345\214\205\351\227\256\351\242\230.md" rename to "src/main/java/cc/tianbin/algorithm_practice/LeetCode/\345\212\250\346\200\201\350\247\204\345\210\222/\350\203\214\345\214\205\351\227\256\351\242\230.md" diff --git a/src/main/java/algorithm_practice/README.md b/src/main/java/cc/tianbin/algorithm_practice/README.md similarity index 100% rename from src/main/java/algorithm_practice/README.md rename to src/main/java/cc/tianbin/algorithm_practice/README.md diff --git a/src/main/java/algorithm_practice/SwordOffer/README.md b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/README.md similarity index 100% rename from src/main/java/algorithm_practice/SwordOffer/README.md rename to src/main/java/cc/tianbin/algorithm_practice/SwordOffer/README.md diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" index 8d9f3d6d..38918c71 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b02_\345\215\225\344\276\213\346\250\241\345\274\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" index 93e2fe60..d3c58062 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b03_\344\272\214\347\273\264\346\225\260\347\273\204\344\270\255\347\232\204\344\272\214\345\210\206\346\237\245\346\211\276.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 在一个二维数组中,每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" index 1c2ab14a..ae98e815 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b04_\346\233\277\346\215\242\347\251\272\346\240\274.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 自然想法,遇到空格就替换成'20%',长度是n的字符串,遇到一个空格,就需要向后移动n个字符,所以时间复杂度为O(N^2) diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" index fe96daec..be852925 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b05_\344\273\216\345\260\276\345\210\260\345\244\264\346\211\223\345\215\260\351\223\276\350\241\250.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import cc.tianbin.common.datastruct.ListNode; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" index 1b2e9cb4..17c8279f 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b06_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import java.util.HashMap; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" index f22426a3..c1ee36fc 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b07_\347\224\250\344\270\244\344\270\252\346\240\210\345\256\236\347\216\260\351\230\237\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" index 49c2e3f9..e3265ddd 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b08_\346\227\213\350\275\254\346\225\260\347\273\204\344\270\255\344\272\214\345\210\206\346\237\245\346\211\276\346\234\200\345\260\217\346\225\260\345\255\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 【题目】 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" similarity index 93% rename from "src/main/java/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" index b0362f9f..d9dcbf55 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b09_\346\226\220\346\263\242\351\202\243\345\245\221\346\225\260\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * Created by nibnait on 2016/9/20. diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" index 275c5f4e..fae72c5e 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/b10_\344\272\214\350\277\233\345\210\266\344\270\2551\347\232\204\344\270\252\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 典型的位运算 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" index 5a789b31..bff9064d 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c11_\346\225\260\345\200\274\347\232\204\346\225\264\346\225\260\346\254\241\346\226\271.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 实现函数double Power(double base, int exponent),求base的exponent次方。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" index 1f63fd42..54240805 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c12_\346\211\223\345\215\2601\345\210\260\346\234\200\345\244\247\347\232\204n\344\275\215\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 输入数字n,按顺序打印出从1最大的n位十进制数。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" similarity index 94% rename from "src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" index 241ac7ef..bbf30ab9 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c13_\345\210\240\351\231\244\351\223\276\350\241\250\347\273\223\347\202\271.java" @@ -1,9 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; -import common.util.SysOut; - -import static common.util.SysOut.printLinkedNode; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.SysOut; /** * 给定单向链表的头指针和一个结点指针,定义一个函数在0(1)时间删除该结点, diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" similarity index 94% rename from "src/main/java/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" index 2bb34c7a..8f7bbc29 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c14_\350\260\203\346\225\264\346\225\260\347\273\204\351\241\272\345\272\217\344\275\277\345\245\207\346\225\260\344\275\215\344\272\216\345\201\266\346\225\260\345\211\215\351\235\242.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SwapUtil; -import common.util.SysOut; +import cc.tianbin.common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; /** * 输入一个整数数组,实现一个函数来调整该数组中数字的顺序,使得所有奇数位于数组的前半部分,所有偶数位予数组的后半部分。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" index 7333d09b..530c4c33 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c15_\351\223\276\350\241\250\344\270\255\345\200\222\346\225\260\347\254\254k\344\270\252\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import cc.tianbin.common.datastruct.ListNode; /** * 题目:输入一个链表,输出该链表中倒数第k 个结点. diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" similarity index 94% rename from "src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" index c28754d0..25721ebb 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c16_\345\217\215\350\275\254\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.SysOut; /** * 题目:定义一个函数,输入一个链表的头结点,反转该链表并输出反转后链表的头结点。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" index eb4fd9f8..75b1f2f6 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c17_\345\220\210\345\271\266\344\270\244\344\270\252\346\216\222\345\272\217\347\232\204\351\223\276\350\241\250.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode; +import cc.tianbin.common.util.SysOut; /** * 题目:输入两个递增排序的链表,合并这两个链表并使新链表中的结点仍然是按照递增排序的 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" index 09814715..b88c3798 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/c18_\346\240\221\347\232\204\345\255\220\347\273\223\346\236\204.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; /** * 题目:输入两棵二叉树 A 和 B,判断 B 是不是 A 的子结构。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" index fa0b3845..e005ff14 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d19_\344\272\214\345\217\211\346\240\221\347\232\204\351\225\234\345\203\217.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.SysOut; /** * 题目:请完成一个函数,输入一个二叉树,该函数输出它的镜像。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" index fb4ef1e9..f69d76e7 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d20_\351\241\272\346\227\266\351\222\210\346\211\223\345\215\260\347\237\251\351\230\265.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:输入一个矩阵,按照从外向里以顺时针的顺序依次扫印出每一个数字 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" index 61d3ee03..5c8dddeb 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d21_\345\214\205\345\220\253min\345\207\275\346\225\260\347\232\204\346\240\210.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" index da9f34b6..009b90cb 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d22_\346\240\210\347\232\204\345\216\213\345\205\245$\345\274\271\345\207\272\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.Stack; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" index 736af070..0e6e928e 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d23_\344\273\216\344\270\212\345\276\200\344\270\213\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; import java.util.LinkedList; import java.util.Queue; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" index 17b7913d..b89292e8 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d24_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\345\220\216\345\272\217\351\201\215\345\216\206\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:输入一个整数数组,判断该数组是不是某二叉搜索树的后序遍历的结果。如果是则返回 true。否则返回 false。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" index 753c0e25..35ca37cc 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d25_\344\272\214\345\217\211\346\240\221\344\270\255\345\222\214\344\270\272\346\237\220\344\270\200\345\200\274\347\232\204\350\267\257\345\276\204.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; import java.util.ArrayList; import java.util.List; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" index da04a3d2..5f66814f 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d26_\345\244\215\346\235\202\351\223\276\350\241\250\347\232\204\345\244\215\345\210\266.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.HashMap; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" index 8d9d01bf..0bf770bd 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d27_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\344\270\216\345\217\214\345\220\221\351\223\276\350\241\250.java" @@ -1,12 +1,12 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; import java.util.LinkedList; import java.util.Queue; -import static common.util.SysOut.inOrderPrint; -import static common.util.SysOut.printDoubleLinkedList; +import static cc.tianbin.common.util.SysOut.inOrderPrint; +import static cc.tianbin.common.util.SysOut.printDoubleLinkedList; /** * 题目:输入一棵二叉搜索树,将该二叉搜索树转换成一个排序的双向链表。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" index 19339358..66a316d5 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\346\216\222\345\210\227.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SwapUtil; +import cc.tianbin.common.util.SwapUtil; import java.util.Arrays; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" index 9d096ae0..cc3aed55 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/d28_\345\255\227\347\254\246\344\270\262\347\232\204\347\273\204\345\220\210.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:输入一个字符串,打印出该字符串中字符的所有组合。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" index af26beef..361da71e 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e29_\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\346\254\241\346\225\260\350\266\205\350\277\207\344\270\200\345\215\212\347\232\204\346\225\260\345\255\227.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SwapUtil; +import cc.tianbin.common.util.SwapUtil; /** * 题目:数组中有一个数字出现的次数超过数组长度的一半,请找出这个数字 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" similarity index 92% rename from "src/main/java/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" index 2036a25a..7e7b6fee 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e30_\346\234\200\345\260\217\347\232\204k\344\270\252\346\225\260.java" @@ -1,9 +1,9 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SysOut; -import common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SwapUtil; -import static algorithm_practice.SwordOffer.old.e29_数组中出现次数超过一半的数字.partition; +import static cc.tianbin.algorithm_practice.SwordOffer.old.e29_数组中出现次数超过一半的数字.partition; /** * 题目: 输入n个整数,找出其中最小的k个数。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" index a7129946..c9d6f76d 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e31_\350\277\236\347\273\255\345\255\220\346\225\260\347\273\204\347\232\204\346\234\200\345\244\247\345\222\214.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:输入一个整型数组,数组里有正数也有负数。数组中一个或连续的多个整数组成一个子数组。求所有子数组的和的最大值。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" index 3d59857e..ece1f832 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e32_\344\273\2161\345\210\260n\346\225\264\346\225\260\344\270\2551\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:输入一个整数 n 求从 1 到 n 这 n 个整数的十进制表示中 1 出现的次数。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" index 04650406..52cb943c 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e33_\346\212\212\346\225\260\347\273\204\346\216\222\346\210\220\346\234\200\345\260\217\347\232\204\346\225\260.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SwapUtil; +import cc.tianbin.common.util.SwapUtil; import java.util.Comparator; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" index 85802756..6ce0c466 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e34_\344\270\221\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:我们把只包含因子 2、3 和 5 的数称作丑数(Ugly Number)。求从小到大的顺序的第 1500个丑数。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" index 9c2b40f5..db57c7ab 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e35_\347\254\254\344\270\200\344\270\252\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\345\255\227\347\254\246.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.HashMap; import java.util.Map; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" index 14ff46f5..88feb163 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e36_\346\225\260\347\273\204\344\270\255\347\232\204\351\200\206\345\272\217\345\257\271.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:在数组中的两个数字如果前面一个数字大于后面的数字,则这两个数字组成一个逆序对。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" index a75f963e..25bc7986 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/e37_\344\270\244\344\270\252\345\215\225\345\220\221\351\223\276\350\241\250\347\232\204\347\254\254\344\270\200\344\270\252\345\205\254\345\205\261\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode;; +import cc.tianbin.common.datastruct.ListNode;; /** * 题目:输入两个链表,找出它们的第一个公共结点。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" index af2c9551..610a86a7 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f38_\346\225\260\345\255\227\345\234\250\346\216\222\345\272\217\346\225\260\347\273\204\344\270\255\345\207\272\347\216\260\347\232\204\346\254\241\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:统计一个数字:在排序数组中出现的次数。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" similarity index 84% rename from "src/main/java/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" index d12f8fc9..f4ec6a41 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_1$\344\272\214\345\217\211\346\240\221\347\232\204\346\267\261\345\272\246.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; /** * 题目一:输入一棵二叉树的根结点,求该树的深度。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" index 6d4d7be9..7740eaf7 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f39_2$\345\210\244\346\226\255\344\272\214\345\217\211\346\240\221\346\230\257\345\220\246\345\271\263\350\241\241.java" @@ -1,8 +1,8 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; -import static algorithm_practice.SwordOffer.old.f39_1$二叉树的深度.TreeDepth; +import static cc.tianbin.algorithm_practice.SwordOffer.old.f39_1$二叉树的深度.TreeDepth; /** * 题目二:输入一棵二叉树的根结点,判断该树是不是平衡二叉树。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" index d08fef34..62e3e1c6 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f40_\346\225\260\347\273\204\344\270\255\345\217\252\345\207\272\347\216\260\344\270\200\346\254\241\347\232\204\346\225\260\345\255\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:一个整型数组里除了两个数字之外,其他的数字都出现了两次,请写程序找出这两个只出现一次的数字。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" similarity index 94% rename from "src/main/java/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" index 34e116ed..40e4fe68 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_1$\345\222\214\344\270\272s\347\232\204\344\270\244\344\270\252\346\225\260\345\255\227.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; /** * 题目一:输入一个递增排序的数组和一个数字 s,在数组中查找两个数,得它们的和正好是 s。如果有多对数字的和等于 s,输出任意一对即可。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" index 8d94c9a7..8b462ea1 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f41_2$\345\222\214\344\270\272s\347\232\204\350\277\236\347\273\255\346\255\243\346\225\260\345\272\217\345\210\227.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.ArrayList; import java.util.List; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" index 77b31678..f862031a 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_1$\347\277\273\350\275\254\345\215\225\350\257\215\351\241\272\345\272\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import org.apache.commons.lang3.StringUtils; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" similarity index 91% rename from "src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" index c4e1199a..e780f907 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f42_2$\345\267\246\346\227\213\350\275\254\345\255\227\347\254\246\344\270\262.java" @@ -1,8 +1,8 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import org.apache.commons.lang3.StringUtils; -import static algorithm_practice.SwordOffer.old.f42_1$翻转单词顺序.Reverse; +import static cc.tianbin.algorithm_practice.SwordOffer.old.f42_1$翻转单词顺序.Reverse; /** * 题目二:字符串的左旋转操作是把字符串前面的若干个字符转移到字符串的尾部。请定义一个函数实现字符串左旋转操作的功能。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" index 821a1a8e..0b449720 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f43_n\344\270\252\351\252\260\345\255\220\347\232\204\347\202\271\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:把 n 个骰子扔在地上,所有骰子朝上一面的点数之和为 s。输入 n,打印出 s 的所有可能的值出现的概率。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" index 9e8bf58b..fd9ca735 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f44_\346\211\221\345\205\213\347\211\214\347\232\204\351\241\272\345\255\220.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.Arrays; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" index 813a0c61..b120b1b3 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f45_\345\234\206\345\234\210\344\270\255\346\234\200\345\220\216\345\211\251\344\270\213\347\232\204\346\225\260\345\255\227$\347\272\246\347\221\237\345\244\253\347\216\257\346\235\200\344\272\272.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.LinkedList; import java.util.List; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" index 3426b466..ed8c09bb 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f46_\346\261\2021\345\210\260n\347\232\204\345\222\214.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:求1 + 2 + ···+ n, diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" index b863bb5e..d87ae248 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f47_\344\270\215\347\224\250\345\212\240\345\207\217\344\271\230\351\231\244\345\201\232\345\212\240\346\263\225.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:写一个函数,求两个整数之和,要求在函数体内不得使用+、-、×、÷四则运算符号。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" index 77810ee2..404fbe62 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/f48_\344\270\215\350\203\275\350\242\253\347\273\247\346\211\277\347\232\204\347\261\273.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:设计一个不能被继承的类 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" index 65caca0d..3dc30389 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g49_\346\212\212\345\255\227\347\254\246\344\270\262\350\275\254\346\215\242\346\210\220\346\225\264\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:实现一个函数 stringToInt,实现把字符串转换成整数这个功能,不能使用 atoi 或者其他类似的库函数。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" similarity index 99% rename from "src/main/java/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" index 6c258067..6daa47e1 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/g50_\346\240\221\344\270\255\344\270\244\344\270\252\347\273\223\347\202\271\347\232\204\346\234\200\344\275\216\345\205\254\345\205\261\347\245\226\345\205\210.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.Iterator; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" index 937ee80f..c5bc217e 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h51_\346\225\260\347\273\204\344\270\255\351\207\215\345\244\215\347\232\204\346\225\260\345\255\227.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SwapUtil; +import cc.tianbin.common.util.SwapUtil; /** * 题目:在一个长度为n的数组里的所有数字都在 0 到 n-1 的范围内。数组中某些数字是重复的,但不知道有几个数字重复了,也不知道每个数字重复了几次。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" index 3b653d87..ccecd6dd 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h52_\346\236\204\345\273\272\344\271\230\347\247\257\346\225\260\347\273\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.Arrays; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" index deabb9e3..d529c65b 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h53_\346\255\243\345\210\231\350\241\250\350\276\276\345\274\217\345\214\271\351\205\215.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:请实现一个函数用来匹配包含‘.’和‘*’的正则表达式。模式中的字符’.’表示任意一个字符,而‘*’表示它前面的字符可以出现任意次(含0次)。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" similarity index 99% rename from "src/main/java/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" index dd8ce118..ac162dcb 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h54_\350\241\250\347\244\272\346\225\260\345\200\274\347\232\204\345\255\227\347\254\246\344\270\262.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:请实现一个函数用来判断字符串是否表示数值(包括整数和小数)。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" index bd008865..0e64930a 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h55_\345\255\227\347\254\246\346\265\201\344\270\255\347\254\254\344\270\200\344\270\252\344\270\215\351\207\215\345\244\215\347\232\204\345\255\227\347\254\246.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import org.apache.commons.lang3.StringUtils; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" index 51de3dc2..684f3d41 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h56_\351\223\276\350\241\250\344\270\255\347\216\257\347\232\204\345\205\245\345\217\243\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode; +import cc.tianbin.common.datastruct.ListNode; /** * 题目:一个链表中包含环,如何找出环的入口结点? diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" index a976518a..0701fac8 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h57_\345\210\240\351\231\244\351\223\276\350\241\250\344\270\255\351\207\215\345\244\215\347\232\204\347\273\223\347\202\271.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.ListNode;; -import common.util.SysOut; +import cc.tianbin.common.datastruct.ListNode;; +import cc.tianbin.common.util.SysOut; /** * 题目:在一个排序的链表中,如何删除重复的结点? diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" index ba220030..61f696c9 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h58_\344\272\214\345\217\211\346\240\221\347\232\204\344\270\213\344\270\200\344\270\252\347\273\223\347\202\271.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNodeWithParent; +import cc.tianbin.common.datastruct.BinaryTreeNodeWithParent; /** * 题目:给定一棵二叉树和其中的一个结点,如何找出中序遍历顺序的下一个结点? diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" index b7bd432b..75be9a82 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h59_\345\257\271\347\247\260\347\232\204\344\272\214\345\217\211\346\240\221.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; /** * 题目:请实现一个函数来判断一棵二叉树是不是对称的。如果一棵二叉树和它的镜像一样,那么它是对称的。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" index 1fa6131f..97e031d1 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h60_\346\212\212\344\272\214\345\217\211\346\240\221\346\211\223\345\215\260\346\210\220\345\244\232\350\241\214.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; import java.util.LinkedList; import java.util.List; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" index ec7b9e7d..3c3d066c 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h61_\346\214\211\344\271\213\345\255\227\345\275\242\351\241\272\345\272\217\346\211\223\345\215\260\344\272\214\345\217\211\346\240\221.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; import java.util.LinkedList; import java.util.List; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" similarity index 97% rename from "src/main/java/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" index 6f673adf..690ea021 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h62_\345\272\217\345\210\227\345\214\226\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.SysOut; import java.util.LinkedList; import java.util.List; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" similarity index 94% rename from "src/main/java/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" index ef2368e0..0c4b5e71 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h63_\344\272\214\345\217\211\346\220\234\347\264\242\346\240\221\347\232\204\347\254\254k\344\270\252\347\273\223\347\202\271.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.datastruct.BinaryTreeNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.SysOut; /** * 题目:给定一棵二叉搜索树,请找出其中的第k大的结点。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" similarity index 99% rename from "src/main/java/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" index 08c08541..e3b6c8f0 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h64_\346\225\260\346\215\256\346\265\201\344\270\255\347\232\204\344\270\255\344\275\215\346\225\260.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; import java.util.ArrayList; import java.util.Comparator; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" index a387cd5e..87bb103d 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h65_\346\273\221\345\212\250\347\252\227\345\217\243\347\232\204\346\234\200\345\244\247\345\200\274.java" @@ -1,6 +1,6 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.LinkedList; diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" similarity index 99% rename from "src/main/java/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" index c9d8cb1a..c333733c 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h66_\347\237\251\351\230\265\344\270\255\347\232\204\350\267\257\345\276\204.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:请设计一个函数,用来判断在一个矩阵中是否存在一条包含某字符串所有字符的路径。 diff --git "a/src/main/java/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" similarity index 98% rename from "src/main/java/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" index a7369a0a..66e37224 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/old/h67_\346\234\272\345\231\250\344\272\272\347\232\204\350\277\220\345\212\250\350\214\203\345\233\264.java" @@ -1,4 +1,4 @@ -package algorithm_practice.SwordOffer.old; +package cc.tianbin.algorithm_practice.SwordOffer.old; /** * 题目:地上有个 m 行 n 列的方格。一个机器人从坐标(0,0)的格子开始移动, diff --git "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" similarity index 95% rename from "src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" index 93c214af..3227e207 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/MorrisTraversal.java" @@ -1,8 +1,8 @@ -package algorithm_practice.SwordOffer.树; +package cc.tianbin.algorithm_practice.SwordOffer.树; -import common.datastruct.TreeNode; -import common.util.binaryTree.ConstructBinaryTree; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.TreeNode; +import cc.tianbin.common.util.binaryTree.ConstructBinaryTree; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" index 99139d21..36690bf2 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\205\210\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.树; +package cc.tianbin.algorithm_practice.SwordOffer.树; -import common.datastruct.BinaryTreeNode; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" similarity index 96% rename from "src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" rename to "src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" index bddaa966..841969f8 100644 --- "a/src/main/java/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/SwordOffer/\346\240\221/b06_\346\240\271\346\215\256\345\220\216\345\272\217\345\222\214\344\270\255\345\272\217\346\225\260\347\273\204_\351\207\215\345\273\272\344\272\214\345\217\211\346\240\221.java" @@ -1,7 +1,7 @@ -package algorithm_practice.SwordOffer.树; +package cc.tianbin.algorithm_practice.SwordOffer.树; -import common.datastruct.BinaryTreeNode; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import junit.framework.TestCase; import org.junit.Test; diff --git a/src/main/java/algorithm_practice/a_Sorting/README.md b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/README.md similarity index 100% rename from src/main/java/algorithm_practice/a_Sorting/README.md rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/README.md diff --git a/src/main/java/algorithm_practice/a_Sorting/a_Bubble.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/a_Bubble.java similarity index 91% rename from src/main/java/algorithm_practice/a_Sorting/a_Bubble.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/a_Bubble.java index 90db2daf..62f7e8f8 100644 --- a/src/main/java/algorithm_practice/a_Sorting/a_Bubble.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/a_Bubble.java @@ -1,6 +1,6 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SwapUtil; +import cc.tianbin.common.util.SwapUtil; /** * Bubble_Sort diff --git a/src/main/java/algorithm_practice/a_Sorting/a_Selection.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/a_Selection.java similarity index 84% rename from src/main/java/algorithm_practice/a_Sorting/a_Selection.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/a_Selection.java index 0883ca74..9f19a828 100644 --- a/src/main/java/algorithm_practice/a_Sorting/a_Selection.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/a_Selection.java @@ -1,8 +1,8 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SwapUtil; -import common.util.SysOut; -import common.util.SysRandom; +import cc.tianbin.common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SysRandom; /** * Selection_Sort * 时间复杂度:O(n^2) diff --git a/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/b_Insertion.java similarity index 78% rename from src/main/java/algorithm_practice/a_Sorting/b_Insertion.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/b_Insertion.java index aa958061..4bb9b73a 100644 --- a/src/main/java/algorithm_practice/a_Sorting/b_Insertion.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/b_Insertion.java @@ -1,8 +1,8 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SwapUtil; -import common.util.SysOut; -import common.util.SysRandom; +import cc.tianbin.common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SysRandom; /** * Created by nibnait on 2016/8/7. diff --git a/src/main/java/algorithm_practice/a_Sorting/c_Shell.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/c_Shell.java similarity index 89% rename from src/main/java/algorithm_practice/a_Sorting/c_Shell.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/c_Shell.java index d3e71a1c..449c3421 100644 --- a/src/main/java/algorithm_practice/a_Sorting/c_Shell.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/c_Shell.java @@ -1,7 +1,7 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SysOut; -import common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SwapUtil; /** * Created by nibnait on 2016/8/7. diff --git a/src/main/java/algorithm_practice/a_Sorting/d_Merge.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/d_Merge.java similarity index 90% rename from src/main/java/algorithm_practice/a_Sorting/d_Merge.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/d_Merge.java index 1c7cb9f2..f0e48628 100644 --- a/src/main/java/algorithm_practice/a_Sorting/d_Merge.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/d_Merge.java @@ -1,8 +1,8 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SysOut; -import common.util.SysRandom; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SysRandom; /** * Created by nibnait on 2016/8/8. diff --git a/src/main/java/algorithm_practice/a_Sorting/e_Quick.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/e_Quick.java similarity index 91% rename from src/main/java/algorithm_practice/a_Sorting/e_Quick.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/e_Quick.java index 23fee988..6965c26c 100644 --- a/src/main/java/algorithm_practice/a_Sorting/e_Quick.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/e_Quick.java @@ -1,7 +1,7 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SysOut; -import common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SwapUtil; /** * Created by nibnait on 2016/8/9. diff --git a/src/main/java/algorithm_practice/a_Sorting/f_Heap.java b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/f_Heap.java similarity index 92% rename from src/main/java/algorithm_practice/a_Sorting/f_Heap.java rename to src/main/java/cc/tianbin/algorithm_practice/a_Sorting/f_Heap.java index be3dc857..c167742b 100644 --- a/src/main/java/algorithm_practice/a_Sorting/f_Heap.java +++ b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/f_Heap.java @@ -1,7 +1,7 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; -import common.util.SysOut; -import common.util.SwapUtil; +import cc.tianbin.common.util.SysOut; +import cc.tianbin.common.util.SwapUtil; /** * Created by nibnait on 2016/8/10. diff --git "a/src/main/java/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" similarity index 98% rename from "src/main/java/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" index 06860f11..503390fd 100644 --- "a/src/main/java/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\345\237\272\346\225\260\346\216\222\345\272\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; /** * Radix_Sort diff --git "a/src/main/java/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" "b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" similarity index 96% rename from "src/main/java/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" rename to "src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" index 9ec7314b..6b32099f 100644 --- "a/src/main/java/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/a_Sorting/g_\350\256\241\346\225\260\346\216\222\345\272\217_\346\241\266\346\216\222\345\272\217.java" @@ -1,4 +1,4 @@ -package algorithm_practice.a_Sorting; +package cc.tianbin.algorithm_practice.a_Sorting; /** * 一些时间复杂度趋近于O(N)的排序算法 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/SlidingWindowMaxValue.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype/SlidingWindowMaxValue.java similarity index 90% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/SlidingWindowMaxValue.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype/SlidingWindowMaxValue.java index b9d48ea1..1f60e0e5 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/SlidingWindowMaxValue.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype/SlidingWindowMaxValue.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810; +package cc.tianbin.algorithm_practice.nowcoder.AlgorithmPrototype; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java similarity index 91% rename from src/main/java/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java index 516c40a1..ec40f0e8 100644 --- a/src/main/java/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/AlgorithmPrototype/SubArrayMaxSum.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.AlgorithmPrototype; +package cc.tianbin.algorithm_practice.nowcoder.AlgorithmPrototype; /** * 子数组最大和(leetcode 53) diff --git a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java index 7cca3ada..8d11f77f 100644 --- a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.a_1st_Season.aa_Manacher_bfprt_KMP; +package cc.tianbin.algorithm_practice.nowcoder.a_1st_Season.aa_Manacher_bfprt_KMP; /** * 字符串匹配问题 diff --git "a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP\347\256\227\346\263\225.md" "b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP\347\256\227\346\263\225.md" similarity index 100% rename from "src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP\347\256\227\346\263\225.md" rename to "src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/KMP\347\256\227\346\263\225.md" diff --git a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java index 387fbe91..ae98735d 100644 --- a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.a_1st_Season.aa_Manacher_bfprt_KMP; +package cc.tianbin.algorithm_practice.nowcoder.a_1st_Season.aa_Manacher_bfprt_KMP; /** * 求 最长回文字串的长度 diff --git "a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher\347\256\227\346\263\225.md" "b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher\347\256\227\346\263\225.md" similarity index 100% rename from "src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher\347\256\227\346\263\225.md" rename to "src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/Manacher\347\256\227\346\263\225.md" diff --git a/src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/a_1st_Season/aa_Manacher_bfprt_KMP/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java index 109dab49..cf2c7bdb 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/RussianDollEnvelopes.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.ba160720; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.ba160720; import java.util.Arrays; import java.util.Comparator; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java index 4f70ffa4..91fa030a 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/TrappingRainWater.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.ba160720; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.ba160720; /** * 雨水补漏(leetCode42) diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java index 1e7cbd89..1dfe85e7 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/ba160720/arrUp.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.ba160720; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.ba160720; /** * 求最长递增子序列的长度 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java similarity index 91% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java index a5127fe7..2efa19d4 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/a_SubArrayMaxSum.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bb160727; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bb160727; /** * 子数组最大和(leetcode 53) diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java similarity index 93% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java index 236c7994..e95a8395 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/b_TwoSubArrayMaxSum.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bb160727; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bb160727; /** * 求两个子数组最大的累加和 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java index f9acf9cc..a03c5843 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bb160727/c_MaxLength.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bb160727; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bb160727; -import common.datastruct.BinarySearch; +import cc.tianbin.common.datastruct.BinarySearch; import java.util.HashMap; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java similarity index 93% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java index 89684a04..9c923013 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/CompleteTreeNodeNumber.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; public class CompleteTreeNodeNumber { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java similarity index 92% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java index 579f0096..7ef95ed4 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/LongestLessSumSubArrayLength.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; -import common.datastruct.BinarySearch; +import cc.tianbin.common.datastruct.BinarySearch; public class LongestLessSumSubArrayLength { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java similarity index 89% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java index 1bac9a66..df1ee668 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaxSubMatrixSumLessK.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; -import common.datastruct.BinarySearch; +import cc.tianbin.common.datastruct.BinarySearch; public class MaxSubMatrixSumLessK { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java similarity index 94% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java index cc629ed4..d2663d30 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/MaximalRectangle.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java similarity index 92% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java index 0c99416a..b0313007 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/PrefixCheck.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; import java.util.HashMap; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java similarity index 91% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java index 8f5939fa..81d5bed1 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubArrayMaxSum.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; public class SubArrayMaxSum { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java similarity index 90% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java index 0772377e..a37a008f 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bc160803/src/SubMatrixMaxSum.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bc160803.src; public class SubMatrixMaxSum { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/AlgorithmPrototype/SlidingWindowMaxValue.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/SlidingWindowMaxValue.java similarity index 90% rename from src/main/java/algorithm_practice/nowcoder/AlgorithmPrototype/SlidingWindowMaxValue.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/SlidingWindowMaxValue.java index cfcf2c0a..73fea00d 100644 --- a/src/main/java/algorithm_practice/nowcoder/AlgorithmPrototype/SlidingWindowMaxValue.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/SlidingWindowMaxValue.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.AlgorithmPrototype; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java index 77296ecf..82680bd0 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ExpressionCompute.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java index aef9e1b2..c338620a 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/GetMinStack.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java similarity index 90% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java index c60ed64c..f504292d 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/ReverseStackUsingRecursive.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java similarity index 92% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java index 18507500..8970c518 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/SlidingWindowMaxArray.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java index 004d7baa..dfa55295 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoQueuesImplementStack.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java similarity index 94% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java index 5ce0fb68..4af1ae1d 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bd160810/src/TwoStacksImplementQueue.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bd160810.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java index ce4d3a3e..1099454e 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/AllLessNumSubArray.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.be160817.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.be160817.src; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java index 64de3543..ed737f18 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/DogCat.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.be160817.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.be160817.src; import java.util.LinkedList; import java.util.Queue; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java similarity index 98% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java index 9e6368d8..658bfd1d 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/Hanoi.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.be160817.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.be160817.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java index 00559071..385de486 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/be160817/src/MaxTree.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.be160817.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.be160817.src; import java.util.HashMap; import java.util.Map.Entry; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java index 863bd01f..6b5cab29 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/CopyListWithRandom.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; import java.util.HashMap; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java similarity index 98% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java index 31ee8d01..e76cff8c 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/FindFirstIntersectNode.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; public class FindFirstIntersectNode { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java similarity index 98% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java index e709a7cc..a60d9217 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/IsPalindromeList.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java index ae59b792..1f7d4dca 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/Josephus.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; public class Josephus { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java similarity index 94% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java index 384ae939..62ab33ea 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bf160824/src/RemoveNodeWired.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bf160824.src; public class RemoveNodeWired { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java similarity index 98% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java index 55b936de..22a5be79 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/BSTtoDoubleLinkedList.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bg160831.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bg160831.src; import java.util.LinkedList; import java.util.Queue; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java similarity index 93% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java index afaa9793..e3296054 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/KMPAlgorithm.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bg160831.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bg160831.src; public class KMPAlgorithm { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java similarity index 94% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java index 87142d4e..76555c74 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bg160831/src/LongestSubarrayLessSumAwesomeSolution.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bg160831.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bg160831.src; -import common.datastruct.BinarySearch; +import cc.tianbin.common.datastruct.BinarySearch; import java.util.HashMap; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java similarity index 87% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java index 2965119b..47453b9b 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/BiggestSubBSTInTree.java @@ -1,7 +1,7 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907; -import common.datastruct.BinaryTreeNode; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; /** * 找到二叉树中的最大搜索二叉子树 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java index 861b1bef..7aa6b890 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/PreInPosTraversal.java @@ -1,7 +1,7 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907; -import common.datastruct.BinaryTreeNode; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java index cb9e09b8..90f13afd 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_01_PreInPosTraversal.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java index 3243df1f..ef343dba 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_03_PrintBinaryTree.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; public class Problem_03_PrintBinaryTree { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java index 61a007a3..649e8a70 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_06_LongestPathSum.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; import java.util.HashMap; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java index 5266e40c..fb933dd0 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_07_BiggestSubBSTInTree.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; public class Problem_07_BiggestSubBSTInTree { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java index 049d6771..755296a4 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bh160907/src/Problem_20_MaxDistanceInTree.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bh160907.src; public class Problem_20_MaxDistanceInTree { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java index c27c19e0..724a8783 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/BiggestBSTTopologyInTree.java @@ -1,7 +1,7 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bi160914; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bi160914; -import common.datastruct.BinaryTreeNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.SysOut; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java index 7dcfd4a2..6f24b7f2 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/MorrisTraversal.java @@ -1,7 +1,7 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bi160914; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bi160914; -import common.datastruct.BinaryTreeNode; -import common.util.binaryTree.PrintBinaryTree; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.binaryTree.PrintBinaryTree; /** * 二叉树的神级遍历 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java similarity index 98% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java index 77179b4c..c60c0b47 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_05_MorrisTraversal.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bi160914.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bi160914.src; public class Problem_05_MorrisTraversal { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java similarity index 98% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java index 4a8835cc..b96416ff 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_08_BiggestBSTTopologyInTree.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bi160914.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bi160914.src; import java.util.HashMap; import java.util.Map; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java index 26f29cb7..0378b561 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bi160914/src/Problem_17_DescendantNode.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bi160914.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bi160914.src; public class Problem_17_DescendantNode { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java similarity index 83% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java index 51b151f2..4235ccdf 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsBalancedBinaryTree.java @@ -1,7 +1,7 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; /** * 判断一棵二叉树是否为 平衡二叉树 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java similarity index 90% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java index 0c621869..0b9b89a4 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsCompleteBinaryTree.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; import java.util.LinkedList; import java.util.Queue; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java similarity index 89% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java index 283141d1..553a0137 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/IsSearchBinaryTree.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; /** * 判断一棵二叉树是否为搜索二叉树 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java similarity index 64% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java index 06678def..e45592b4 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/RecoverBST.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928; -import common.datastruct.BinaryTreeNode; +import cc.tianbin.common.datastruct.BinaryTreeNode; /** * 先挖个坑,争取一周之内填上 diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java index 7a626e80..193ee95e 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_09_PrintBinaryTreeByLevelAndZigZag.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; import java.util.Deque; import java.util.LinkedList; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java similarity index 99% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java index f2144556..6ccac638 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_10_RecoverBST.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; import java.util.Stack; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java similarity index 92% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java index 8f02500f..c6f2bebf 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_13_IsBalancedTree.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; public class Problem_13_IsBalancedTree { diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java similarity index 97% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java index 81ccf1fa..2f2c17b0 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/src/Problem_15_IsBSTAndCBT.java @@ -1,4 +1,4 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928.src; import java.util.LinkedList; import java.util.Queue; diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java similarity index 96% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java index ff5e8c39..78640598 100644 --- a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bj160928/testRecoverBST.java @@ -1,10 +1,10 @@ -package algorithm_practice.nowcoder.b_2nd_Season.bj160928; +package cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928; -import common.datastruct.BinaryTreeNode; -import common.util.SysOut; +import cc.tianbin.common.datastruct.BinaryTreeNode; +import cc.tianbin.common.util.SysOut; -import static algorithm_practice.nowcoder.b_2nd_Season.bj160928.IsSearchBinaryTree.isBST; -import static algorithm_practice.nowcoder.b_2nd_Season.bj160928.RecoverBST.recoverTree; +import static cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928.IsSearchBinaryTree.isBST; +import static cc.tianbin.algorithm_practice.nowcoder.b_2nd_Season.bj160928.RecoverBST.recoverTree; /** * Created by nibnait on 2016/10/9. diff --git a/src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bk161012/README.md b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bk161012/README.md similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/b_2nd_Season/bk161012/README.md rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/b_2nd_Season/bk161012/README.md diff --git a/src/main/java/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java similarity index 95% rename from src/main/java/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java index c0a701fa..c275f6f8 100644 --- a/src/main/java/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java +++ b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/book/BinaryTree/getPosArray.java @@ -1,6 +1,6 @@ -package algorithm_practice.nowcoder.book.BinaryTree; +package cc.tianbin.algorithm_practice.nowcoder.book.BinaryTree; -import common.util.SysOut; +import cc.tianbin.common.util.SysOut; import java.util.HashMap; diff --git a/src/main/java/algorithm_practice/nowcoder/image/KMP-1.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/KMP-1.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/KMP-1.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/KMP-1.png diff --git "a/src/main/java/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-1.png" "b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-1.png" similarity index 100% rename from "src/main/java/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-1.png" rename to "src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-1.png" diff --git "a/src/main/java/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-2.png" "b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-2.png" similarity index 100% rename from "src/main/java/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-2.png" rename to "src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/Manacher\347\256\227\346\263\225-2.png" diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbb16072701.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbb16072701.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbb16072701.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbb16072701.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbb16072702.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbb16072702.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbb16072702.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbb16072702.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbc16080301.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbc16080301.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbc16080301.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbc16080301.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbc16080302.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbc16080302.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbc16080302.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbc16080302.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbc16080303.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbc16080303.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbc16080303.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbc16080303.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbd16081001.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbd16081001.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbd16081001.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbd16081001.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbf16082401.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbf16082401.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbf16082401.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbf16082401.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbf16082402.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbf16082402.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbf16082402.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbf16082402.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbi16091401.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbi16091401.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbi16091401.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbi16091401.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbj16092801.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbj16092801.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbj16092801.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbj16092801.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbj16092802.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbj16092802.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbj16092802.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbj16092802.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101201.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101201.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101201.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101201.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101202.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101202.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101202.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101202.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101203.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101203.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101203.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101203.png diff --git a/src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101204.png b/src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101204.png similarity index 100% rename from src/main/java/algorithm_practice/nowcoder/image/nowcoderbk16101204.png rename to src/main/java/cc/tianbin/algorithm_practice/nowcoder/image/nowcoderbk16101204.png diff --git a/src/main/java/common/CommonConstants.java b/src/main/java/cc/tianbin/common/CommonConstants.java similarity index 88% rename from src/main/java/common/CommonConstants.java rename to src/main/java/cc/tianbin/common/CommonConstants.java index e71bea57..ce5050c6 100644 --- a/src/main/java/common/CommonConstants.java +++ b/src/main/java/cc/tianbin/common/CommonConstants.java @@ -1,4 +1,4 @@ -package common; +package cc.tianbin.common; /** * Created by nibnait on 2022/06/21 diff --git a/src/main/java/common/context/ApplicationContextHelper.java b/src/main/java/cc/tianbin/common/context/ApplicationContextHelper.java similarity index 98% rename from src/main/java/common/context/ApplicationContextHelper.java rename to src/main/java/cc/tianbin/common/context/ApplicationContextHelper.java index e782af88..fd75a7bd 100644 --- a/src/main/java/common/context/ApplicationContextHelper.java +++ b/src/main/java/cc/tianbin/common/context/ApplicationContextHelper.java @@ -1,4 +1,4 @@ -package common.context; +package cc.tianbin.common.context; import io.github.nibnait.common.exception.ServiceException; import lombok.extern.slf4j.Slf4j; diff --git a/src/main/java/common/datastruct/BinarySearch.java b/src/main/java/cc/tianbin/common/datastruct/BinarySearch.java similarity index 94% rename from src/main/java/common/datastruct/BinarySearch.java rename to src/main/java/cc/tianbin/common/datastruct/BinarySearch.java index 49f2f7d7..59bf345d 100644 --- a/src/main/java/common/datastruct/BinarySearch.java +++ b/src/main/java/cc/tianbin/common/datastruct/BinarySearch.java @@ -1,4 +1,4 @@ -package common.datastruct; +package cc.tianbin.common.datastruct; /** * Created by nibnait on 2016/10/2. diff --git a/src/main/java/common/datastruct/BinaryTreeNode.java b/src/main/java/cc/tianbin/common/datastruct/BinaryTreeNode.java similarity index 91% rename from src/main/java/common/datastruct/BinaryTreeNode.java rename to src/main/java/cc/tianbin/common/datastruct/BinaryTreeNode.java index 1ee1ee69..b62dfcfc 100644 --- a/src/main/java/common/datastruct/BinaryTreeNode.java +++ b/src/main/java/cc/tianbin/common/datastruct/BinaryTreeNode.java @@ -1,4 +1,4 @@ -package common.datastruct; +package cc.tianbin.common.datastruct; /** * 《剑指offer》二叉树结点 diff --git a/src/main/java/common/datastruct/BinaryTreeNodeWithParent.java b/src/main/java/cc/tianbin/common/datastruct/BinaryTreeNodeWithParent.java similarity index 92% rename from src/main/java/common/datastruct/BinaryTreeNodeWithParent.java rename to src/main/java/cc/tianbin/common/datastruct/BinaryTreeNodeWithParent.java index 996c2056..62cdb2da 100644 --- a/src/main/java/common/datastruct/BinaryTreeNodeWithParent.java +++ b/src/main/java/cc/tianbin/common/datastruct/BinaryTreeNodeWithParent.java @@ -1,4 +1,4 @@ -package common.datastruct; +package cc.tianbin.common.datastruct; /** * Created by nibnait on 2016/10/3. diff --git a/src/main/java/common/datastruct/ListNode.java b/src/main/java/cc/tianbin/common/datastruct/ListNode.java similarity index 93% rename from src/main/java/common/datastruct/ListNode.java rename to src/main/java/cc/tianbin/common/datastruct/ListNode.java index 8b33e79c..d741e0d7 100644 --- a/src/main/java/common/datastruct/ListNode.java +++ b/src/main/java/cc/tianbin/common/datastruct/ListNode.java @@ -1,4 +1,4 @@ -package common.datastruct; +package cc.tianbin.common.datastruct; /** * LeetCode 链表结点 diff --git a/src/main/java/common/datastruct/Node.java b/src/main/java/cc/tianbin/common/datastruct/Node.java similarity index 90% rename from src/main/java/common/datastruct/Node.java rename to src/main/java/cc/tianbin/common/datastruct/Node.java index 0f714f71..52979d10 100644 --- a/src/main/java/common/datastruct/Node.java +++ b/src/main/java/cc/tianbin/common/datastruct/Node.java @@ -1,4 +1,4 @@ -package common.datastruct; +package cc.tianbin.common.datastruct; import lombok.NoArgsConstructor; diff --git a/src/main/java/common/datastruct/TreeNode.java b/src/main/java/cc/tianbin/common/datastruct/TreeNode.java similarity index 92% rename from src/main/java/common/datastruct/TreeNode.java rename to src/main/java/cc/tianbin/common/datastruct/TreeNode.java index 10072fa5..17408ff9 100644 --- a/src/main/java/common/datastruct/TreeNode.java +++ b/src/main/java/cc/tianbin/common/datastruct/TreeNode.java @@ -1,4 +1,4 @@ -package common.datastruct; +package cc.tianbin.common.datastruct; /** * LeetCode 二叉树结点 diff --git a/src/main/java/common/enums/ErrorCode.java b/src/main/java/cc/tianbin/common/enums/ErrorCode.java similarity index 89% rename from src/main/java/common/enums/ErrorCode.java rename to src/main/java/cc/tianbin/common/enums/ErrorCode.java index 5e5fe9b6..4f2501e8 100644 --- a/src/main/java/common/enums/ErrorCode.java +++ b/src/main/java/cc/tianbin/common/enums/ErrorCode.java @@ -1,4 +1,4 @@ -package common.enums; +package cc.tianbin.common.enums; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/src/main/java/common/model/Person.java b/src/main/java/cc/tianbin/common/model/Person.java similarity index 97% rename from src/main/java/common/model/Person.java rename to src/main/java/cc/tianbin/common/model/Person.java index 12a88768..543bac3b 100644 --- a/src/main/java/common/model/Person.java +++ b/src/main/java/cc/tianbin/common/model/Person.java @@ -1,4 +1,4 @@ -package common.model; +package cc.tianbin.common.model; import lombok.AllArgsConstructor; import lombok.Data; diff --git a/src/main/java/common/model/PersonDTO.java b/src/main/java/cc/tianbin/common/model/PersonDTO.java similarity index 89% rename from src/main/java/common/model/PersonDTO.java rename to src/main/java/cc/tianbin/common/model/PersonDTO.java index 3376e85a..9947d8cf 100644 --- a/src/main/java/common/model/PersonDTO.java +++ b/src/main/java/cc/tianbin/common/model/PersonDTO.java @@ -1,4 +1,4 @@ -package common.model; +package cc.tianbin.common.model; import lombok.Data; diff --git a/src/main/java/common/util/AssertUtils.java b/src/main/java/cc/tianbin/common/util/AssertUtils.java similarity index 83% rename from src/main/java/common/util/AssertUtils.java rename to src/main/java/cc/tianbin/common/util/AssertUtils.java index 85533a61..8028fb9a 100644 --- a/src/main/java/common/util/AssertUtils.java +++ b/src/main/java/cc/tianbin/common/util/AssertUtils.java @@ -1,8 +1,7 @@ -package common.util; +package cc.tianbin.common.util; -import common.datastruct.ListNode; +import cc.tianbin.common.datastruct.ListNode; import io.github.nibnait.common.utils.DataUtils; -import io.github.nibnait.common.utils.compare.CompareUtils; import java.util.List; @@ -17,7 +16,7 @@ private AssertUtils() { } public static void compareListList(List> expect, List> actual, int[] nums) { - if (!common.util.CompareUtils.compareListList(expect, actual)) { + if (!CompareUtils.compareListList(expect, actual)) { LogUtil.log("nums: {}", nums); LogUtil.log("except: {}", DataUtils.toJsonStringArray(expect)); LogUtil.log("actual: {}", DataUtils.toJsonStringArray(actual)); @@ -26,7 +25,7 @@ public static void compareListList(List> expect, List { +// double acquire = limiter.acquire(1); +// System.out.println(index + " \t" + acquire + " \t" +// + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); +// }); +// } +// +// Thread.sleep(5 * 1000L); +// } +// +// @Test +// public void tryAcquire() throws Exception { +// for (int i = 0; i < 10; i++) { +// final int index = i; +// +// pool.execute(() -> { +// boolean acquire = limiter.tryAcquire(); +// System.out.println(index + " \t" + acquire + " \t" +// + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); +// }); +// } +// +// Thread.sleep(5 * 1000L); +// } +// +// @Test +// public void tryAcquireTimeout() throws Exception { +// for (int i = 0; i < 10; i++) { +// final int index = i; +// +// pool.execute(() -> { +// boolean acquire = limiter.tryAcquire(1000L, TimeUnit.MILLISECONDS); +// System.out.println(index + " \t" + acquire + " \t" +// + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); +// }); +// } +// +// Thread.sleep(5 * 1000L); +// } +// +// @Test +// public void batchAcquireLazy() throws Exception { +// JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); +// jedisPoolConfig.setMaxTotal(50); +// JedisPool jedisPool = new JedisPool(jedisPoolConfig, "localhost"); +// +// RedisRateLimiter redisRateLimiter = RedisRateLimiter.create("500", 1000, jedisPool, true); +// redisRateLimiter.setBatchSize(50); +// +// for (int i = 0; i < 1000; i++) { +// final String index = String.format("%3d", i); +// +// pool.execute(() -> { +// double acquire = redisRateLimiter.acquireLazy(10); +// System.out.println(index + " \t" + acquire + " \t" +// + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); +// }); +// } +// +// Thread.sleep(5 * 1000L); +// } +// +} diff --git a/src/main/test/cc/tianbin/demo/temp/JsonParseTest.java b/src/main/test/cc/tianbin/demo/temp/JsonParseTest.java new file mode 100644 index 00000000..400d56b1 --- /dev/null +++ b/src/main/test/cc/tianbin/demo/temp/JsonParseTest.java @@ -0,0 +1,29 @@ +package cc.tianbin.demo.temp; + +/** + * Created by nibnait on 2020-02-25 + */ +public class JsonParseTest { + +// @Test + public void test() { +// String s = JSON.toJSONString(null); +// System.out.println(s); + } + +// @Test + public void testCase() { + +// String attribute_json = "{\"active_at\":1582566155,\"user_name\":\"32a9bd7c2\"}"; +// JSONObject jsonObject = JSONObject.parseObject(attribute_json); +// System.out.println(jsonObject); +// String is_from_tp_new_retail = jsonObject.getString("is_from_tp_new_retail"); +// System.out.println(is_from_tp_new_retail); +// +// if (StringUtils.isNotBlank(attribute_json) && jsonObject.getString("is_from_tp_new_retail") == "1") { +// System.out.println("asdfsafsafsa"); +// } + } + + +} \ No newline at end of file diff --git a/src/main/test/cc/tianbin/excel/ExcelGen.java b/src/main/test/cc/tianbin/excel/ExcelGen.java deleted file mode 100644 index 65beead4..00000000 --- a/src/main/test/cc/tianbin/excel/ExcelGen.java +++ /dev/null @@ -1,65 +0,0 @@ -package cc.tianbin.excel; - -import com.google.common.collect.Lists; -import io.github.nibnait.common.bo.email.EmailAccount; -import io.github.nibnait.common.bo.email.EmailBO; -import io.github.nibnait.common.bo.excel.SheetBO; -import io.github.nibnait.common.bo.excel.WorkBookBO; -import io.github.nibnait.common.utils.EmailUtils; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; - -import java.io.File; -import java.time.LocalDateTime; -import java.time.format.DateTimeFormatter; - -/** - * Created by nibnait on 2021/01/21 - */ -public class ExcelGen { - - @Test - public void test() { - System.out.println(StringUtils.isBlank(" ")); - } - - private static final String DELAY_DELIVERY_REPORT_FILE_NAME = "报表-%s"; - public static final String DATE_TIME_FORMAT = "yyyyMMdd-HHmm"; - - @Test - public void excelGen() throws Exception { - - String targetFileName = String.format(DELAY_DELIVERY_REPORT_FILE_NAME, - getNowDateTime(DATE_TIME_FORMAT)); - - WorkBookBO workBookBO = new WorkBookBO(); - SheetBO sheet = workBookBO.getSheetList().get(0); - - xiegehanshu(sheet); - - File delay_delivery_report = workBookBO.writeToDefaultLocalPath(targetFileName); - - System.out.println(delay_delivery_report.getName()); - - EmailUtils.sendEmailThrowException(new EmailAccount(), new EmailBO()); - } - - public static String getNowDateTime(String dateFormat) { - return LocalDateTime.now().format(DateTimeFormatter.ofPattern(dateFormat)); - } - - - private void xiegehanshu(SheetBO sheet) { - sheet.appendRow(Lists.newArrayList("123", "234")); - } - - private String getEmailContent() { - StringBuilder content = new StringBuilder("

Hi All:

"); - content.append("    "); - content.append("2021年1月21日"); - content.append(" 报表如下,请核实:"); - content.append("
"); - content.append("
"); - return content.toString(); - } -} diff --git a/src/main/test/cc/tianbin/excel/ParseJson.java b/src/main/test/cc/tianbin/excel/ParseJson.java deleted file mode 100644 index 00843d96..00000000 --- a/src/main/test/cc/tianbin/excel/ParseJson.java +++ /dev/null @@ -1,30 +0,0 @@ -package cc.tianbin.excel; - -import com.google.common.collect.Lists; -import io.github.nibnait.common.bo.excel.SheetBO; -import io.github.nibnait.common.bo.excel.WorkBookBO; -import io.github.nibnait.common.utils.DataUtils; - -import java.util.List; - -/** - * Created by nibnait on 2022/01/18 - */ -public class ParseJson { - - public static void main(String[] args) { - String str = "[{\"skuId\":1000098016,\"stock\":239,\"frozenStock\":583,\"outStock\":0,\"isolateStock\":0,\"purchaseStock\":840,\"warehouseIds\":\"\",\"warnStock\":1,\"frozenUndeliveryStock\":0,\"ctime\":1623744663000,\"mtime\":1642147764000,\"boxNum\":0,\"onsaleBoxNum\":0}]"; - List stockDTOS = DataUtils.parseArray(str, StockDTO.class); - - WorkBookBO workBookBO = new WorkBookBO(); - SheetBO sheetBO = workBookBO.getSheetList().get(0); - - for (StockDTO stockDTO : stockDTOS) { - sheetBO.appendRow(Lists.newArrayList(stockDTO.getSkuId()+"", stockDTO.getStock()+"")); - } - - workBookBO.writeToDefaultLocalPath("stock"); - - } - -} diff --git a/src/main/test/cc/tianbin/excel/StockDTO.java b/src/main/test/cc/tianbin/excel/StockDTO.java deleted file mode 100644 index 620acf43..00000000 --- a/src/main/test/cc/tianbin/excel/StockDTO.java +++ /dev/null @@ -1,80 +0,0 @@ -package cc.tianbin.excel; - -import lombok.Data; - -import java.util.Date; - -/** - * Created by nibnait on 2022/01/18 - */ -@Data -public class StockDTO { - - private static final long serialVersionUID = -503150452346799617L; - - /** - * sku_id - */ - private Long skuId; - - /** - * 可售库存 - */ - private Integer stock; - - /** - * 冻结库存 - */ - private Integer frozenStock; - - /** - * 出库库存 - */ - private Integer outStock; - - /** - * 隔离库存 - */ - private Integer isolateStock; - - /** - * 采购库存 - */ - private Integer purchaseStock; - - /** - * 仓库id - */ - private String warehouseIds; - - /** - * 预警库存 - */ - private Integer warnStock; - - /** - * 待下发冻结 - */ - private Integer frozenUndeliveryStock; - - /** - * 创建时间 - */ - private Date ctime; - - /** - * 修改时间 - */ - private Date mtime; - - /** - * 一番赏箱子数量 - */ - private Integer boxNum; - - - /** - * 一番赏箱子数量 - */ - private Integer onsaleBoxNum; -} diff --git a/src/main/test/cc/tianbin/java/ObjectTest.java b/src/main/test/cc/tianbin/java/ObjectTest.java deleted file mode 100644 index 187138c2..00000000 --- a/src/main/test/cc/tianbin/java/ObjectTest.java +++ /dev/null @@ -1,19 +0,0 @@ -package cc.tianbin.java; - -import org.junit.Test; - -/** - * Created by nibnait on 2021/04/01 - */ -public class ObjectTest { - - @Test - public void testEquals() { - Byte saleType = null; - Byte saleType1 = 1; - - boolean equals = saleType1.equals(saleType); - System.out.println(equals); - - } -} diff --git a/src/main/test/java/lang/test/String.class b/src/main/test/cc/tianbin/java/lang/test/String.class similarity index 100% rename from src/main/test/java/lang/test/String.class rename to src/main/test/cc/tianbin/java/lang/test/String.class diff --git a/src/main/test/java/lang/test/String_.java b/src/main/test/cc/tianbin/java/lang/test/String_.java similarity index 100% rename from src/main/test/java/lang/test/String_.java rename to src/main/test/cc/tianbin/java/lang/test/String_.java diff --git a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java deleted file mode 100644 index 8133043f..00000000 --- a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java +++ /dev/null @@ -1,13 +0,0 @@ -package cc.tianbin.java.mybatis; - -import org.junit.Test; - -/** - * Created by nibnait on 2022/10/18 - */ -public class MybatisTest { - - @Test - public void test() { - } -} diff --git a/src/main/test/javalang/test/FinallyTest.java b/src/main/test/cc/tianbin/javalang/test/FinallyTest.java similarity index 96% rename from src/main/test/javalang/test/FinallyTest.java rename to src/main/test/cc/tianbin/javalang/test/FinallyTest.java index 83fe27bc..ac7e8e0c 100644 --- a/src/main/test/javalang/test/FinallyTest.java +++ b/src/main/test/cc/tianbin/javalang/test/FinallyTest.java @@ -1,4 +1,4 @@ -package javalang.test; +package cc.tianbin.javalang.test; import io.github.nibnait.common.exception.ClientViewException; import org.junit.Test; diff --git a/src/main/test/javalang/test/IfTest.java b/src/main/test/cc/tianbin/javalang/test/IfTest.java similarity index 97% rename from src/main/test/javalang/test/IfTest.java rename to src/main/test/cc/tianbin/javalang/test/IfTest.java index 607592b5..ec1c1cb2 100644 --- a/src/main/test/javalang/test/IfTest.java +++ b/src/main/test/cc/tianbin/javalang/test/IfTest.java @@ -1,4 +1,4 @@ -package javalang.test; +package cc.tianbin.javalang.test; import com.alibaba.fastjson.JSON; import io.github.nibnait.common.constants.CommonConstants; diff --git a/src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java b/src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java deleted file mode 100644 index 9617de5a..00000000 --- a/src/main/test/cc/tianbin/redis/RateLimiter/RedisRateLimiterTest.java +++ /dev/null @@ -1,103 +0,0 @@ -package cc.tianbin.redis.RateLimiter; - -import io.github.nibnait.common.utils.date.DateTimeConvertUtils; -import org.junit.After; -import org.junit.BeforeClass; -import org.junit.Test; -import redis.clients.jedis.JedisPool; -import redis.clients.jedis.JedisPoolConfig; - -import java.time.LocalDateTime; -import java.util.concurrent.ExecutorService; -import java.util.concurrent.Executors; -import java.util.concurrent.TimeUnit; - -/** - * Created by nibnait on 2020/11/17 - */ -public class RedisRateLimiterTest { - private static RedisRateLimiter limiter; - - @BeforeClass - public static void init() { - JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - jedisPoolConfig.setMaxTotal(200); - JedisPool jedisPool = new JedisPool(jedisPoolConfig, "localhost"); - limiter = RedisRateLimiter.create("1000", 1, jedisPool,true); - } - - @After - public void tearDown() throws Exception { - Thread.sleep(2000L); - } - - private ExecutorService pool = Executors.newFixedThreadPool(500); - - @Test - public void acquire() throws Exception { - for (int i = 0; i < 10; i++) { - final int index = i; - - pool.execute(() -> { - double acquire = limiter.acquire(1); - System.out.println(index + " \t" + acquire + " \t" - + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); - }); - } - - Thread.sleep(5 * 1000L); - } - - @Test - public void tryAcquire() throws Exception { - for (int i = 0; i < 10; i++) { - final int index = i; - - pool.execute(() -> { - boolean acquire = limiter.tryAcquire(); - System.out.println(index + " \t" + acquire + " \t" - + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); - }); - } - - Thread.sleep(5 * 1000L); - } - - @Test - public void tryAcquireTimeout() throws Exception { - for (int i = 0; i < 10; i++) { - final int index = i; - - pool.execute(() -> { - boolean acquire = limiter.tryAcquire(1000L, TimeUnit.MILLISECONDS); - System.out.println(index + " \t" + acquire + " \t" - + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); - }); - } - - Thread.sleep(5 * 1000L); - } - - @Test - public void batchAcquireLazy() throws Exception { - JedisPoolConfig jedisPoolConfig = new JedisPoolConfig(); - jedisPoolConfig.setMaxTotal(50); - JedisPool jedisPool = new JedisPool(jedisPoolConfig, "localhost"); - - RedisRateLimiter redisRateLimiter = RedisRateLimiter.create("500", 1000, jedisPool, true); - redisRateLimiter.setBatchSize(50); - - for (int i = 0; i < 1000; i++) { - final String index = String.format("%3d", i); - - pool.execute(() -> { - double acquire = redisRateLimiter.acquireLazy(10); - System.out.println(index + " \t" + acquire + " \t" - + DateTimeConvertUtils.localDateTime2String(LocalDateTime.now())); - }); - } - - Thread.sleep(5 * 1000L); - } - -} diff --git a/src/main/test/cc/tianbin/temp/DataGen.java b/src/main/test/cc/tianbin/temp/DataGen.java deleted file mode 100644 index dc0951a4..00000000 --- a/src/main/test/cc/tianbin/temp/DataGen.java +++ /dev/null @@ -1,24 +0,0 @@ -package cc.tianbin.temp; - -import org.junit.Test; - -/** - * Created by nibnait on 2021/01/27 - */ -public class DataGen { - @Test - public void test() { - String ipIdStr = "3000001,3000002,3000003,3000004,3000005,3000006,3000007,3000008,3000009,3000010,3000011,3000012,3000013,3000014,3000015,3000016,3000017,3000018,3000019,3000020,3000021,3000022,3000023,3000024,3000025,3000026,3000027,3000028,3000029,3000030,3000031,3000032,3000033,3000034,3000035,3000036,3000037,3000038,3000039,3000040,3000041,3000042,3000043,3000044,3000045,3000046,3000047,3000048,3000049,3000050,3000051,3000052,3000053,3000054,3000055,3000056,3000057,3000058,3000059,3000060,3000061,3000062,3000063,3000064,3000065,3000066,3000067,3000068,3000069,3000070,3000071,3000072,3000073,3000074,3000075,3000076,3000077,3000078,3000079,3000080,3000081,3000082,3000083,3000084,3000085,3000086,3000087,3000088,3000089,3000090,3000091,3000092,3000093,3000094,3000095,3000096,3000097,3000098,3000099,3000100,3000101,3000102,3000103,3000104,3000105,3000106,3000107,3000108,3000109,3000110,3000111,3000112,3000113,3000114,3000115,3000116,3000117,3000118,3000119,3000120,3000121,3000122,3000123,3000124,3000125,3000126,3000127,3000128,3000129,3000130,3000131,3000132,3000133,3000134,3000135,3000136,3000137,3000138,3000139,3000140,3000141,3000142,3000143,3000144,3000145,3000146,3000147,3000148,3000149,3000150,3000151,3000152,3000153,3000154,3000155,3000156,3000157,3000158,3000159,3000160,3000161,3000162,3000163,3000164,3000165,3000166,3000167,3000168,3000169,3000170,3000171,3000172,3000173,3000174,3000175,3000176,3000177,3000178,3000179,3000180,3000181,3000182,3000183,3000184,3000185,3000186,3000187,3000188,3000189,3000190,3000191,3000192,3000193,3000194,3000195,3000196,3000197,3000198,3000199,3000200,3000201,3000202,3000203,3000204,3000205,3000206,3000207,3000208,3000209,3000210,3000211,3000212,3000213,3000214,3000215,3000216,3000217,3000218,3000219,3000220,3000221,3000222,3000223,3000224,3000225,3000226,3000227,3000228,3000229,3000230,3000231,3000232,3000233,3000234,3000235,3000236,3000237,3000238,3000239,3000240,3000241,3000242,3000243,3000244,3000245,3000246,3000247,3000248,3000249,3000250,3000251,3000252,3000253,3000254,3000255,3000256,3000257,3000258,3000259,3000260,3000261,3000262,3000263,3000264,3000265,3000266,3000267,3000268,3000269,3000270,3000271,3000272,3000273,3000274,3000275,3000276,3000277,3000278,3000279,3000280,3000281,3000282,3000283,3000284,3000285,3000286,3000287,3000288,3000289,3000290,3000291,3000292,3000293,3000294,3000295,3000296,3000297,3000298,3000299,3000300,3000301,3000302,3000303,3000304,3000305,3000306,3000307,3000308,3000309,3000310,3000311,3000312,3000313,3000314,3000315,3000316,3000317,3000318,3000319,3000320,3000321,3000322,3000323,3000324,3000325,3000326,3000327,3000328,3000329,3000330,3000331,3000332,3000333,3000334,3000335,3000336,3000337,3000338,3000339,3000340,3000341,3000342,3000343,3000344,3000345,3000346,3000347,3000348,3000349,3000350,3000351,3000352,3000353,3000354,3000355,3000356,3000357,3000358,3000359,3000360,3000361,3000362,3000363,3000364,3000365,3000366,3000367,3000368,3000369,3000370,3000371,3000372,3000373,3000374,3000375,3000376,3000377,3000378,3000379,3000380,3000381,3000382,3000383,3000384,3000385,3000386,3000387,3000388,3000389,3000390,3000391,3000392,3000393,3000394,3000395,3000396,3000397,3000398,3000399,3000400,3000401,3000402,3000403,3000404,3000405,3000406,3000407,3000408,3000409,3000410,3000411,3000412,3000413,3000414,3000415,3000416,3000417,3000418,3000419,3000420,3000421,3000422,3000423,3000424,3000425,3000426,3000427,3000428,3000429,3000430,3000431,3000432,3000433,3000434,3000435,3000436,3000437,3000438,3000439,3000440,3000441,3000442,3000443,3000444,3000445,3000446,3000447,3000448,3000449,3000450,3000451,3000452,3000453,3000454,3000455,3000456,3000457,3000458,3000459,3000460,3000461,3000462,3000463,3000464,3000465,3000466,3000467,3000468,3000469,3000470,3000471,3000472,3000473,3000474,3000475,3000476,3000477,3000478,3000479,3000480,3000481,3000482,3000483,3000484,3000485,3000486,3000487,3000488,3000489,3000490,3000491,3000492,3000493,3000494,3000495,3000496,3000497,3000498,3000499,3000500,3000501,3000502,3000503,3000504,3000505,3000506,3000507,3000508,3000509,3000510,3000511,3000512,3000513,3000514,3000515,3000516,3000517,3000518,3000519,3000520,3000521,3000522,3000523,3000524,3000525,3000526,3000527,3000528,3000529,3000530,3000531,3000532,3000533,3000534,3000535,3000536,3000537,3000538,3000539,3000540,3000541,3000542,3000543,3000544,3000545,3000546,3000547,3000548,3000549,3000550,3000551,3000552,3000553,3000554,3000555,3000556,3000557,3000558,3000559,3000560,3000561,3000562,3000563,3000564,3000565,3000566,3000567,3000568,3000569,3000570,3000571,3000572,3000573,3000574,3000575,3000576,3000577,3000578,3000579,3000580,3000581,3000582,3000583,3000584,3000585,3000586,3000587,3000588,3000589,3000590,3000591,3000592,3000593,3000594,3000595,3000596,3000597,3000598,3100002,3100005,3100007,3100009,3100011,3100013,3100015,3100018,3100020,3100022,3100024,3100026,3100028,3100031,3100033,3100034,3100036,3100037,3100039,3100041,3100043,3100045,3100047,3100049,3100052,3100054,3100056,3100058,3100060,3100062,3100064,3100066,3100069,3100071,3100073,3100075,3100077,3100079,3100082,3100084,3100087,3100089,3100091,3100093,3100095,3100097,3100099,3100101,3100103,3100105,3100107,3100109,3100112,3100114,3100116,3100118,3100120,3100122,3100124,3100126,3100128,3100130,3100132,3100134,3100136,3100138,3100140,3100142,3100144,3100146,3100149,3100151,3100154,3100156,3100158,3100160,3100162,3100164,3100166,3100168,3100170,3100172,3100174,3100176,3100178,3100180,3100183,3100185,3100187,3100189,3100191,3100193,3100195,3100197,3100199,3100201,3100203,3100205,3100207,3100209,3100211,3100213,3100215,3100217,3100219,3100221,3100223,3100225,3100227,3100229,3100231,3100234,3100236,3100257,3100259,3100261,3100264,3100266,3100272,3100274,3100276,3100278,3100280,3100282,3100284,3100286,3100293,3100295,3100297,3100300,3100302,3100304,3100307,3100309,3100311,3100314,3100317,3100319,3100321,3100323,3100325,3100327,3100329,3100331,3100333,3100335,3100337,3100339,3100341,3100343,3100345,3100347,3100350,3100353,3100355,3100357,3100359,3100361,3100363,3100365,3100367,3100369,3100371,3100373,3100375,3100377,3100379,3100381,3100383,3100385,3100387,3100389,3100391,3100393,3100395,3100398,3100401,3100403,3100405,3100407,3100410,3100412,3100414,3100416,3100418,3100420,3100422,3100424,3100427,3100429,3100431,3100433,3100435,3100437,3100439,3100441,3100444,3100446,3100448,3100450,3100452,3100454,3100456,3100458,3100460,3100462,3100465,3100471,3100473,3100475,3100477,3100479,3100481,3100483,3100485,3100487,3100489,3100491,3100493,3100495,3100497,3100499,3100501,3100503,3100506,3100508,3100510,3100512,3100515,3100517,3100519,3100521,3100523,3100525,3100527,3100529,3100532,3100533,3100565,3100568,3100570,3100572,3100574,3100598,3100606,3100608,3100610,3100612,3100614,3100616,3100618,3100620,3100622,3100624,3100626,3100628,3100631,3100633,3100635,3100637,3100639,3100642,3100644,3100646,3100648,3100650,3100652,3100654,3100656,3100658,3100660,3100662,3100666,3100673,3100675,3100679,3100681,3100683,3100685,3100687,3100689,3100691,3100693,3100695,3100697,3100699,3100702,3100705,3100707,3100709,3100711,3100720,3100722,3100724,3100726,3100728,3100730,3100732,3100734,3100736,3100738,3100740,3100743,3100745,3100747,3100748,3100750,3100752,3100754,3100757,3100759,3100761,3100763,3100765,3100767,3100769,3100771,3100773,3100775,3100778,3100780,3100781,3100784,3100786,3100788"; - String[] split = ipIdStr.split(","); - for (String ipId : split) { - System.out.println(ipId + ",10" + ",0"); - System.out.println(ipId + ",10" + ",10"); - System.out.println(ipId + ",10" + ",20"); - System.out.println(ipId + ",10" + ",30"); - System.out.println(ipId + ",10" + ",40"); - System.out.println(ipId + ",10" + ",50"); - System.out.println(ipId + ",10" + ",60"); - System.out.println(ipId + ",10" + ",70"); - } - } -} diff --git a/src/main/test/cc/tianbin/temp/JsonParseTest.java b/src/main/test/cc/tianbin/temp/JsonParseTest.java deleted file mode 100644 index 77fe3a8e..00000000 --- a/src/main/test/cc/tianbin/temp/JsonParseTest.java +++ /dev/null @@ -1,35 +0,0 @@ -package cc.tianbin.temp; - -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; -import junit.framework.TestCase; -import org.apache.commons.lang3.StringUtils; -import org.junit.Test; - -/** - * Created by nibnait on 2020-02-25 - */ -public class JsonParseTest extends TestCase { - - @Test - public void test() { - String s = JSON.toJSONString(null); - System.out.println(s); - } - - @Test - public void testCase() { - - String attribute_json = "{\"active_at\":1582566155,\"user_name\":\"32a9bd7c2\"}"; - JSONObject jsonObject = JSONObject.parseObject(attribute_json); - System.out.println(jsonObject); - String is_from_tp_new_retail = jsonObject.getString("is_from_tp_new_retail"); - System.out.println(is_from_tp_new_retail); - - if (StringUtils.isNotBlank(attribute_json) && jsonObject.getString("is_from_tp_new_retail") == "1") { - System.out.println("asdfsafsafsa"); - } - } - - -} \ No newline at end of file diff --git a/src/main/test/tmp/interview/Main.java b/src/main/test/cc/tianbin/tmp/interview/Main.java similarity index 73% rename from src/main/test/tmp/interview/Main.java rename to src/main/test/cc/tianbin/tmp/interview/Main.java index 50423ae5..7eb9f87d 100644 --- a/src/main/test/tmp/interview/Main.java +++ b/src/main/test/cc/tianbin/tmp/interview/Main.java @@ -1,4 +1,4 @@ -package tmp.interview; +package cc.tianbin.tmp.interview; import org.junit.Test; From f083bdaccf1f84b9897ff923d6adf9c33f6db5ea Mon Sep 17 00:00:00 2001 From: tianbin Date: Wed, 1 Mar 2023 12:07:35 +0800 Subject: [PATCH 31/36] =?UTF-8?q?feat=20=E5=B0=8F=E7=BB=83=E4=B9=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...\347\232\204\347\237\251\345\275\242.java" | 98 ++++++++++- ...\345\244\247\347\237\251\345\275\242.java" | 120 +++++++++++++ ...\346\257\215\347\273\204\345\220\210.java" | 2 +- ...\345\205\250\346\216\222\345\210\227.java" | 39 ++++- ...345\205\250\346\216\222\345\210\2272.java" | 35 ++-- ...\346\226\207\351\223\276\350\241\250.java" | 91 ++++++++++ .../LockAndAqs.java" | 25 +++ ...1_\345\205\254\345\271\263\351\224\201.md" | 1 - .../JUC/JUC_AQS/mylock/MyLock.java" | 93 ++++++++++ .../JUC/JUC_AQS/mylock/MyLockTest.java" | 55 ++++++ ...\345\217\257\350\247\201\346\200\247.java" | 8 + .../OddEvenPrint.java" | 57 ++++++ .../aThreadJoinDemo.java" | 2 +- .../cThreadWaitNotifyDemo.java" | 2 +- .../dThreadAwaitSingalDemo.java" | 2 +- .../Map\347\261\273.java" | 164 ++---------------- .../context/ApplicationContextHelper.java | 84 --------- src/main/java/common/enums/ErrorCode.java | 20 --- .../common/util/validate/FluentValidator.java | 137 --------------- .../java/common/util/validate/Validator.java | 24 --- .../validate/context/ValidateContext.java | 127 -------------- .../context/ValidateContextAttrKey.java | 22 --- .../validate/context/ValidateElement.java | 23 --- .../util/validate/context/ValidateResult.java | 34 ---- .../validate/validator/OperatorValidator.java | 29 ---- .../cc/tianbin/java/mybatis/MybatisTest.java | 1 - 26 files changed, 606 insertions(+), 689 deletions(-) create mode 100644 "src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" create mode 100644 "src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" create mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" delete mode 100644 src/main/java/common/context/ApplicationContextHelper.java delete mode 100644 src/main/java/common/enums/ErrorCode.java delete mode 100644 src/main/java/common/util/validate/FluentValidator.java delete mode 100644 src/main/java/common/util/validate/Validator.java delete mode 100644 src/main/java/common/util/validate/context/ValidateContext.java delete mode 100644 src/main/java/common/util/validate/context/ValidateContextAttrKey.java delete mode 100644 src/main/java/common/util/validate/context/ValidateElement.java delete mode 100644 src/main/java/common/util/validate/context/ValidateResult.java delete mode 100644 src/main/java/common/util/validate/validator/OperatorValidator.java diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" index 599227da..72f71eb9 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H084_\346\237\261\347\212\266\345\233\276\344\270\255\346\234\200\345\244\247\347\232\204\347\237\251\345\275\242.java" @@ -1,21 +1,23 @@ package algorithm_practice.LeetCode.code000; +import com.google.common.collect.Lists; import org.junit.Assert; import org.junit.Test; +import java.util.List; import java.util.Stack; /** - * 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 - * 求在该柱状图中,能够勾勒出来的矩形的最大面积。 - * + * 给定 n 个非负整数,用来表示柱状图中各个柱子的高度。每个柱子彼此相邻,且宽度为 1 。 + * 求在该柱状图中,能够勾勒出来的矩形的最大面积。 + *

* 输入:heights = [2,1,5,6,2,3] * 输出:10 - * 解释:最大的矩形为图中红色区域,面积为 10 - * + * 解释:最大的矩形为图中红色区域,面积为 10 + *

* 输入: heights = [2,4] * 输出: 4 - * + *

* https://leetcode.cn/problems/largest-rectangle-in-histogram/ * Created by nibnait on 2022/11/16 */ @@ -23,15 +25,95 @@ public class H084_柱状图中最大的矩形 { @Test public void test() { - int[] heights = new int[]{2,1,5,6,2,3}; + int[] heights = new int[]{2, 1, 5, 6, 2, 3}; int ans = largestRectangleArea(heights); Assert.assertEquals(10, ans); - heights = new int[]{2,4}; + heights = new int[]{2, 4}; ans = largestRectangleArea(heights); Assert.assertEquals(4, ans); + + heights = new int[]{1, 1}; + ans = largestRectangleArea(heights); + Assert.assertEquals(2, ans); + + heights = new int[]{1, 2, 3, 3, 4, 3, 3, 5, 1}; + ans = largestRectangleArea(heights); + Assert.assertEquals(18, ans); + } + + /** + * 法1: + * 1. 单调栈,找到每个元素,最近的 左、右 两边的第一个比他小的index + * 2. 再遍历一遍数组,求以每个元素为高时,其对应的矩形的面积 + */ + public int largestRectangleArea1(int[] heights) { + + int[][] nearestSmallIndex = nearestSmallIndex(heights); + int[] nearLeftSmall = new int[heights.length]; + int[] nearRightSmall = new int[heights.length]; + for (int i = 0; i < nearestSmallIndex.length; i++) { + nearLeftSmall[i] = nearestSmallIndex[i][0]; + nearRightSmall[i] = nearestSmallIndex[i][1]; + } + + int maxArea = heights[0] * getWidth(-1, nearRightSmall[0], heights.length); + for (int i = 1; i < heights.length; i++) { + maxArea = Math.max(maxArea, heights[i] * getWidth(nearLeftSmall[i], nearRightSmall[i], heights.length)); + } + return maxArea; + } + + private int getWidth(int left, int right, int length) { + if (left == -1 && right == -1) { + return length; + } + if (left == -1) { + return right; + } + if (right == -1) { + return length - left - 1; + } + return right - left - 1; + } + + private int[][] nearestSmallIndex(int[] heights) { + int[][] result = new int[heights.length][2]; + Stack> stack = new Stack<>(); + + for (int i = 0; i < heights.length; i++) { + while (!stack.isEmpty() && heights[stack.peek().get(0)] > heights[i]) { + List popIndexs = stack.pop(); + int leftLessIndex = stack.isEmpty() ? -1 : stack.peek().get(stack.peek().size() - 1); + for (Integer popIndex : popIndexs) { + result[popIndex][0] = leftLessIndex; + result[popIndex][1] = i; + } + } + + if (!stack.isEmpty() && heights[stack.peek().get(0)] == heights[i]) { + stack.peek().add(i); + } else { + stack.add(Lists.newArrayList(i)); + } + } + + while (!stack.isEmpty()) { + List popIndexs = stack.pop(); + int leftLessIndex = stack.isEmpty() ? -1 : stack.peek().get(stack.peek().size() - 1); + for (Integer popIndex : popIndexs) { + result[popIndex][0] = leftLessIndex; + result[popIndex][1] = -1; + } + } + + return result; } + /** + * 法2: + * + */ public int largestRectangleArea(int[] heights) { if (heights == null || heights.length == 0) { return 0; diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" "b/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" new file mode 100644 index 00000000..6332c4a2 --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code000/H085_\346\234\200\345\244\247\347\237\251\345\275\242.java" @@ -0,0 +1,120 @@ +package algorithm_practice.LeetCode.code000; + +import org.junit.Assert; +import org.junit.Test; + +import java.util.Stack; + +/* + * 给定一个仅包含 0 和 1 、大小为 rows x cols 的二维二进制矩阵,找出只包含 1 的最大矩形,并返回其面积。 + * 示例 1: + * 输入:matrix = [["1","0","1","0","0"], + * ["1","0","1","1","1"], + * ["1","1","1","1","1"], + * ["1","0","0","1","0"]] + * 输出:6 + * + * 示例 2: + * 输入:matrix = [] + * 输出:0 + * + * 示例 3: + * 输入:matrix = [["0"]] + * 输出:0 + * + * 示例 4: + * 输入:matrix = [["1"]] + * 输出:1 + * + * 示例 5: + * 输入:matrix = [["0","0"]] + * 输出:0 + * + * https://leetcode.cn/problems/maximal-rectangle/?favorite=2cktkvj + */ +public class H085_最大矩形 { + + + @Test + public void test() { + char[][] matrix = new char[][]{ + {'1', '0', '1', '0', '0'}, + {'1', '0', '1', '1', '1'}, + {'1', '1', '1', '1', '1'}, + {'0', '0', '0', '1', '0'}, + }; + int ans = maximalRectangle(matrix); + Assert.assertEquals(6, ans); + + matrix = new char[][]{}; + ans = maximalRectangle(matrix); + Assert.assertEquals(0, ans); + + matrix = new char[][]{{'0'}}; + ans = maximalRectangle(matrix); + Assert.assertEquals(0, ans); + + matrix = new char[][]{{'1'}}; + ans = maximalRectangle(matrix); + Assert.assertEquals(1, ans); + + matrix = new char[][]{{'0', '0'}}; + ans = maximalRectangle(matrix); + Assert.assertEquals(0, ans); + + } + + /** + * 跟上一题一样。单调栈。 + * 1. 求出第1层的最大矩形 + * 2. 再求第2层的最大矩形,遍历第2层的时候,遇到0则直接高度归0,非0则高度累加 + * 3. 重复步骤2,遍历3、4、5... 层, + * 4. 循环结束。得到最大的矩形面积 + * + */ + public int maximalRectangle(char[][] matrix) { + if (matrix.length == 0 || matrix[0].length == 0) { + return 0; + } + + int[][] m = new int[matrix.length][matrix[0].length]; + + for (int i = 0; i < matrix.length; i++) { + for (int j = 0; j < matrix[0].length; j++) { + m[i][j] = matrix[i][j] == '0' ? 0 : 1; + } + } + int maxArea = 0; + for (int i = 0; i < m.length; i++) { + if (i >= 1) { + for (int k = 0; k < m[0].length; k++) { + m[i][k] = m[i][k] == 0 ? 0 : m[i-1][k] + m[i][k]; + } + } + + Stack stack = new Stack<>(); + for (int j = 0; j < m[0].length; j++) { + while (!stack.isEmpty() && m[i][j] <= m[i][stack.peek()]) { + int pop = stack.pop(); + int leftIndex = stack.isEmpty() ? -1 : stack.peek(); + int curArea = m[i][pop] * (j - leftIndex - 1); + maxArea = Math.max(maxArea, curArea); + } + + stack.push(j); + } + + while (!stack.isEmpty()) { + int pop = stack.pop(); + int leftIndex = stack.isEmpty() ? -1 : stack.peek(); + int curArea = m[i][pop] * (m[0].length - leftIndex - 1); + maxArea = Math.max(maxArea, curArea); + } + } + + return maxArea; + } + + + +} diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" index a85c6362..6276a55b 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M017_\347\224\265\350\257\235\345\217\267\347\240\201\347\232\204\345\255\227\346\257\215\347\273\204\345\220\210.java" @@ -21,7 +21,7 @@ public void test() { } - private static final char[][] phone = new char[][]{ + private static final char[][] phone = new char[][] { {'.'}, {'.'}, {'a', 'b', 'c'}, diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" index 9b343c94..a3f89bdd 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M046_\345\205\250\346\216\222\345\210\227.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import org.junit.Assert; +import common.util.AssertUtils; import org.junit.Test; import java.util.ArrayList; @@ -35,7 +35,7 @@ public class M046_全排列 { @Test public void testCase() { int[] nums = new int[]{1,2,3}; - List> excepted = Lists.newArrayList( + List> except = Lists.newArrayList( Lists.newArrayList(1,2,3), Lists.newArrayList(1,3,2), Lists.newArrayList(2,1,3), @@ -43,8 +43,39 @@ public void testCase() { Lists.newArrayList(3,1,2), Lists.newArrayList(3,2,1)); List> result = permute(nums); - Assert.assertEquals(excepted, result); + AssertUtils.compareListList(except, result, nums); + } + + public List> permute(int[] nums) { + if (nums == null || nums.length == 0) { + return new ArrayList<>(); + } + + List> ans = new ArrayList<>(); + process(nums, 0, ans); + return ans; + } + private void process(int[] nums, int index, List> ans) { + if (index == nums.length) { + List path = new ArrayList<>(); + for (int num : nums) { + path.add(num); + } + ans.add(path); + } else { + for (int i = index; i < nums.length; i++) { + swap(nums, i, index); + process(nums, index + 1, ans); + swap(nums, i, index); + } + } + } + + private void swap(int[] nums, int a, int b) { + int tmp = nums[a]; + nums[a] = nums[b]; + nums[b] = tmp; } /* @@ -69,7 +100,7 @@ def backtrack(路径,选择列表) { */ - public List> permute(int[] nums) { + public List> permute2(int[] nums) { List> result = new ArrayList<>(); Deque path = new LinkedList<>(); diff --git "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" "b/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" index 55d5ab64..f98f6061 100644 --- "a/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" +++ "b/src/main/java/algorithm_practice/LeetCode/code000/M047_\345\205\250\346\216\222\345\210\2272.java" @@ -1,7 +1,7 @@ package algorithm_practice.LeetCode.code000; import com.google.common.collect.Lists; -import org.junit.Assert; +import common.util.AssertUtils; import org.junit.Test; import java.util.*; @@ -28,15 +28,13 @@ public class M047_全排列2 { @Test public void testCase() { - int[] nums = new int[]{1,1,2}; - List> excepted = Lists.newArrayList( - Lists.newArrayList(1,1,2), - Lists.newArrayList(1,2,1), - Lists.newArrayList(2,1,1)); + int[] nums = new int[]{1, 1, 2}; + List> except = Lists.newArrayList( + Lists.newArrayList(1, 1, 2), + Lists.newArrayList(1, 2, 1), + Lists.newArrayList(2, 1, 1)); List> result = permuteUnique(nums); - Assert.assertEquals(excepted, result); - - + AssertUtils.compareListList(except, result, nums); } public List> permuteUnique(int[] nums) { @@ -52,16 +50,17 @@ public List> permuteUnique(int[] nums) { private void process(int[] nums, int index, List> result) { if (index == nums.length) { List e = toArrayList(nums); - if (!result.contains(e)) { - result.add(e); + result.add(e); + } else { + HashSet set = new HashSet<>(); + for (int i = index; i < nums.length; i++) { + if (!set.contains(nums[i])) { + set.add(nums[i]); + swap(nums, i, index); + process(nums, index + 1, result); + swap(nums, i, index); + } } - return; - } - - for (int i = index; i < nums.length; i++) { - swap(nums, i, index); - process(nums, index + 1, result); - swap(nums, i, index); } } diff --git "a/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" "b/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" new file mode 100644 index 00000000..c2b5c209 --- /dev/null +++ "b/src/main/java/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" @@ -0,0 +1,91 @@ +package algorithm_practice.LeetCode.code200; + +import cn.hutool.core.lang.Assert; +import common.datastruct.ListNode; +import common.util.ConstructLinkedNode; +import org.junit.Test; + +/** + * 给你一个单链表的头节点 head ,请你判断该链表是否为回文链表。如果是,返回 true ;否则,返回 false 。 + * + * 输入:head = [1,2,2,1] + * 输出:true + * + * 输入:head = [1,2] + * 输出:false + * + * Created by nibnait on 2023/03/01 + */ +public class E234_回文链表 { + + @Test + public void test() { + int[] nums = new int[]{1,2,2,1}; + boolean result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(true, result); + + nums = new int[]{1}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(true, result); + + nums = new int[]{1, 2}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(false, result); + + nums = new int[]{1, 2, 1}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(true, result); + + nums = new int[]{1,1,0,0,1}; + result = isPalindrome(ConstructLinkedNode.constructSingleLinkedNode(nums)); + Assert.equals(false, result); + + } + + public boolean isPalindrome(ListNode head) { + if (head == null) { + return false; + } + + ListNode p1 = head; + ListNode p2 = head; + int count = 1; + while (p2.next != null && p2.next.next != null) { + p1 = p1.next; + p2 = p2.next.next; + count++; + } + + ListNode reverseStart = p1; + if (count % 2 == 0) { + reverseStart = p1.next; + } + + // 翻转链表 + ListNode dummyHead = new ListNode(); + dummyHead.next = reverseStart; + + ListNode cur = reverseStart.next; + reverseStart.next = null; + while (cur != null) { + ListNode next = cur.next; + + cur.next = dummyHead.next; + dummyHead.next = cur; + + cur = next; + } + + // 一一对比 + dummyHead = dummyHead.next; + while (head != null && dummyHead != null) { + if (head.val != dummyHead.val) { + return false; + } + head = head.next; + dummyHead = dummyHead.next; + } + return true; + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" new file mode 100644 index 00000000..249082a6 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" @@ -0,0 +1,25 @@ +package cc.tianbin.java.并发.AQS源码阅读; + +import java.util.concurrent.locks.ReentrantLock; + +/** + * Created by nibnait on 2023/02/01 + */ +public class LockAndAqs { + + private static ReentrantLock lock = new ReentrantLock(); + + public static void main(String[] args) { + + + try { + lock.lock(); + } finally { + lock.unlock(); + } + + + + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" index eb4a9840..1c6f5bbc 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/ReentrantLock\345\217\257\351\207\215\345\205\245\351\224\201_\345\205\254\345\271\263\351\224\201.md" @@ -1,4 +1,3 @@ - ## lock (sync.lock()) ```java diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" new file mode 100644 index 00000000..0c7469f2 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" @@ -0,0 +1,93 @@ +package cc.tianbin.java.并发.JUC.JUC_AQS.mylock; + +import org.jetbrains.annotations.NotNull; + +import java.util.concurrent.TimeUnit; +import java.util.concurrent.locks.AbstractQueuedSynchronizer; +import java.util.concurrent.locks.Condition; +import java.util.concurrent.locks.Lock; + +/** + * Created by nibnait on 2023/02/01 + */ +public class MyLock implements Lock { + + protected static final String MY_LOCK_NAME = "myLock"; + + /** + * tryAcquire 加锁 + * tryRelease 解锁 + */ + private static class Sync extends AbstractQueuedSynchronizer { + + /** + * 加锁 + */ + protected boolean tryAcquire(int arg) { + if (!Thread.currentThread().getName().startsWith(MY_LOCK_NAME)) { + // 加锁失败 + return false; + } + + if (compareAndSetState(0, arg)) { + setExclusiveOwnerThread(Thread.currentThread()); + // 加锁成功 + return true; + } + + return false; + } + + /** + * 解锁 + */ + protected boolean tryRelease(int arg) { + if (getState() == 0) { + throw new IllegalMonitorStateException(); + } + setState(0); + + setExclusiveOwnerThread(null); + return true; + } + + protected Condition getCondition() { + return new ConditionObject(); + } + } + + // 内部类 + Sync sync = new Sync(); + + @Override + public void lock() { + sync.acquire(1); + } + + @Override + public boolean tryLock() { + return sync.tryAcquire(1); + } + + @Override + public boolean tryLock(long time, @NotNull TimeUnit unit) throws InterruptedException { + return sync.tryAcquireNanos(1, unit.toNanos(time)); + } + + @Override + public void lockInterruptibly() throws InterruptedException { + sync.acquireInterruptibly(1); + } + + @Override + public void unlock() { + sync.release(1); + } + + @NotNull + @Override + public Condition newCondition() { + return sync.getCondition(); + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" new file mode 100644 index 00000000..2f172d39 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" @@ -0,0 +1,55 @@ +package cc.tianbin.java.并发.JUC.JUC_AQS.mylock; + +import common.util.LogUtil; + +import static cc.tianbin.java.并发.JUC.JUC_AQS.mylock.MyLock.MY_LOCK_NAME; + +/** + * Created by nibnait on 2023/02/01 + */ +public class MyLockTest { + + private static MyLock lock = new MyLock(); + + /** + * 自定义一把锁 + * 设计一把自定义的锁你高要多久?需求如下: + * 1.排它锁,只有线程 name 以"myLock”开头的才能获取剑 + * 2.不支持重入,喜欢一次藏够了。 + * 3.支持尝试加锁 + * 4,支持超时尝试加锁 + * 5.支持可中衙加锁 + * 6.支wait notify功能 + * 7.其他不以“myLock”开头的线程名称,一律拒之门外。 + */ + public static void main(String[] args) { + + Thread t1 = new Thread(() -> { + testLock(); + }); + + Thread t2 = new Thread(() -> { + testLock(); + }); + + t1.setName(MY_LOCK_NAME); +// t1.setName("xx" + MY_LOCK_NAME); + t2.setName("xxx"); + + t1.start(); + t2.start(); + + } + + private static void testLock() { + lock.lock(); + + try { + LogUtil.log("{} 拿到了锁", Thread.currentThread().getName()); + } finally { + lock.unlock(); + } + } + + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" index e7361bcb..fa3086c1 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/\345\217\257\350\247\201\346\200\247.java" @@ -16,6 +16,14 @@ public class 可见性 { private Number number = new Number(); private int loopCount = 100000; + private volatile Integer count = 0; + + @Test + public void testVolatile() { + count = count + 1; + System.out.println(count); + } + @Test public void test可见性() { diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" new file mode 100644 index 00000000..3f7d3068 --- /dev/null +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" @@ -0,0 +1,57 @@ +package cc.tianbin.java.并发.threadpool.让3个线程顺序执行; + +import lombok.SneakyThrows; +import org.junit.Test; + +import java.util.concurrent.CyclicBarrier; +import java.util.concurrent.Semaphore; + +/** + * 两个线程,依次打印奇数、偶数 + * Created by nibnait on 2023/02/01 + */ +public class OddEvenPrint { + + @Test + public void test2() { + + CyclicBarrier c = new CyclicBarrier(2); + + } + + @Test + public void test1() { + + Semaphore s1 = new Semaphore(1); + Semaphore s2 = new Semaphore(0); + + Thread oddThread = new Thread(new Runnable() { + @SneakyThrows + @Override + public void run() { + for (int i = 1; i <= 100; i += 2) { + s1.acquire(); + System.out.println(i); + s2.release(); + } + } + }); + + Thread evenThread = new Thread(new Runnable() { + @SneakyThrows + @Override + public void run() { + for (int i = 2; i <= 100; i += 2) { + s2.acquire(); + System.out.println(i); + s1.release(); + } + } + }); + + evenThread.start(); + oddThread.start(); + + } + +} diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" index e3479cc0..9cab497a 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/aThreadJoinDemo.java" @@ -9,7 +9,7 @@ public class aThreadJoinDemo { /** - * join():是Theard的方法,作用是调用线程需等待该join()线程执行完成后,才能继续用下运行。 + * join():是 Thread 的方法,作用是调用线程需等待该join()线程执行完成后,才能继续用下运行。 * * 应用场景:当一个线程必须等待另一个线程执行完毕才能执行时可以使用join方法。 */ diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" index 2e4c2624..f2a73d46 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/cThreadWaitNotifyDemo.java" @@ -10,7 +10,7 @@ public class cThreadWaitNotifyDemo { /** - * wait():是Object的方法,作用是让当前线程进入等待状态,同时,wait()也会让当前线程释放它所持有的锁。“直到其他线程调用此对象的 notify() 方法或 notifyAll() 方法”,当前线程被唤醒(进入“就绪状态”) + * wait():是 Object 的方法,作用是让当前线程进入等待状态,同时,wait()也会让当前线程释放它所持有的锁。“直到其他线程调用此对象的 notify() 方法或 notifyAll() 方法”,当前线程被唤醒(进入“就绪状态”) *

* notify()和notifyAll():是Object的方法,作用则是唤醒当前对象上的等待线程;notify()是唤醒单个线程,而notifyAll()是唤醒所有的线程。 *

diff --git "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" index 888d1d8d..b95fe0da 100644 --- "a/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" +++ "b/src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/dThreadAwaitSingalDemo.java" @@ -13,7 +13,7 @@ public class dThreadAwaitSingalDemo { /** - * Condition(条件变量):通常与一个锁关联。需要在多个Contidion中共享一个锁时,可以传递一个Lock/RLock实例给构造方法,否则它将自己生成一个RLock实例。 + * Condition(条件变量):通常与一个锁关联。需要在多个Condition中共享一个锁时,可以传递一个Lock/RLock实例给构造方法,否则它将自己生成一个RLock实例。 * * Condition中await()方法类似于Object类中的wait()方法。 * diff --git "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" index 50b8d017..6b8be08b 100644 --- "a/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" +++ "b/src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" @@ -29,163 +29,21 @@ public static void main(String[] args) { } @Test - public void test01() { - // ParameterizedType + public void hashMap() { + HashMap map = new HashMap(); - } + map.put(1, 1); + map.put(2, 2); -/* putVal - ** - * Implements Map.put and related methods. - * - * @param hash hash for key - * @param key the key - * @param value the value to put - * @param onlyIfAbsent if true, don't change existing value - * @param evict if false, the table is in creation mode. - * @return previous value, or null if none - * - final V putVal(int hash, K key, V value, boolean onlyIfAbsent, - boolean evict) { - HashMap.Node[] tab; HashMap.Node p; int n, i; - if ((tab = table) == null || (n = tab.length) == 0) - n = (tab = resize()).length; - if ((p = tab[i = (n - 1) & hash]) == null) - tab[i] = newNode(hash, key, value, null); - else { - HashMap.Node e; K k; - if (p.hash == hash && - ((k = p.key) == key || (key != null && key.equals(k)))) - e = p; - else if (p instanceof HashMap.TreeNode) - e = ((HashMap.TreeNode)p).putTreeVal(this, tab, hash, key, value); - else { - for (int binCount = 0; ; ++binCount) { - if ((e = p.next) == null) { - p.next = newNode(hash, key, value, null); - if (binCount >= TREEIFY_THRESHOLD - 1) // -1 for 1st - treeifyBin(tab, hash); - break; - } - if (e.hash == hash && - ((k = e.key) == key || (key != null && key.equals(k)))) - break; - p = e; - } - } - if (e != null) { // existing mapping for key - V oldValue = e.value; - if (!onlyIfAbsent || oldValue == null) - e.value = value; - afterNodeAccess(e); - return oldValue; - } - } - ++modCount; - if (++size > threshold) - resize(); - afterNodeInsertion(evict); - return null; - } + map.get(1); + map.remove(1); - //如果一个hashmap.里边有1g00个元素。 - //我们可以通过ut方法的返回值,进行一个是否有数值覆盖的判断、 - //如果有的业务逻辑从上层业务需求上,就可以肯定歌ey绝对是唯一的。那么这个时候,如果我们使跳ashmap - //进行数据的维护添加的话,好的代码需要使用到这个特性来保证我们的业务的伽y确实是唯一的 - //如果发现我们的put方法的返回值有值的话。擦,那说明业务伽y不唯一了,可以根据业务需求,直接抛出异常 - //通过代码,进行二次的校验。 + } - //这时候己经写入了。那么我想问下一下,我们的的返回值是什么? - //返回值是oldvalue。请问返回值丢失了吗? - //没有丢失啊,你可以再set回去啊,或者直接把这个事情当成了纯异常,再次从新oad数据 -*/ + @Test + public void concurrentHashMap() { + ConcurrentHashMap concurrentHashMap = new ConcurrentHashMap(); -/* resize - ** - * Initializes or doubles table size. If null, allocates in - * accord with initial capacity target held in field threshold. - * Otherwise, because we are using power-of-two expansion, the - * elements from each bin must either stay at same index, or move - * with a power of two offset in the new table. - * - * @return the table - * - final HashMap.Node[] resize() { - // old 16 - HashMap.Node[] oldTab = table; - // 16 - int oldCap = (oldTab == null) ? 0 : oldTab.length; - // 12 - int oldThr = threshold; - int newCap, newThr = 0; - if (oldCap > 0) { - if (oldCap >= MAXIMUM_CAPACITY) { - // 放弃扩容 - threshold = Integer.MAX_VALUE; - return oldTab; - } - else if ((newCap = oldCap << 1) < MAXIMUM_CAPACITY && - oldCap >= DEFAULT_INITIAL_CAPACITY) - newThr = oldThr << 1; // double threshold - } - else if (oldThr > 0) // initial capacity was placed in threshold - newCap = oldThr; - else { // zero initial threshold signifies using defaults - newCap = DEFAULT_INITIAL_CAPACITY; - newThr = (int)(DEFAULT_LOAD_FACTOR * DEFAULT_INITIAL_CAPACITY); - } - if (newThr == 0) { - float ft = (float)newCap * loadFactor; - newThr = (newCap < MAXIMUM_CAPACITY && ft < (float)MAXIMUM_CAPACITY ? - (int)ft : Integer.MAX_VALUE); - } - threshold = newThr; - @SuppressWarnings({"rawtypes","unchecked"}) - HashMap.Node[] newTab = (HashMap.Node[])new HashMap.Node[newCap]; - table = newTab; - if (oldTab != null) { - for (int j = 0; j < oldCap; ++j) { - HashMap.Node e; - if ((e = oldTab[j]) != null) { - oldTab[j] = null; - if (e.next == null) - newTab[e.hash & (newCap - 1)] = e; - else if (e instanceof HashMap.TreeNode) - ((HashMap.TreeNode)e).split(this, newTab, j, oldCap); - else { // preserve order - HashMap.Node loHead = null, loTail = null; - HashMap.Node hiHead = null, hiTail = null; - HashMap.Node next; - do { - next = e.next; - if ((e.hash & oldCap) == 0) { - if (loTail == null) - loHead = e; - else - loTail.next = e; - loTail = e; - } - else { - if (hiTail == null) - hiHead = e; - else - hiTail.next = e; - hiTail = e; - } - } while ((e = next) != null); - if (loTail != null) { - loTail.next = null; - newTab[j] = loHead; - } - if (hiTail != null) { - hiTail.next = null; - newTab[j + oldCap] = hiHead; - } - } - } - } - } - return newTab; + concurrentHashMap.put(1, 1); } - */ } \ No newline at end of file diff --git a/src/main/java/common/context/ApplicationContextHelper.java b/src/main/java/common/context/ApplicationContextHelper.java deleted file mode 100644 index e782af88..00000000 --- a/src/main/java/common/context/ApplicationContextHelper.java +++ /dev/null @@ -1,84 +0,0 @@ -package common.context; - -import io.github.nibnait.common.exception.ServiceException; -import lombok.extern.slf4j.Slf4j; -import org.springframework.beans.BeansException; -import org.springframework.beans.factory.config.BeanDefinition; -import org.springframework.beans.factory.support.BeanDefinitionBuilder; -import org.springframework.beans.factory.support.BeanDefinitionRegistry; -import org.springframework.context.ApplicationContext; -import org.springframework.context.ApplicationContextAware; -import org.springframework.context.ConfigurableApplicationContext; - -import java.beans.Introspector; -import java.util.Map; - -/** - * Created by nibnait on 2021/09/01 - */ -@Slf4j -public class ApplicationContextHelper implements ApplicationContextAware { - - private static ApplicationContext applicationContext; - - private static BeanDefinitionRegistry beanDefinitionRegistry; - - /** - * 动态注册bean - */ - public synchronized static void registerBean(String beanName, Class clazz) { - if (null == beanName || null == clazz) { - throw new RuntimeException(beanName + "注册失败"); - } - - BeanDefinition beanDefinition = getBeanDefinitionBuilder(clazz).getBeanDefinition(); - if (!beanDefinitionRegistry.containsBeanDefinition(beanName)) { - beanDefinitionRegistry.registerBeanDefinition(beanName, beanDefinition); - } - } - - - private static BeanDefinitionBuilder getBeanDefinitionBuilder(Class clazz) { - return BeanDefinitionBuilder.genericBeanDefinition(clazz); - } - - @Override - public void setApplicationContext(ApplicationContext applicationContext) throws BeansException { - ApplicationContextHelper.applicationContext = applicationContext; - ConfigurableApplicationContext configurableApplicationContext = (ConfigurableApplicationContext) applicationContext; - beanDefinitionRegistry = (BeanDefinitionRegistry) configurableApplicationContext.getBeanFactory(); - } - - public static T getBean(Class targetClz) { - T beanInstance = null; - //byType - try { - beanInstance = applicationContext.getBean(targetClz); - } catch (Exception e) { - log.error("ApplicationContextHelper getBean error ", e); - } - //byName - if (beanInstance == null) { - String simpleName = Introspector.decapitalize(targetClz.getSimpleName()); - try { - Object bean = applicationContext.getBean(simpleName); - if (bean == null) { - throw new ServiceException("获取bean失败 {}", targetClz); - } - beanInstance = targetClz.cast(bean); - } catch (Exception e) { - log.error("ApplicationContextHelper getBean beanInstance error", e); - } - } - return beanInstance; - } - - public static T getBean(String beanName, Class targetClz) { - return applicationContext.getBean(beanName, targetClz); - } - - public static Map getBeansOfType(Class clazz) { - return applicationContext.getBeansOfType(clazz); - } - -} diff --git a/src/main/java/common/enums/ErrorCode.java b/src/main/java/common/enums/ErrorCode.java deleted file mode 100644 index 5e5fe9b6..00000000 --- a/src/main/java/common/enums/ErrorCode.java +++ /dev/null @@ -1,20 +0,0 @@ -package common.enums; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * Created by nibnait on 2021/09/01 - */ -@Getter -@AllArgsConstructor -public enum ErrorCode { - SUCCESS(0L, "success"), - SERVICE_ERROR(83000004L, "service error"), - - ; - - private Long code; - private String message; - -} diff --git a/src/main/java/common/util/validate/FluentValidator.java b/src/main/java/common/util/validate/FluentValidator.java deleted file mode 100644 index 4fd61e4f..00000000 --- a/src/main/java/common/util/validate/FluentValidator.java +++ /dev/null @@ -1,137 +0,0 @@ -package common.util.validate; - -import common.context.ApplicationContextHelper; -import common.util.validate.context.ValidateContext; -import common.util.validate.context.ValidateContextAttrKey; -import common.util.validate.context.ValidateElement; -import common.util.validate.context.ValidateResult; -import lombok.extern.slf4j.Slf4j; -import org.apache.commons.collections4.CollectionUtils; - -import java.util.ArrayList; -import java.util.List; - -/** - * 链式调用验证器,参考fluent-validator的简单实现 - * https://github.com/neoremind/fluent-validator - */ -@Slf4j -public class FluentValidator { - /** - * 验证器链,惰性求值期间就是不断的改变这个链表,及时求值期间就是遍历链表依次执行验证 - */ - private List validateElementList = new ArrayList<>(); - - /** - * 验证器上下文 - */ - private ValidateContext context = new ValidateContext(); - - /** - * 私有构造方法,只能通过checkAll创建对象 - */ - private FluentValidator() { - } - - /** - * 创建FluentValidator对象 - * - * @return - */ - public static FluentValidator checkAll() { - return new FluentValidator(); - } - - /** - * 使用验证器进行验证 - * - * @param validator 验证器 - * @return - */ - public FluentValidator on(Class validator) { - validateElementList.add(new ValidateElement(null, validator)); - return this; - } - - /** - * 使用验证器验证指定对象 - * - * @param t 待验证对象 - * @param validator 验证器 - * @return - */ - public FluentValidator on(T t, Class validator) { - validateElementList.add(new ValidateElement(t, validator)); - return this; - } - - /** - * 使用验证器验证指定对象 - * - * @param t 待验证对象 - * @param validator 验证器 - * @param condition 条件,为true时才会将验证器加入验证器列表中 - * @return - */ - public FluentValidator on(T t, Class validator, boolean condition) { - if (condition) { - validateElementList.add(new ValidateElement(t, validator)); - } - return this; - } - - /** - * 执行各个验证器中的验证逻辑 - * - * @return - */ - public FluentValidator doValidate() { - if (CollectionUtils.isEmpty(validateElementList)) { - log.info("Nothing to validate"); - return null; - } - try { - for (ValidateElement element : validateElementList) { - Object target = element.getTarget(); - Validator validator = (Validator) ApplicationContextHelper.getBean(element.getValidator()); - validator.validate(context, target); - } - } catch (Exception e) { - log.error("FluentValidator.doValidate error ", e); - throw e; - } - return this; - } - - /** - * 转换为对外的验证结果,在FluentValidator.on(..).on(..).doValidate()这一连串计算后的“及时求值”收殓出口。 - * - * @return 对外验证结果 - */ - public ValidateResult result() { - return context.result(); - } - - /** - * 将键值对放入上下文 - * - * @param key 键 - * @param value 值 - * @return FluentValidator - */ - public FluentValidator putAttribute2Context(ValidateContextAttrKey key, Object value) { - if (context == null) { - context = new ValidateContext(); - } - context.setAttribute(key, value); - return this; - } - - /** - * 获取验证器上下文 - */ - public ValidateContext getContext() { - return context; - } - -} diff --git a/src/main/java/common/util/validate/Validator.java b/src/main/java/common/util/validate/Validator.java deleted file mode 100644 index 40bb83eb..00000000 --- a/src/main/java/common/util/validate/Validator.java +++ /dev/null @@ -1,24 +0,0 @@ -package common.util.validate; - -import common.util.validate.context.ValidateContext; - -/** - * 验证器接口。 - *

- * 泛型T表示待验证对象的类型 - * - */ -public interface Validator { - - /** - * 执行验证 - *

- * 如果发生错误内部需要调用{@link ValidateContext#addErrorMsg(String)}方法,也即context.addErrorMsg(String) - * 来添加错误,该错误会被添加到结果存根{@link ValidateContext#result()} 的错误消息列表中。 - * - * @param context 验证上下文 - * @param t 待验证对象 - */ - void validate(ValidateContext context, T t); - -} diff --git a/src/main/java/common/util/validate/context/ValidateContext.java b/src/main/java/common/util/validate/context/ValidateContext.java deleted file mode 100644 index 81d89648..00000000 --- a/src/main/java/common/util/validate/context/ValidateContext.java +++ /dev/null @@ -1,127 +0,0 @@ -package common.util.validate.context; - -import org.apache.commons.collections4.MapUtils; - -import java.math.BigDecimal; -import java.util.HashMap; -import java.util.Map; - -/** - * 验证器在执行调用过程中的上下文 - * 1.验证器中的数据传递共享 - * 2.验证结果数据缓存以作后续使用 - * Created by nibnait on 2021/08/22 - */ -public class ValidateContext { - /** - * 验证器均可以共享使用的属性键值对 - */ - private Map attributes; - - /** - * 调用结果对象 - */ - public ValidateResult result = new ValidateResult(); - - /** - * 添加错误信息 - * - * @param msg 错误信息 - */ - public void addErrorMsg(String msg) { - result.addError(msg); - } - - public ValidateResult result() { - return result; - } - - /** - * 设置属性值 - * - * @param key 键 - * @param value 值 - */ - public void setAttribute(ValidateContextAttrKey key, Object value) { - if (attributes == null) { - attributes = new HashMap<>(); - } - attributes.put(key, value); - } - - /** - * 获取对象 - * - * @param key - * @param - * @return - */ - public T get(ValidateContextAttrKey key) { - return (T) getAttribute(key); - } - - /** - * 获取属性 - * - * @param key 键 - * @return 值 - */ - public Object getAttribute(ValidateContextAttrKey key) { - if (MapUtils.isNotEmpty(attributes)) { - return attributes.get(key); - } - return null; - } - - /** - * 获取String值 - * - * @param key - * @return - */ - public String getString(ValidateContextAttrKey key) { - return (String) getAttribute(key); - } - - /** - * 获取Integer值 - * - * @param key - * @return - */ - public Integer getInteger(ValidateContextAttrKey key) { - return (Integer) getAttribute(key); - } - - /** - * 获取Boolean值 - * - * @param key - * @return - */ - public Boolean getBoolean(ValidateContextAttrKey key) { - return (Boolean) getAttribute(key); - } - - - /** - * 获取Long值 - * - * @param key - * @return - */ - public Long getLong(ValidateContextAttrKey key) { - return (Long) getAttribute(key); - } - - /** - * 获取BigDecimal值 - * - * @param key - * @return - */ - public BigDecimal getBigDecimal(ValidateContextAttrKey key) { - return (BigDecimal) getAttribute(key); - } - -} diff --git a/src/main/java/common/util/validate/context/ValidateContextAttrKey.java b/src/main/java/common/util/validate/context/ValidateContextAttrKey.java deleted file mode 100644 index 87e4698b..00000000 --- a/src/main/java/common/util/validate/context/ValidateContextAttrKey.java +++ /dev/null @@ -1,22 +0,0 @@ -package common.util.validate.context; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -import java.util.Map; - -/** - * Created by nibnait on 2021/08/22 - */ -@Getter -@AllArgsConstructor -public enum ValidateContextAttrKey { - - TAG_NAME_MAP("tagMap", Map.class), - - ; - - private String description; - private Class attrClass; - -} diff --git a/src/main/java/common/util/validate/context/ValidateElement.java b/src/main/java/common/util/validate/context/ValidateElement.java deleted file mode 100644 index 71a0209b..00000000 --- a/src/main/java/common/util/validate/context/ValidateElement.java +++ /dev/null @@ -1,23 +0,0 @@ -package common.util.validate.context; - -import lombok.AllArgsConstructor; -import lombok.Getter; - -/** - * 验证器包装类 - * Created by nibnait on 2021/08/22 - */ -@Getter -@AllArgsConstructor -public class ValidateElement { - /** - * 待验证对象 - */ - private Object target; - - /** - * 验证器 - */ - private Class validator; - -} diff --git a/src/main/java/common/util/validate/context/ValidateResult.java b/src/main/java/common/util/validate/context/ValidateResult.java deleted file mode 100644 index 9de8d400..00000000 --- a/src/main/java/common/util/validate/context/ValidateResult.java +++ /dev/null @@ -1,34 +0,0 @@ -package common.util.validate.context; - -import lombok.Data; - -import java.util.ArrayList; -import java.util.List; - -/** - * 内部用验证结果 - * - */ -@Data -public class ValidateResult { - - /** - * 是否成功,一旦发生错误,即置为false,默认为{@value} - */ - private boolean isSuccess = true; - - /** - * 验证错误 - */ - private List errorMsg = new ArrayList<>(); - - /** - * 添加错误 - * - * @param error 错误 - */ - public void addError(String error) { - errorMsg.add(error); - } - -} diff --git a/src/main/java/common/util/validate/validator/OperatorValidator.java b/src/main/java/common/util/validate/validator/OperatorValidator.java deleted file mode 100644 index bd77eb58..00000000 --- a/src/main/java/common/util/validate/validator/OperatorValidator.java +++ /dev/null @@ -1,29 +0,0 @@ -package common.util.validate.validator; - -import common.model.Person; -import common.util.validate.Validator; -import common.util.validate.context.ValidateContext; -import io.github.nibnait.common.exception.ClientViewException; -import org.apache.commons.lang3.StringUtils; - -/** - * Created by nibnait on 2021/08/22 - */ -public class OperatorValidator implements Validator { - - /** - * 执行验证 - *

- * 如果发生错误内部需要调用{@link ValidateContext#addErrorMsg(String)}方法,也即context.addErrorMsg(String) - * 来添加错误,该错误会被添加到结果存根{@link ValidateContext#result()} 的错误消息列表中。 - * - * @param context 验证上下文 - * @param person 待验证对象 - */ - @Override - public void validate(ValidateContext context, Person person) { - if (StringUtils.isBlank(person.getName())) { - throw new ClientViewException("用户名 不能为空"); - } - } -} diff --git a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java index 9a135fb4..8133043f 100644 --- a/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java +++ b/src/main/test/cc/tianbin/java/mybatis/MybatisTest.java @@ -1,6 +1,5 @@ package cc.tianbin.java.mybatis; -import org.apache.ibatis.binding.MapperMethod; import org.junit.Test; /** From cbd686eb93c4c97a13f5c64f2ec86f77d525f92a Mon Sep 17 00:00:00 2001 From: tianbin Date: Mon, 6 Mar 2023 16:50:41 +0800 Subject: [PATCH 32/36] update --- .../E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git "a/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" index 42220dd6..02c86da4 100644 --- "a/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" +++ "b/src/main/java/cc/tianbin/algorithm_practice/LeetCode/code200/E234_\345\233\236\346\226\207\351\223\276\350\241\250.java" @@ -51,7 +51,7 @@ public boolean isPalindrome(ListNode head) { ListNode p2 = head; int count = 1; while (p2.next != null && p2.next.next != null) { - ListNode cur = p1.next; + p1 = p1.next; p2 = p2.next.next; count++; } From ffb4f063746c075686317149b7f358702a754770 Mon Sep 17 00:00:00 2001 From: tianbin Date: Sat, 25 Mar 2023 22:29:35 +0800 Subject: [PATCH 33/36] =?UTF-8?q?feat=20spi=E7=9B=B8=E5=85=B3=20demo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .obsidian/community-plugins.json | 3 + .obsidian/core-plugins-migration.json | 29 + .obsidian/core-plugins.json | 1 + .obsidian/hotkeys.json | 62 +- .../plugins/table-editor-obsidian/data.json | 6 + .../plugins/table-editor-obsidian/main.js | 24038 ++++++++++++++++ .../table-editor-obsidian/manifest.json | 12 + .../plugins/table-editor-obsidian/styles.css | 78 + .obsidian/workspace.json | 38 +- pom.xml | 36 +- ...\350\267\257\345\276\204\345\222\214.java" | 92 + ...\345\255\220\346\225\260\347\273\204.java" | 77 + ...\347\202\271\346\270\270\346\210\217.java" | 128 + .../java/cc/tianbin/demo/java/spi/README.md | 44 + .../spi/dubboSPI/DistributedArchitecture.java | 11 + .../java/spi/dubboSPI/Main_Dubbo_SPI.java | 37 + .../java/spi/dubboSPI/impl/DubboImpl.java | 14 + .../spi/dubboSPI/impl/ServiceMeshImpl.java | 14 + .../spi/dubboSPI/impl/SpringCloudImpl.java | 15 + .../demo/java/spi/javaSPI/JdbcDemo.java | 35 + .../cc/tianbin/demo/java/spi/javaSPI/Log.java | 10 + .../demo/java/spi/javaSPI/Main_Java_SPI.java | 41 + .../demo/java/spi/javaSPI/impl/Log4jImpl.java | 14 + .../java/spi/javaSPI/impl/LogbackImpl.java | 14 + .../demo/java/spi/javaSPI/impl/Sfl4jImpl.java | 14 + .../java/spi/springSPI/Main_Spring_SPI.java | 39 + .../SpringApplicationContextInitializer.java | 16 + .../java/spi/springSPI/SpringXXXListener.java | 10 + .../impl/SpringXXXListenerImpl01.java | 14 + .../impl/SpringXXXListenerImpl02.java | 14 + .../JUC/JUC_demo/DisruptorDemo.java" | 21 +- .../thread_demo/README.md" | 113 +- .../thread_demo/ThreadDemo1.java" | 38 + .../thread_demo/ThreadDemo2.java" | 18 + .../thread_demo/ThreadDemo3.java" | 24 + .../thread_demo/ThreadDemo4.java" | 23 + .../threadpool/Main.java" | 30 + .../java/\345\274\202\345\270\270/README.md" | 18 + .../\347\273\247\346\211\277/HelloA.java" | 20 + .../\347\273\247\346\211\277/HelloB.java" | 27 + .../LockAndAqs.java" | 25 - .../JUC/JUC_AQS/mylock/MyLock.java" | 93 - .../JUC/JUC_AQS/mylock/MyLockTest.java" | 55 - .../OddEvenPrint.java" | 57 - .../Map\347\261\273.java" | 49 - src/main/resources/META-INF/MANIFEST.MF | 3 - ....java.spi.dubboSPI.DistributedArchitecture | 3 + .../cc.tianbin.demo.java.spi.javaSPI.Log | 3 + src/main/resources/META-INF/spring.factories | 7 + src/main/test/cc/tianbin/demo/Main.java | 11 +- .../cc/tianbin/demo/temp/JsonParseTest.java | 31 +- 51 files changed, 25301 insertions(+), 324 deletions(-) create mode 100644 .obsidian/community-plugins.json create mode 100644 .obsidian/core-plugins-migration.json create mode 100644 .obsidian/plugins/table-editor-obsidian/data.json create mode 100644 .obsidian/plugins/table-editor-obsidian/main.js create mode 100644 .obsidian/plugins/table-editor-obsidian/manifest.json create mode 100644 .obsidian/plugins/table-editor-obsidian/styles.css create mode 100644 "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code000/M064_\346\234\200\345\260\217\350\267\257\345\276\204\345\222\214.java" create mode 100644 "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code500/M560_\345\222\214\344\270\272K\347\232\204\345\255\220\346\225\260\347\273\204.java" create mode 100644 "src/main/java/cc/tianbin/algorithm_practice/LeetCode/code600/H679_24\347\202\271\346\270\270\346\210\217.java" create mode 100644 src/main/java/cc/tianbin/demo/java/spi/README.md create mode 100644 src/main/java/cc/tianbin/demo/java/spi/dubboSPI/DistributedArchitecture.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/dubboSPI/Main_Dubbo_SPI.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/dubboSPI/impl/DubboImpl.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/dubboSPI/impl/ServiceMeshImpl.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/dubboSPI/impl/SpringCloudImpl.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/javaSPI/JdbcDemo.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/javaSPI/Log.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/javaSPI/Main_Java_SPI.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/javaSPI/impl/Log4jImpl.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/javaSPI/impl/LogbackImpl.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/javaSPI/impl/Sfl4jImpl.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/springSPI/Main_Spring_SPI.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/springSPI/SpringApplicationContextInitializer.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/springSPI/SpringXXXListener.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/springSPI/impl/SpringXXXListenerImpl01.java create mode 100644 src/main/java/cc/tianbin/demo/java/spi/springSPI/impl/SpringXXXListenerImpl02.java create mode 100644 "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/thread_demo/ThreadDemo1.java" create mode 100644 "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/thread_demo/ThreadDemo2.java" create mode 100644 "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/thread_demo/ThreadDemo3.java" create mode 100644 "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/thread_demo/ThreadDemo4.java" create mode 100644 "src/main/java/cc/tianbin/demo/java/\345\271\266\345\217\221/threadpool/Main.java" create mode 100644 "src/main/java/cc/tianbin/demo/java/\345\274\202\345\270\270/README.md" create mode 100644 "src/main/java/cc/tianbin/demo/java/\347\273\247\346\211\277/HelloA.java" create mode 100644 "src/main/java/cc/tianbin/demo/java/\347\273\247\346\211\277/HelloB.java" delete mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/AQS\346\272\220\347\240\201\351\230\205\350\257\273/LockAndAqs.java" delete mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLock.java" delete mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/JUC/JUC_AQS/mylock/MyLockTest.java" delete mode 100644 "src/main/java/cc/tianbin/java/\345\271\266\345\217\221/threadpool/\350\256\2513\344\270\252\347\272\277\347\250\213\351\241\272\345\272\217\346\211\247\350\241\214/OddEvenPrint.java" delete mode 100644 "src/main/java/cc/tianbin/java/\351\233\206\345\220\210/Map\347\261\273.java" delete mode 100644 src/main/resources/META-INF/MANIFEST.MF create mode 100644 src/main/resources/META-INF/dubbo/internal/cc.tianbin.demo.java.spi.dubboSPI.DistributedArchitecture create mode 100644 src/main/resources/META-INF/services/cc.tianbin.demo.java.spi.javaSPI.Log create mode 100644 src/main/resources/META-INF/spring.factories diff --git a/.obsidian/community-plugins.json b/.obsidian/community-plugins.json new file mode 100644 index 00000000..7e0c513c --- /dev/null +++ b/.obsidian/community-plugins.json @@ -0,0 +1,3 @@ +[ + "table-editor-obsidian" +] \ No newline at end of file diff --git a/.obsidian/core-plugins-migration.json b/.obsidian/core-plugins-migration.json new file mode 100644 index 00000000..0f4e0de4 --- /dev/null +++ b/.obsidian/core-plugins-migration.json @@ -0,0 +1,29 @@ +{ + "file-explorer": true, + "global-search": true, + "switcher": true, + "graph": true, + "backlink": true, + "outgoing-link": true, + "tag-pane": true, + "page-preview": true, + "daily-notes": true, + "templates": true, + "note-composer": true, + "command-palette": true, + "slash-command": false, + "editor-status": true, + "starred": true, + "markdown-importer": false, + "zk-prefixer": false, + "random-note": false, + "outline": true, + "word-count": true, + "slides": false, + "audio-recorder": false, + "workspaces": false, + "file-recovery": true, + "publish": false, + "sync": false, + "canvas": true +} \ No newline at end of file diff --git a/.obsidian/core-plugins.json b/.obsidian/core-plugins.json index 96869dfd..086a8e4e 100644 --- a/.obsidian/core-plugins.json +++ b/.obsidian/core-plugins.json @@ -4,6 +4,7 @@ "switcher", "graph", "backlink", + "canvas", "outgoing-link", "tag-pane", "page-preview", diff --git a/.obsidian/hotkeys.json b/.obsidian/hotkeys.json index 9e26dfee..e8760c5a 100644 --- a/.obsidian/hotkeys.json +++ b/.obsidian/hotkeys.json @@ -1 +1,61 @@ -{} \ No newline at end of file +{ + "app:toggle-left-sidebar": [ + { + "modifiers": [], + "key": "F1" + } + ], + "app:toggle-right-sidebar": [ + { + "modifiers": [], + "key": "F4" + } + ], + "editor:set-heading-1": [], + "editor:set-heading-2": [ + { + "modifiers": [ + "Mod" + ], + "key": "2" + } + ], + "editor:set-heading-3": [ + { + "modifiers": [ + "Mod" + ], + "key": "3" + } + ], + "editor:set-heading-4": [ + { + "modifiers": [ + "Mod" + ], + "key": "4" + } + ], + "editor:set-heading": [ + { + "modifiers": [ + "Mod" + ], + "key": "1" + } + ], + "workspace:goto-tab-1": [], + "workspace:goto-tab-2": [], + "workspace:goto-tab-3": [], + "workspace:goto-tab-4": [], + "app:open-help": [], + "table-editor-obsidian:format-all-tables": [ + { + "modifiers": [ + "Alt", + "Mod" + ], + "key": "L" + } + ] +} \ No newline at end of file diff --git a/.obsidian/plugins/table-editor-obsidian/data.json b/.obsidian/plugins/table-editor-obsidian/data.json new file mode 100644 index 00000000..90094659 --- /dev/null +++ b/.obsidian/plugins/table-editor-obsidian/data.json @@ -0,0 +1,6 @@ +{ + "formatType": "normal", + "showRibbonIcon": true, + "bindEnter": true, + "bindTab": true +} \ No newline at end of file diff --git a/.obsidian/plugins/table-editor-obsidian/main.js b/.obsidian/plugins/table-editor-obsidian/main.js new file mode 100644 index 00000000..ad79700e --- /dev/null +++ b/.obsidian/plugins/table-editor-obsidian/main.js @@ -0,0 +1,24038 @@ +'use strict'; + +var obsidian = require('obsidian'); +var state = require('@codemirror/state'); +var view = require('@codemirror/view'); + +/*! ***************************************************************************** +Copyright (c) Microsoft Corporation. + +Permission to use, copy, modify, and/or distribute this software for any +purpose with or without fee is hereby granted. + +THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +PERFORMANCE OF THIS SOFTWARE. +***************************************************************************** */ +/* global Reflect, Promise */ + +var extendStatics = function(d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; + return extendStatics(d, b); +}; + +function __extends(d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); +} + +var __assign = function() { + __assign = Object.assign || function __assign(t) { + for (var s, i = 1, n = arguments.length; i < n; i++) { + s = arguments[i]; + for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; + } + return t; + }; + return __assign.apply(this, arguments); +}; + +function __awaiter(thisArg, _arguments, P, generator) { + function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); } + return new (P || (P = Promise))(function (resolve, reject) { + function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } } + function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } } + function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); } + step((generator = generator.apply(thisArg, _arguments || [])).next()); + }); +} + +function __generator(thisArg, body) { + var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g; + return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g; + function verb(n) { return function (v) { return step([n, v]); }; } + function step(op) { + if (f) throw new TypeError("Generator is already executing."); + while (_) try { + if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t; + if (y = 0, t) op = [op[0] & 2, t.value]; + switch (op[0]) { + case 0: case 1: t = op; break; + case 4: _.label++; return { value: op[1], done: false }; + case 5: _.label++; y = op[1]; op = [0]; continue; + case 7: op = _.ops.pop(); _.trys.pop(); continue; + default: + if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; } + if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; } + if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; } + if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; } + if (t[2]) _.ops.pop(); + _.trys.pop(); continue; + } + op = body.call(thisArg, _); + } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; } + if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true }; + } +} + +var icons = { + spreadsheet: "\n\n \n", + alignLeft: "\n\n \n \n \n \n \n \n", + alignCenter: "\n\n \n \n \n \n \n \n", + alignRight: "\n\n \n \n \n \n", + deleteColumn: "\n\n \n \n", + deleteRow: "\n\n \n \n \n", + insertColumn: "\n\n \n \n \n \n \n \n", + insertRow: "\n\n \n \n \n \n \n \n", + moveColumnLeft: "\n\n \n \n \n", + moveColumnRight: "\n\n \n \n \n", + moveRowDown: "\n\n \n \n \n", + moveRowUp: "\n\n \n \n \n", + sortAsc: "\n\n \n \n \n \n \n \n", + sortDesc: "\n\n \n \n \n \n \n \n", + formula: "\n\n \n \n", + help: "\n\n \n \n \n", + csv: "\n\n \n", + arrowenter: "\n\n \n", + arrowtab: "\n\n \n", +}; +var addIcons = function () { + Object.keys(icons).forEach(function (key) { + // Don't add the 'help' icon here as it will overwrite the native one. + if (key !== 'help') { + obsidian.addIcon(key, icons[key]); + } + }); +}; + +var commonjsGlobal = typeof globalThis !== 'undefined' ? globalThis : typeof window !== 'undefined' ? window : typeof global !== 'undefined' ? global : typeof self !== 'undefined' ? self : {}; + +function createCommonjsModule(fn, basedir, module) { + return module = { + path: basedir, + exports: {}, + require: function (path, base) { + return commonjsRequire(path, (base === undefined || base === null) ? module.path : base); + } + }, fn(module, module.exports), module.exports; +} + +function getAugmentedNamespace(n) { + if (n.__esModule) return n; + var a = Object.defineProperty({}, '__esModule', {value: true}); + Object.keys(n).forEach(function (k) { + var d = Object.getOwnPropertyDescriptor(n, k); + Object.defineProperty(a, k, d.get ? d : { + enumerable: true, + get: function () { + return n[k]; + } + }); + }); + return a; +} + +function commonjsRequire () { + throw new Error('Dynamic requires are not currently supported by @rollup/plugin-commonjs'); +} + +var point = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Point = void 0; +/** + * A `Point` represents a point in the text editor. + */ +class Point { + /** + * Creates a new `Point` object. + * + * @param row - Row of the point, starts from 0. + * @param column - Column of the point, starts from 0. + */ + constructor(row, column) { + this.row = row; + this.column = column; + } + /** + * Checks if the point is equal to another point. + */ + equals(point) { + return this.row === point.row && this.column === point.column; + } +} +exports.Point = Point; +}); + +var range = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Range = void 0; +/** + * A `Range` object represents a range in the text editor. + */ +class Range { + /** + * Creates a new `Range` object. + * + * @param start - The start point of the range. + * @param end - The end point of the range. + */ + constructor(start, end) { + this.start = start; + this.end = end; + } +} +exports.Range = Range; +}); + +var focus = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Focus = void 0; +/** + * A `Focus` object represents which cell is focused in the table. + * + * Note that `row` and `column` properties specifiy a cell's position in the + * table, not the cursor's position in the text editor as {@link Point} class. + * + * @private + */ +class Focus { + /** + * Creates a new `Focus` object. + * + * @param row - Row of the focused cell. + * @param column - Column of the focused cell. + * @param offset - Raw offset in the cell. + */ + constructor(row, column, offset) { + this.row = row; + this.column = column; + this.offset = offset; + } + /** + * Checks if two focuses point the same cell. + * Offsets are ignored. + */ + posEquals(focus) { + return this.row === focus.row && this.column === focus.column; + } + /** + * Creates a copy of the focus object by setting its row to the specified value. + * + * @param row - Row of the focused cell. + * @returns A new focus object with the specified row. + */ + setRow(row) { + return new Focus(row, this.column, this.offset); + } + /** + * Creates a copy of the focus object by setting its column to the specified value. + * + * @param column - Column of the focused cell. + * @returns A new focus object with the specified column. + */ + setColumn(column) { + return new Focus(this.row, column, this.offset); + } + /** + * Creates a copy of the focus object by setting its offset to the specified value. + * + * @param offset - Offset in the focused cell. + * @returns A new focus object with the specified offset. + */ + setOffset(offset) { + return new Focus(this.row, this.column, offset); + } +} +exports.Focus = Focus; +}); + +var alignment = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.HeaderAlignment = exports.DefaultAlignment = exports.Alignment = void 0; +/** + * Represents column alignment. + * + * - `Alignment.NONE` - Use default alignment. + * - `Alignment.LEFT` - Align left. + * - `Alignment.RIGHT` - Align right. + * - `Alignment.CENTER` - Align center. + * + */ +var Alignment; +(function (Alignment) { + Alignment["NONE"] = "none"; + Alignment["LEFT"] = "left"; + Alignment["RIGHT"] = "right"; + Alignment["CENTER"] = "center"; +})(Alignment = exports.Alignment || (exports.Alignment = {})); +/** + * Represents default column alignment + * + * - `DefaultAlignment.LEFT` - Align left. + * - `DefaultAlignment.RIGHT` - Align right. + * - `DefaultAlignment.CENTER` - Align center. + * + */ +var DefaultAlignment; +(function (DefaultAlignment) { + DefaultAlignment["LEFT"] = "left"; + DefaultAlignment["RIGHT"] = "right"; + DefaultAlignment["CENTER"] = "center"; +})(DefaultAlignment = exports.DefaultAlignment || (exports.DefaultAlignment = {})); +/** + * Represents alignment of header cells. + * + * - `HeaderAlignment.FOLLOW` - Follow column's alignment. + * - `HeaderAlignment.LEFT` - Align left. + * - `HeaderAlignment.RIGHT` - Align right. + * - `HeaderAlignment.CENTER` - Align center. + * + */ +var HeaderAlignment; +(function (HeaderAlignment) { + HeaderAlignment["FOLLOW"] = "follow"; + HeaderAlignment["LEFT"] = "left"; + HeaderAlignment["RIGHT"] = "right"; + HeaderAlignment["CENTER"] = "center"; +})(HeaderAlignment = exports.HeaderAlignment || (exports.HeaderAlignment = {})); +}); + +var tableCell = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TableCell = void 0; + +/** + * A `TableCell` object represents a table cell. + * + * @private + */ +class TableCell { + /** + * Creates a new `TableCell` object. + * + * @param rawContent - Raw content of the cell. + */ + constructor(rawContent) { + this.rawContent = rawContent; + this.content = rawContent.trim(); + this.paddingLeft = + this.content === '' + ? this.rawContent === '' + ? 0 + : 1 + : this.rawContent.length - this.rawContent.trimLeft().length; + this.paddingRight = + this.rawContent.length - this.content.length - this.paddingLeft; + } + /** + * Convers the cell to a text representation. + * + * @returns The raw content of the cell. + */ + toText() { + return this.rawContent; + } + /** + * Checks if the cell is a delimiter i.e. it only contains hyphens `-` with optional one + * leading and trailing colons `:`. + * + * @returns `true` if the cell is a delimiter. + */ + isDelimiter() { + return /^\s*:?-+:?\s*$/.test(this.rawContent); + } + /** + * Returns the alignment the cell represents. + * + * @returns The alignment the cell represents; `undefined` if the cell is not a delimiter. + */ + getAlignment() { + if (!this.isDelimiter()) { + return undefined; + } + if (this.content[0] === ':') { + if (this.content[this.content.length - 1] === ':') { + return alignment.Alignment.CENTER; + } + return alignment.Alignment.LEFT; + } + if (this.content[this.content.length - 1] === ':') { + return alignment.Alignment.RIGHT; + } + return alignment.Alignment.NONE; + } + /** + * Computes a relative position in the trimmed content from that in the raw content. + * + * @param rawOffset - Relative position in the raw content. + * @returns - Relative position in the trimmed content. + */ + computeContentOffset(rawOffset) { + if (this.content === '') { + return 0; + } + if (rawOffset < this.paddingLeft) { + return 0; + } + if (rawOffset < this.paddingLeft + this.content.length) { + return rawOffset - this.paddingLeft; + } + return this.content.length; + } + /** + * Computes a relative position in the raw content from that in the trimmed content. + * + * @param contentOffset - Relative position in the trimmed content. + * @returns - Relative position in the raw content. + */ + computeRawOffset(contentOffset) { + return contentOffset + this.paddingLeft; + } +} +exports.TableCell = TableCell; +}); + +var tableRow = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.TableRow = void 0; + +/** + * A `TableRow` object represents a table row. + * + * @private + */ +class TableRow { + /** + * Creates a new `TableRow` objec. + * + * @param cells - Cells that the row contains. + * @param marginLeft - Margin string at the left of the row. + * @param marginRight - Margin string at the right of the row. + */ + constructor(cells, marginLeft, marginRight) { + this._cells = cells.slice(); + this.marginLeft = marginLeft; + this.marginRight = marginRight; + } + /** + * Gets the number of the cells in the row. + */ + getWidth() { + return this._cells.length; + } + /** + * Returns the cells that the row contains. + */ + getCells() { + return this._cells.slice(); + } + /** + * Gets a cell at the specified index. + * + * @param index - Index. + * @returns The cell at the specified index if exists; `undefined` if no cell is found. + */ + getCellAt(index) { + return this._cells[index]; + } + /** + * Sets a cell in the row to a new value, returning a copy of the row + * with the modified value. + * + * If an invalid index is provided, the row will be unchanged. + */ + setCellAt(index, value) { + const cells = this.getCells(); // a copy + cells[index] = new tableCell.TableCell(value); + return new TableRow(cells, this.marginLeft, this.marginRight); + } + /** + * Convers the row to a text representation. + */ + toText() { + if (this._cells.length === 0) { + return this.marginLeft; + } + const cells = this._cells.map((cell) => cell.toText()).join('|'); + return `${this.marginLeft}|${cells}|${this.marginRight}`; + } + /** + * Checks if the row is a delimiter or not. + * + * @returns `true` if the row is a delimiter i.e. all the cells contained are delimiters. + */ + isDelimiter() { + return this._cells.every((cell) => cell.isDelimiter()); + } +} +exports.TableRow = TableRow; +}); + +var neverthrow = createCommonjsModule(function (module, exports) { +/** + * Retrieved from + * https://github.com/supermacro/neverthrow + * + * MIT License + * Copyright (c) 2019 Giorgio Delgado + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.Err = exports.Ok = exports.err = exports.ok = void 0; +const ok = (value) => new Ok(value); +exports.ok = ok; +const err = (err) => new Err(err); +exports.err = err; +class Ok { + constructor(value) { + this.value = value; + this.match = (ok, _err) => ok(this.value); + } + isOk() { + return true; + } + isErr() { + return !this.isOk(); + } + map(f) { + return exports.ok(f(this.value)); + } + mapErr(_f) { + return exports.ok(this.value); + } + // add info on how this is really useful for converting a + // Result, E1> + // into a Result + andThen(f) { + return f(this.value); + } + unwrapOr(_v) { + return this.value; + } + _unsafeUnwrap() { + return this.value; + } + _unsafeUnwrapErr() { + throw new Error('Called `_unsafeUnwrapErr` on an Ok'); + } +} +exports.Ok = Ok; +class Err { + constructor(error) { + this.error = error; + this.match = (_ok, err) => err(this.error); + } + isOk() { + return false; + } + isErr() { + return !this.isOk(); + } + map(_f) { + return exports.err(this.error); + } + mapErr(f) { + return exports.err(f(this.error)); + } + andThen(_f) { + return exports.err(this.error); + } + unwrapOr(v) { + return v; + } + _unsafeUnwrap() { + throw new Error('Called `_unsafeUnwrap` on an Err'); + } + _unsafeUnwrapErr() { + return this.error; + } +} +exports.Err = Err; +}); + +var ast_utils = createCommonjsModule(function (module, exports) { +Object.defineProperty(exports, "__esModule", { value: true }); +exports.prettyPrintAST = exports.checkChildLength = exports.checkType = exports.errRelativeReferenceIndex = exports.errIndex0 = void 0; +exports.errIndex0 = new Error('Index 0 used to create a reference'); +exports.errRelativeReferenceIndex = new Error('Can not use relative reference where absolute reference is required'); +const checkType = (ast, ...expectedTypes) => { + if (expectedTypes.indexOf(ast.type) >= 0) { + return; + } + return new Error(`Formula element '${ast.text}' is a ${ast.type} but expected ` + + `one of ${expectedTypes} in this position.`); +}; +exports.checkType = checkType; +const checkChildLength = (ast, len) => { + if (ast.children.length === len) { + return; + } + return new Error(`Formula element '${ast.text}' was expected to have ${len} ` + + `elements, but had ${ast.children.length}`); +}; +exports.checkChildLength = checkChildLength; +const prettyPrintAST = (token, level = 0) => { + console.log(' '.repeat(level) + + `|-${token.type}${token.children.length === 0 ? '=' + token.text : ''}`); + if (token.children) { + token.children.forEach((c) => { + exports.prettyPrintAST(c, level + 1); + }); + } +}; +exports.prettyPrintAST = prettyPrintAST; +}); + +var lodash = createCommonjsModule(function (module, exports) { +(function() { + + /** Used as a safe reference for `undefined` in pre-ES5 environments. */ + var undefined$1; + + /** Used as the semantic version number. */ + var VERSION = '4.17.20'; + + /** Used as the size to enable large array optimizations. */ + var LARGE_ARRAY_SIZE = 200; + + /** Error message constants. */ + var CORE_ERROR_TEXT = 'Unsupported core-js use. Try https://npms.io/search?q=ponyfill.', + FUNC_ERROR_TEXT = 'Expected a function'; + + /** Used to stand-in for `undefined` hash values. */ + var HASH_UNDEFINED = '__lodash_hash_undefined__'; + + /** Used as the maximum memoize cache size. */ + var MAX_MEMOIZE_SIZE = 500; + + /** Used as the internal argument placeholder. */ + var PLACEHOLDER = '__lodash_placeholder__'; + + /** Used to compose bitmasks for cloning. */ + var CLONE_DEEP_FLAG = 1, + CLONE_FLAT_FLAG = 2, + CLONE_SYMBOLS_FLAG = 4; + + /** Used to compose bitmasks for value comparisons. */ + var COMPARE_PARTIAL_FLAG = 1, + COMPARE_UNORDERED_FLAG = 2; + + /** Used to compose bitmasks for function metadata. */ + var WRAP_BIND_FLAG = 1, + WRAP_BIND_KEY_FLAG = 2, + WRAP_CURRY_BOUND_FLAG = 4, + WRAP_CURRY_FLAG = 8, + WRAP_CURRY_RIGHT_FLAG = 16, + WRAP_PARTIAL_FLAG = 32, + WRAP_PARTIAL_RIGHT_FLAG = 64, + WRAP_ARY_FLAG = 128, + WRAP_REARG_FLAG = 256, + WRAP_FLIP_FLAG = 512; + + /** Used as default options for `_.truncate`. */ + var DEFAULT_TRUNC_LENGTH = 30, + DEFAULT_TRUNC_OMISSION = '...'; + + /** Used to detect hot functions by number of calls within a span of milliseconds. */ + var HOT_COUNT = 800, + HOT_SPAN = 16; + + /** Used to indicate the type of lazy iteratees. */ + var LAZY_FILTER_FLAG = 1, + LAZY_MAP_FLAG = 2, + LAZY_WHILE_FLAG = 3; + + /** Used as references for various `Number` constants. */ + var INFINITY = 1 / 0, + MAX_SAFE_INTEGER = 9007199254740991, + MAX_INTEGER = 1.7976931348623157e+308, + NAN = 0 / 0; + + /** Used as references for the maximum length and index of an array. */ + var MAX_ARRAY_LENGTH = 4294967295, + MAX_ARRAY_INDEX = MAX_ARRAY_LENGTH - 1, + HALF_MAX_ARRAY_LENGTH = MAX_ARRAY_LENGTH >>> 1; + + /** Used to associate wrap methods with their bit flags. */ + var wrapFlags = [ + ['ary', WRAP_ARY_FLAG], + ['bind', WRAP_BIND_FLAG], + ['bindKey', WRAP_BIND_KEY_FLAG], + ['curry', WRAP_CURRY_FLAG], + ['curryRight', WRAP_CURRY_RIGHT_FLAG], + ['flip', WRAP_FLIP_FLAG], + ['partial', WRAP_PARTIAL_FLAG], + ['partialRight', WRAP_PARTIAL_RIGHT_FLAG], + ['rearg', WRAP_REARG_FLAG] + ]; + + /** `Object#toString` result references. */ + var argsTag = '[object Arguments]', + arrayTag = '[object Array]', + asyncTag = '[object AsyncFunction]', + boolTag = '[object Boolean]', + dateTag = '[object Date]', + domExcTag = '[object DOMException]', + errorTag = '[object Error]', + funcTag = '[object Function]', + genTag = '[object GeneratorFunction]', + mapTag = '[object Map]', + numberTag = '[object Number]', + nullTag = '[object Null]', + objectTag = '[object Object]', + promiseTag = '[object Promise]', + proxyTag = '[object Proxy]', + regexpTag = '[object RegExp]', + setTag = '[object Set]', + stringTag = '[object String]', + symbolTag = '[object Symbol]', + undefinedTag = '[object Undefined]', + weakMapTag = '[object WeakMap]', + weakSetTag = '[object WeakSet]'; + + var arrayBufferTag = '[object ArrayBuffer]', + dataViewTag = '[object DataView]', + float32Tag = '[object Float32Array]', + float64Tag = '[object Float64Array]', + int8Tag = '[object Int8Array]', + int16Tag = '[object Int16Array]', + int32Tag = '[object Int32Array]', + uint8Tag = '[object Uint8Array]', + uint8ClampedTag = '[object Uint8ClampedArray]', + uint16Tag = '[object Uint16Array]', + uint32Tag = '[object Uint32Array]'; + + /** Used to match empty string literals in compiled template source. */ + var reEmptyStringLeading = /\b__p \+= '';/g, + reEmptyStringMiddle = /\b(__p \+=) '' \+/g, + reEmptyStringTrailing = /(__e\(.*?\)|\b__t\)) \+\n'';/g; + + /** Used to match HTML entities and HTML characters. */ + var reEscapedHtml = /&(?:amp|lt|gt|quot|#39);/g, + reUnescapedHtml = /[&<>"']/g, + reHasEscapedHtml = RegExp(reEscapedHtml.source), + reHasUnescapedHtml = RegExp(reUnescapedHtml.source); + + /** Used to match template delimiters. */ + var reEscape = /<%-([\s\S]+?)%>/g, + reEvaluate = /<%([\s\S]+?)%>/g, + reInterpolate = /<%=([\s\S]+?)%>/g; + + /** Used to match property names within property paths. */ + var reIsDeepProp = /\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/, + reIsPlainProp = /^\w*$/, + rePropName = /[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g; + + /** + * Used to match `RegExp` + * [syntax characters](http://ecma-international.org/ecma-262/7.0/#sec-patterns). + */ + var reRegExpChar = /[\\^$.*+?()[\]{}|]/g, + reHasRegExpChar = RegExp(reRegExpChar.source); + + /** Used to match leading and trailing whitespace. */ + var reTrim = /^\s+|\s+$/g, + reTrimStart = /^\s+/, + reTrimEnd = /\s+$/; + + /** Used to match wrap detail comments. */ + var reWrapComment = /\{(?:\n\/\* \[wrapped with .+\] \*\/)?\n?/, + reWrapDetails = /\{\n\/\* \[wrapped with (.+)\] \*/, + reSplitDetails = /,? & /; + + /** Used to match words composed of alphanumeric characters. */ + var reAsciiWord = /[^\x00-\x2f\x3a-\x40\x5b-\x60\x7b-\x7f]+/g; + + /** Used to match backslashes in property paths. */ + var reEscapeChar = /\\(\\)?/g; + + /** + * Used to match + * [ES template delimiters](http://ecma-international.org/ecma-262/7.0/#sec-template-literal-lexical-components). + */ + var reEsTemplate = /\$\{([^\\}]*(?:\\.[^\\}]*)*)\}/g; + + /** Used to match `RegExp` flags from their coerced string values. */ + var reFlags = /\w*$/; + + /** Used to detect bad signed hexadecimal string values. */ + var reIsBadHex = /^[-+]0x[0-9a-f]+$/i; + + /** Used to detect binary string values. */ + var reIsBinary = /^0b[01]+$/i; + + /** Used to detect host constructors (Safari). */ + var reIsHostCtor = /^\[object .+?Constructor\]$/; + + /** Used to detect octal string values. */ + var reIsOctal = /^0o[0-7]+$/i; + + /** Used to detect unsigned integer values. */ + var reIsUint = /^(?:0|[1-9]\d*)$/; + + /** Used to match Latin Unicode letters (excluding mathematical operators). */ + var reLatin = /[\xc0-\xd6\xd8-\xf6\xf8-\xff\u0100-\u017f]/g; + + /** Used to ensure capturing order of template delimiters. */ + var reNoMatch = /($^)/; + + /** Used to match unescaped characters in compiled string literals. */ + var reUnescapedString = /['\n\r\u2028\u2029\\]/g; + + /** Used to compose unicode character classes. */ + var rsAstralRange = '\\ud800-\\udfff', + rsComboMarksRange = '\\u0300-\\u036f', + reComboHalfMarksRange = '\\ufe20-\\ufe2f', + rsComboSymbolsRange = '\\u20d0-\\u20ff', + rsComboRange = rsComboMarksRange + reComboHalfMarksRange + rsComboSymbolsRange, + rsDingbatRange = '\\u2700-\\u27bf', + rsLowerRange = 'a-z\\xdf-\\xf6\\xf8-\\xff', + rsMathOpRange = '\\xac\\xb1\\xd7\\xf7', + rsNonCharRange = '\\x00-\\x2f\\x3a-\\x40\\x5b-\\x60\\x7b-\\xbf', + rsPunctuationRange = '\\u2000-\\u206f', + rsSpaceRange = ' \\t\\x0b\\f\\xa0\\ufeff\\n\\r\\u2028\\u2029\\u1680\\u180e\\u2000\\u2001\\u2002\\u2003\\u2004\\u2005\\u2006\\u2007\\u2008\\u2009\\u200a\\u202f\\u205f\\u3000', + rsUpperRange = 'A-Z\\xc0-\\xd6\\xd8-\\xde', + rsVarRange = '\\ufe0e\\ufe0f', + rsBreakRange = rsMathOpRange + rsNonCharRange + rsPunctuationRange + rsSpaceRange; + + /** Used to compose unicode capture groups. */ + var rsApos = "['\u2019]", + rsAstral = '[' + rsAstralRange + ']', + rsBreak = '[' + rsBreakRange + ']', + rsCombo = '[' + rsComboRange + ']', + rsDigits = '\\d+', + rsDingbat = '[' + rsDingbatRange + ']', + rsLower = '[' + rsLowerRange + ']', + rsMisc = '[^' + rsAstralRange + rsBreakRange + rsDigits + rsDingbatRange + rsLowerRange + rsUpperRange + ']', + rsFitz = '\\ud83c[\\udffb-\\udfff]', + rsModifier = '(?:' + rsCombo + '|' + rsFitz + ')', + rsNonAstral = '[^' + rsAstralRange + ']', + rsRegional = '(?:\\ud83c[\\udde6-\\uddff]){2}', + rsSurrPair = '[\\ud800-\\udbff][\\udc00-\\udfff]', + rsUpper = '[' + rsUpperRange + ']', + rsZWJ = '\\u200d'; + + /** Used to compose unicode regexes. */ + var rsMiscLower = '(?:' + rsLower + '|' + rsMisc + ')', + rsMiscUpper = '(?:' + rsUpper + '|' + rsMisc + ')', + rsOptContrLower = '(?:' + rsApos + '(?:d|ll|m|re|s|t|ve))?', + rsOptContrUpper = '(?:' + rsApos + '(?:D|LL|M|RE|S|T|VE))?', + reOptMod = rsModifier + '?', + rsOptVar = '[' + rsVarRange + ']?', + rsOptJoin = '(?:' + rsZWJ + '(?:' + [rsNonAstral, rsRegional, rsSurrPair].join('|') + ')' + rsOptVar + reOptMod + ')*', + rsOrdLower = '\\d*(?:1st|2nd|3rd|(?![123])\\dth)(?=\\b|[A-Z_])', + rsOrdUpper = '\\d*(?:1ST|2ND|3RD|(?![123])\\dTH)(?=\\b|[a-z_])', + rsSeq = rsOptVar + reOptMod + rsOptJoin, + rsEmoji = '(?:' + [rsDingbat, rsRegional, rsSurrPair].join('|') + ')' + rsSeq, + rsSymbol = '(?:' + [rsNonAstral + rsCombo + '?', rsCombo, rsRegional, rsSurrPair, rsAstral].join('|') + ')'; + + /** Used to match apostrophes. */ + var reApos = RegExp(rsApos, 'g'); + + /** + * Used to match [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks) and + * [combining diacritical marks for symbols](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks_for_Symbols). + */ + var reComboMark = RegExp(rsCombo, 'g'); + + /** Used to match [string symbols](https://mathiasbynens.be/notes/javascript-unicode). */ + var reUnicode = RegExp(rsFitz + '(?=' + rsFitz + ')|' + rsSymbol + rsSeq, 'g'); + + /** Used to match complex or compound words. */ + var reUnicodeWord = RegExp([ + rsUpper + '?' + rsLower + '+' + rsOptContrLower + '(?=' + [rsBreak, rsUpper, '$'].join('|') + ')', + rsMiscUpper + '+' + rsOptContrUpper + '(?=' + [rsBreak, rsUpper + rsMiscLower, '$'].join('|') + ')', + rsUpper + '?' + rsMiscLower + '+' + rsOptContrLower, + rsUpper + '+' + rsOptContrUpper, + rsOrdUpper, + rsOrdLower, + rsDigits, + rsEmoji + ].join('|'), 'g'); + + /** Used to detect strings with [zero-width joiners or code points from the astral planes](http://eev.ee/blog/2015/09/12/dark-corners-of-unicode/). */ + var reHasUnicode = RegExp('[' + rsZWJ + rsAstralRange + rsComboRange + rsVarRange + ']'); + + /** Used to detect strings that need a more robust regexp to match words. */ + var reHasUnicodeWord = /[a-z][A-Z]|[A-Z]{2}[a-z]|[0-9][a-zA-Z]|[a-zA-Z][0-9]|[^a-zA-Z0-9 ]/; + + /** Used to assign default `context` object properties. */ + var contextProps = [ + 'Array', 'Buffer', 'DataView', 'Date', 'Error', 'Float32Array', 'Float64Array', + 'Function', 'Int8Array', 'Int16Array', 'Int32Array', 'Map', 'Math', 'Object', + 'Promise', 'RegExp', 'Set', 'String', 'Symbol', 'TypeError', 'Uint8Array', + 'Uint8ClampedArray', 'Uint16Array', 'Uint32Array', 'WeakMap', + '_', 'clearTimeout', 'isFinite', 'parseInt', 'setTimeout' + ]; + + /** Used to make template sourceURLs easier to identify. */ + var templateCounter = -1; + + /** Used to identify `toStringTag` values of typed arrays. */ + var typedArrayTags = {}; + typedArrayTags[float32Tag] = typedArrayTags[float64Tag] = + typedArrayTags[int8Tag] = typedArrayTags[int16Tag] = + typedArrayTags[int32Tag] = typedArrayTags[uint8Tag] = + typedArrayTags[uint8ClampedTag] = typedArrayTags[uint16Tag] = + typedArrayTags[uint32Tag] = true; + typedArrayTags[argsTag] = typedArrayTags[arrayTag] = + typedArrayTags[arrayBufferTag] = typedArrayTags[boolTag] = + typedArrayTags[dataViewTag] = typedArrayTags[dateTag] = + typedArrayTags[errorTag] = typedArrayTags[funcTag] = + typedArrayTags[mapTag] = typedArrayTags[numberTag] = + typedArrayTags[objectTag] = typedArrayTags[regexpTag] = + typedArrayTags[setTag] = typedArrayTags[stringTag] = + typedArrayTags[weakMapTag] = false; + + /** Used to identify `toStringTag` values supported by `_.clone`. */ + var cloneableTags = {}; + cloneableTags[argsTag] = cloneableTags[arrayTag] = + cloneableTags[arrayBufferTag] = cloneableTags[dataViewTag] = + cloneableTags[boolTag] = cloneableTags[dateTag] = + cloneableTags[float32Tag] = cloneableTags[float64Tag] = + cloneableTags[int8Tag] = cloneableTags[int16Tag] = + cloneableTags[int32Tag] = cloneableTags[mapTag] = + cloneableTags[numberTag] = cloneableTags[objectTag] = + cloneableTags[regexpTag] = cloneableTags[setTag] = + cloneableTags[stringTag] = cloneableTags[symbolTag] = + cloneableTags[uint8Tag] = cloneableTags[uint8ClampedTag] = + cloneableTags[uint16Tag] = cloneableTags[uint32Tag] = true; + cloneableTags[errorTag] = cloneableTags[funcTag] = + cloneableTags[weakMapTag] = false; + + /** Used to map Latin Unicode letters to basic Latin letters. */ + var deburredLetters = { + // Latin-1 Supplement block. + '\xc0': 'A', '\xc1': 'A', '\xc2': 'A', '\xc3': 'A', '\xc4': 'A', '\xc5': 'A', + '\xe0': 'a', '\xe1': 'a', '\xe2': 'a', '\xe3': 'a', '\xe4': 'a', '\xe5': 'a', + '\xc7': 'C', '\xe7': 'c', + '\xd0': 'D', '\xf0': 'd', + '\xc8': 'E', '\xc9': 'E', '\xca': 'E', '\xcb': 'E', + '\xe8': 'e', '\xe9': 'e', '\xea': 'e', '\xeb': 'e', + '\xcc': 'I', '\xcd': 'I', '\xce': 'I', '\xcf': 'I', + '\xec': 'i', '\xed': 'i', '\xee': 'i', '\xef': 'i', + '\xd1': 'N', '\xf1': 'n', + '\xd2': 'O', '\xd3': 'O', '\xd4': 'O', '\xd5': 'O', '\xd6': 'O', '\xd8': 'O', + '\xf2': 'o', '\xf3': 'o', '\xf4': 'o', '\xf5': 'o', '\xf6': 'o', '\xf8': 'o', + '\xd9': 'U', '\xda': 'U', '\xdb': 'U', '\xdc': 'U', + '\xf9': 'u', '\xfa': 'u', '\xfb': 'u', '\xfc': 'u', + '\xdd': 'Y', '\xfd': 'y', '\xff': 'y', + '\xc6': 'Ae', '\xe6': 'ae', + '\xde': 'Th', '\xfe': 'th', + '\xdf': 'ss', + // Latin Extended-A block. + '\u0100': 'A', '\u0102': 'A', '\u0104': 'A', + '\u0101': 'a', '\u0103': 'a', '\u0105': 'a', + '\u0106': 'C', '\u0108': 'C', '\u010a': 'C', '\u010c': 'C', + '\u0107': 'c', '\u0109': 'c', '\u010b': 'c', '\u010d': 'c', + '\u010e': 'D', '\u0110': 'D', '\u010f': 'd', '\u0111': 'd', + '\u0112': 'E', '\u0114': 'E', '\u0116': 'E', '\u0118': 'E', '\u011a': 'E', + '\u0113': 'e', '\u0115': 'e', '\u0117': 'e', '\u0119': 'e', '\u011b': 'e', + '\u011c': 'G', '\u011e': 'G', '\u0120': 'G', '\u0122': 'G', + '\u011d': 'g', '\u011f': 'g', '\u0121': 'g', '\u0123': 'g', + '\u0124': 'H', '\u0126': 'H', '\u0125': 'h', '\u0127': 'h', + '\u0128': 'I', '\u012a': 'I', '\u012c': 'I', '\u012e': 'I', '\u0130': 'I', + '\u0129': 'i', '\u012b': 'i', '\u012d': 'i', '\u012f': 'i', '\u0131': 'i', + '\u0134': 'J', '\u0135': 'j', + '\u0136': 'K', '\u0137': 'k', '\u0138': 'k', + '\u0139': 'L', '\u013b': 'L', '\u013d': 'L', '\u013f': 'L', '\u0141': 'L', + '\u013a': 'l', '\u013c': 'l', '\u013e': 'l', '\u0140': 'l', '\u0142': 'l', + '\u0143': 'N', '\u0145': 'N', '\u0147': 'N', '\u014a': 'N', + '\u0144': 'n', '\u0146': 'n', '\u0148': 'n', '\u014b': 'n', + '\u014c': 'O', '\u014e': 'O', '\u0150': 'O', + '\u014d': 'o', '\u014f': 'o', '\u0151': 'o', + '\u0154': 'R', '\u0156': 'R', '\u0158': 'R', + '\u0155': 'r', '\u0157': 'r', '\u0159': 'r', + '\u015a': 'S', '\u015c': 'S', '\u015e': 'S', '\u0160': 'S', + '\u015b': 's', '\u015d': 's', '\u015f': 's', '\u0161': 's', + '\u0162': 'T', '\u0164': 'T', '\u0166': 'T', + '\u0163': 't', '\u0165': 't', '\u0167': 't', + '\u0168': 'U', '\u016a': 'U', '\u016c': 'U', '\u016e': 'U', '\u0170': 'U', '\u0172': 'U', + '\u0169': 'u', '\u016b': 'u', '\u016d': 'u', '\u016f': 'u', '\u0171': 'u', '\u0173': 'u', + '\u0174': 'W', '\u0175': 'w', + '\u0176': 'Y', '\u0177': 'y', '\u0178': 'Y', + '\u0179': 'Z', '\u017b': 'Z', '\u017d': 'Z', + '\u017a': 'z', '\u017c': 'z', '\u017e': 'z', + '\u0132': 'IJ', '\u0133': 'ij', + '\u0152': 'Oe', '\u0153': 'oe', + '\u0149': "'n", '\u017f': 's' + }; + + /** Used to map characters to HTML entities. */ + var htmlEscapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + "'": ''' + }; + + /** Used to map HTML entities to characters. */ + var htmlUnescapes = { + '&': '&', + '<': '<', + '>': '>', + '"': '"', + ''': "'" + }; + + /** Used to escape characters for inclusion in compiled string literals. */ + var stringEscapes = { + '\\': '\\', + "'": "'", + '\n': 'n', + '\r': 'r', + '\u2028': 'u2028', + '\u2029': 'u2029' + }; + + /** Built-in method references without a dependency on `root`. */ + var freeParseFloat = parseFloat, + freeParseInt = parseInt; + + /** Detect free variable `global` from Node.js. */ + var freeGlobal = typeof commonjsGlobal == 'object' && commonjsGlobal && commonjsGlobal.Object === Object && commonjsGlobal; + + /** Detect free variable `self`. */ + var freeSelf = typeof self == 'object' && self && self.Object === Object && self; + + /** Used as a reference to the global object. */ + var root = freeGlobal || freeSelf || Function('return this')(); + + /** Detect free variable `exports`. */ + var freeExports = exports && !exports.nodeType && exports; + + /** Detect free variable `module`. */ + var freeModule = freeExports && 'object' == 'object' && module && !module.nodeType && module; + + /** Detect the popular CommonJS extension `module.exports`. */ + var moduleExports = freeModule && freeModule.exports === freeExports; + + /** Detect free variable `process` from Node.js. */ + var freeProcess = moduleExports && freeGlobal.process; + + /** Used to access faster Node.js helpers. */ + var nodeUtil = (function() { + try { + // Use `util.types` for Node.js 10+. + var types = freeModule && freeModule.require && freeModule.require('util').types; + + if (types) { + return types; + } + + // Legacy `process.binding('util')` for Node.js < 10. + return freeProcess && freeProcess.binding && freeProcess.binding('util'); + } catch (e) {} + }()); + + /* Node.js helper references. */ + var nodeIsArrayBuffer = nodeUtil && nodeUtil.isArrayBuffer, + nodeIsDate = nodeUtil && nodeUtil.isDate, + nodeIsMap = nodeUtil && nodeUtil.isMap, + nodeIsRegExp = nodeUtil && nodeUtil.isRegExp, + nodeIsSet = nodeUtil && nodeUtil.isSet, + nodeIsTypedArray = nodeUtil && nodeUtil.isTypedArray; + + /*--------------------------------------------------------------------------*/ + + /** + * A faster alternative to `Function#apply`, this function invokes `func` + * with the `this` binding of `thisArg` and the arguments of `args`. + * + * @private + * @param {Function} func The function to invoke. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} args The arguments to invoke `func` with. + * @returns {*} Returns the result of `func`. + */ + function apply(func, thisArg, args) { + switch (args.length) { + case 0: return func.call(thisArg); + case 1: return func.call(thisArg, args[0]); + case 2: return func.call(thisArg, args[0], args[1]); + case 3: return func.call(thisArg, args[0], args[1], args[2]); + } + return func.apply(thisArg, args); + } + + /** + * A specialized version of `baseAggregator` for arrays. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function arrayAggregator(array, setter, iteratee, accumulator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + var value = array[index]; + setter(accumulator, value, iteratee(value), array); + } + return accumulator; + } + + /** + * A specialized version of `_.forEach` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + function arrayEach(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (iteratee(array[index], index, array) === false) { + break; + } + } + return array; + } + + /** + * A specialized version of `_.forEachRight` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns `array`. + */ + function arrayEachRight(array, iteratee) { + var length = array == null ? 0 : array.length; + + while (length--) { + if (iteratee(array[length], length, array) === false) { + break; + } + } + return array; + } + + /** + * A specialized version of `_.every` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + */ + function arrayEvery(array, predicate) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (!predicate(array[index], index, array)) { + return false; + } + } + return true; + } + + /** + * A specialized version of `_.filter` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ + function arrayFilter(array, predicate) { + var index = -1, + length = array == null ? 0 : array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index]; + if (predicate(value, index, array)) { + result[resIndex++] = value; + } + } + return result; + } + + /** + * A specialized version of `_.includes` for arrays without support for + * specifying an index to search from. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ + function arrayIncludes(array, value) { + var length = array == null ? 0 : array.length; + return !!length && baseIndexOf(array, value, 0) > -1; + } + + /** + * This function is like `arrayIncludes` except that it accepts a comparator. + * + * @private + * @param {Array} [array] The array to inspect. + * @param {*} target The value to search for. + * @param {Function} comparator The comparator invoked per element. + * @returns {boolean} Returns `true` if `target` is found, else `false`. + */ + function arrayIncludesWith(array, value, comparator) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (comparator(value, array[index])) { + return true; + } + } + return false; + } + + /** + * A specialized version of `_.map` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ + function arrayMap(array, iteratee) { + var index = -1, + length = array == null ? 0 : array.length, + result = Array(length); + + while (++index < length) { + result[index] = iteratee(array[index], index, array); + } + return result; + } + + /** + * Appends the elements of `values` to `array`. + * + * @private + * @param {Array} array The array to modify. + * @param {Array} values The values to append. + * @returns {Array} Returns `array`. + */ + function arrayPush(array, values) { + var index = -1, + length = values.length, + offset = array.length; + + while (++index < length) { + array[offset + index] = values[index]; + } + return array; + } + + /** + * A specialized version of `_.reduce` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the first element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduce(array, iteratee, accumulator, initAccum) { + var index = -1, + length = array == null ? 0 : array.length; + + if (initAccum && length) { + accumulator = array[++index]; + } + while (++index < length) { + accumulator = iteratee(accumulator, array[index], index, array); + } + return accumulator; + } + + /** + * A specialized version of `_.reduceRight` for arrays without support for + * iteratee shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @param {boolean} [initAccum] Specify using the last element of `array` as + * the initial value. + * @returns {*} Returns the accumulated value. + */ + function arrayReduceRight(array, iteratee, accumulator, initAccum) { + var length = array == null ? 0 : array.length; + if (initAccum && length) { + accumulator = array[--length]; + } + while (length--) { + accumulator = iteratee(accumulator, array[length], length, array); + } + return accumulator; + } + + /** + * A specialized version of `_.some` for arrays without support for iteratee + * shorthands. + * + * @private + * @param {Array} [array] The array to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ + function arraySome(array, predicate) { + var index = -1, + length = array == null ? 0 : array.length; + + while (++index < length) { + if (predicate(array[index], index, array)) { + return true; + } + } + return false; + } + + /** + * Gets the size of an ASCII `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + var asciiSize = baseProperty('length'); + + /** + * Converts an ASCII `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function asciiToArray(string) { + return string.split(''); + } + + /** + * Splits an ASCII `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function asciiWords(string) { + return string.match(reAsciiWord) || []; + } + + /** + * The base implementation of methods like `_.findKey` and `_.findLastKey`, + * without support for iteratee shorthands, which iterates over `collection` + * using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the found element or its key, else `undefined`. + */ + function baseFindKey(collection, predicate, eachFunc) { + var result; + eachFunc(collection, function(value, key, collection) { + if (predicate(value, key, collection)) { + result = key; + return false; + } + }); + return result; + } + + /** + * The base implementation of `_.findIndex` and `_.findLastIndex` without + * support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} predicate The function invoked per iteration. + * @param {number} fromIndex The index to search from. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseFindIndex(array, predicate, fromIndex, fromRight) { + var length = array.length, + index = fromIndex + (fromRight ? 1 : -1); + + while ((fromRight ? index-- : ++index < length)) { + if (predicate(array[index], index, array)) { + return index; + } + } + return -1; + } + + /** + * The base implementation of `_.indexOf` without `fromIndex` bounds checks. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseIndexOf(array, value, fromIndex) { + return value === value + ? strictIndexOf(array, value, fromIndex) + : baseFindIndex(array, baseIsNaN, fromIndex); + } + + /** + * This function is like `baseIndexOf` except that it accepts a comparator. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @param {Function} comparator The comparator invoked per element. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function baseIndexOfWith(array, value, fromIndex, comparator) { + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (comparator(array[index], value)) { + return index; + } + } + return -1; + } + + /** + * The base implementation of `_.isNaN` without support for number objects. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + */ + function baseIsNaN(value) { + return value !== value; + } + + /** + * The base implementation of `_.mean` and `_.meanBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the mean. + */ + function baseMean(array, iteratee) { + var length = array == null ? 0 : array.length; + return length ? (baseSum(array, iteratee) / length) : NAN; + } + + /** + * The base implementation of `_.property` without support for deep paths. + * + * @private + * @param {string} key The key of the property to get. + * @returns {Function} Returns the new accessor function. + */ + function baseProperty(key) { + return function(object) { + return object == null ? undefined$1 : object[key]; + }; + } + + /** + * The base implementation of `_.propertyOf` without support for deep paths. + * + * @private + * @param {Object} object The object to query. + * @returns {Function} Returns the new accessor function. + */ + function basePropertyOf(object) { + return function(key) { + return object == null ? undefined$1 : object[key]; + }; + } + + /** + * The base implementation of `_.reduce` and `_.reduceRight`, without support + * for iteratee shorthands, which iterates over `collection` using `eachFunc`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {*} accumulator The initial value. + * @param {boolean} initAccum Specify using the first or last element of + * `collection` as the initial value. + * @param {Function} eachFunc The function to iterate over `collection`. + * @returns {*} Returns the accumulated value. + */ + function baseReduce(collection, iteratee, accumulator, initAccum, eachFunc) { + eachFunc(collection, function(value, index, collection) { + accumulator = initAccum + ? (initAccum = false, value) + : iteratee(accumulator, value, index, collection); + }); + return accumulator; + } + + /** + * The base implementation of `_.sortBy` which uses `comparer` to define the + * sort order of `array` and replaces criteria objects with their corresponding + * values. + * + * @private + * @param {Array} array The array to sort. + * @param {Function} comparer The function to define sort order. + * @returns {Array} Returns `array`. + */ + function baseSortBy(array, comparer) { + var length = array.length; + + array.sort(comparer); + while (length--) { + array[length] = array[length].value; + } + return array; + } + + /** + * The base implementation of `_.sum` and `_.sumBy` without support for + * iteratee shorthands. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {number} Returns the sum. + */ + function baseSum(array, iteratee) { + var result, + index = -1, + length = array.length; + + while (++index < length) { + var current = iteratee(array[index]); + if (current !== undefined$1) { + result = result === undefined$1 ? current : (result + current); + } + } + return result; + } + + /** + * The base implementation of `_.times` without support for iteratee shorthands + * or max array length checks. + * + * @private + * @param {number} n The number of times to invoke `iteratee`. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the array of results. + */ + function baseTimes(n, iteratee) { + var index = -1, + result = Array(n); + + while (++index < n) { + result[index] = iteratee(index); + } + return result; + } + + /** + * The base implementation of `_.toPairs` and `_.toPairsIn` which creates an array + * of key-value pairs for `object` corresponding to the property names of `props`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} props The property names to get values for. + * @returns {Object} Returns the key-value pairs. + */ + function baseToPairs(object, props) { + return arrayMap(props, function(key) { + return [key, object[key]]; + }); + } + + /** + * The base implementation of `_.unary` without support for storing metadata. + * + * @private + * @param {Function} func The function to cap arguments for. + * @returns {Function} Returns the new capped function. + */ + function baseUnary(func) { + return function(value) { + return func(value); + }; + } + + /** + * The base implementation of `_.values` and `_.valuesIn` which creates an + * array of `object` property values corresponding to the property names + * of `props`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} props The property names to get values for. + * @returns {Object} Returns the array of property values. + */ + function baseValues(object, props) { + return arrayMap(props, function(key) { + return object[key]; + }); + } + + /** + * Checks if a `cache` value for `key` exists. + * + * @private + * @param {Object} cache The cache to query. + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function cacheHas(cache, key) { + return cache.has(key); + } + + /** + * Used by `_.trim` and `_.trimStart` to get the index of the first string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the first unmatched string symbol. + */ + function charsStartIndex(strSymbols, chrSymbols) { + var index = -1, + length = strSymbols.length; + + while (++index < length && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; + } + + /** + * Used by `_.trim` and `_.trimEnd` to get the index of the last string symbol + * that is not found in the character symbols. + * + * @private + * @param {Array} strSymbols The string symbols to inspect. + * @param {Array} chrSymbols The character symbols to find. + * @returns {number} Returns the index of the last unmatched string symbol. + */ + function charsEndIndex(strSymbols, chrSymbols) { + var index = strSymbols.length; + + while (index-- && baseIndexOf(chrSymbols, strSymbols[index], 0) > -1) {} + return index; + } + + /** + * Gets the number of `placeholder` occurrences in `array`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} placeholder The placeholder to search for. + * @returns {number} Returns the placeholder count. + */ + function countHolders(array, placeholder) { + var length = array.length, + result = 0; + + while (length--) { + if (array[length] === placeholder) { + ++result; + } + } + return result; + } + + /** + * Used by `_.deburr` to convert Latin-1 Supplement and Latin Extended-A + * letters to basic Latin letters. + * + * @private + * @param {string} letter The matched letter to deburr. + * @returns {string} Returns the deburred letter. + */ + var deburrLetter = basePropertyOf(deburredLetters); + + /** + * Used by `_.escape` to convert characters to HTML entities. + * + * @private + * @param {string} chr The matched character to escape. + * @returns {string} Returns the escaped character. + */ + var escapeHtmlChar = basePropertyOf(htmlEscapes); + + /** + * Used by `_.template` to escape characters for inclusion in compiled string literals. + * + * @private + * @param {string} chr The matched character to escape. + * @returns {string} Returns the escaped character. + */ + function escapeStringChar(chr) { + return '\\' + stringEscapes[chr]; + } + + /** + * Gets the value at `key` of `object`. + * + * @private + * @param {Object} [object] The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + function getValue(object, key) { + return object == null ? undefined$1 : object[key]; + } + + /** + * Checks if `string` contains Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a symbol is found, else `false`. + */ + function hasUnicode(string) { + return reHasUnicode.test(string); + } + + /** + * Checks if `string` contains a word composed of Unicode symbols. + * + * @private + * @param {string} string The string to inspect. + * @returns {boolean} Returns `true` if a word is found, else `false`. + */ + function hasUnicodeWord(string) { + return reHasUnicodeWord.test(string); + } + + /** + * Converts `iterator` to an array. + * + * @private + * @param {Object} iterator The iterator to convert. + * @returns {Array} Returns the converted array. + */ + function iteratorToArray(iterator) { + var data, + result = []; + + while (!(data = iterator.next()).done) { + result.push(data.value); + } + return result; + } + + /** + * Converts `map` to its key-value pairs. + * + * @private + * @param {Object} map The map to convert. + * @returns {Array} Returns the key-value pairs. + */ + function mapToArray(map) { + var index = -1, + result = Array(map.size); + + map.forEach(function(value, key) { + result[++index] = [key, value]; + }); + return result; + } + + /** + * Creates a unary function that invokes `func` with its argument transformed. + * + * @private + * @param {Function} func The function to wrap. + * @param {Function} transform The argument transform. + * @returns {Function} Returns the new function. + */ + function overArg(func, transform) { + return function(arg) { + return func(transform(arg)); + }; + } + + /** + * Replaces all `placeholder` elements in `array` with an internal placeholder + * and returns an array of their indexes. + * + * @private + * @param {Array} array The array to modify. + * @param {*} placeholder The placeholder to replace. + * @returns {Array} Returns the new array of placeholder indexes. + */ + function replaceHolders(array, placeholder) { + var index = -1, + length = array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index]; + if (value === placeholder || value === PLACEHOLDER) { + array[index] = PLACEHOLDER; + result[resIndex++] = index; + } + } + return result; + } + + /** + * Converts `set` to an array of its values. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the values. + */ + function setToArray(set) { + var index = -1, + result = Array(set.size); + + set.forEach(function(value) { + result[++index] = value; + }); + return result; + } + + /** + * Converts `set` to its value-value pairs. + * + * @private + * @param {Object} set The set to convert. + * @returns {Array} Returns the value-value pairs. + */ + function setToPairs(set) { + var index = -1, + result = Array(set.size); + + set.forEach(function(value) { + result[++index] = [value, value]; + }); + return result; + } + + /** + * A specialized version of `_.indexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function strictIndexOf(array, value, fromIndex) { + var index = fromIndex - 1, + length = array.length; + + while (++index < length) { + if (array[index] === value) { + return index; + } + } + return -1; + } + + /** + * A specialized version of `_.lastIndexOf` which performs strict equality + * comparisons of values, i.e. `===`. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} fromIndex The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function strictLastIndexOf(array, value, fromIndex) { + var index = fromIndex + 1; + while (index--) { + if (array[index] === value) { + return index; + } + } + return index; + } + + /** + * Gets the number of symbols in `string`. + * + * @private + * @param {string} string The string to inspect. + * @returns {number} Returns the string size. + */ + function stringSize(string) { + return hasUnicode(string) + ? unicodeSize(string) + : asciiSize(string); + } + + /** + * Converts `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function stringToArray(string) { + return hasUnicode(string) + ? unicodeToArray(string) + : asciiToArray(string); + } + + /** + * Used by `_.unescape` to convert HTML entities to characters. + * + * @private + * @param {string} chr The matched character to unescape. + * @returns {string} Returns the unescaped character. + */ + var unescapeHtmlChar = basePropertyOf(htmlUnescapes); + + /** + * Gets the size of a Unicode `string`. + * + * @private + * @param {string} string The string inspect. + * @returns {number} Returns the string size. + */ + function unicodeSize(string) { + var result = reUnicode.lastIndex = 0; + while (reUnicode.test(string)) { + ++result; + } + return result; + } + + /** + * Converts a Unicode `string` to an array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the converted array. + */ + function unicodeToArray(string) { + return string.match(reUnicode) || []; + } + + /** + * Splits a Unicode `string` into an array of its words. + * + * @private + * @param {string} The string to inspect. + * @returns {Array} Returns the words of `string`. + */ + function unicodeWords(string) { + return string.match(reUnicodeWord) || []; + } + + /*--------------------------------------------------------------------------*/ + + /** + * Create a new pristine `lodash` function using the `context` object. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category Util + * @param {Object} [context=root] The context object. + * @returns {Function} Returns a new `lodash` function. + * @example + * + * _.mixin({ 'foo': _.constant('foo') }); + * + * var lodash = _.runInContext(); + * lodash.mixin({ 'bar': lodash.constant('bar') }); + * + * _.isFunction(_.foo); + * // => true + * _.isFunction(_.bar); + * // => false + * + * lodash.isFunction(lodash.foo); + * // => false + * lodash.isFunction(lodash.bar); + * // => true + * + * // Create a suped-up `defer` in Node.js. + * var defer = _.runInContext({ 'setTimeout': setImmediate }).defer; + */ + var runInContext = (function runInContext(context) { + context = context == null ? root : _.defaults(root.Object(), context, _.pick(root, contextProps)); + + /** Built-in constructor references. */ + var Array = context.Array, + Date = context.Date, + Error = context.Error, + Function = context.Function, + Math = context.Math, + Object = context.Object, + RegExp = context.RegExp, + String = context.String, + TypeError = context.TypeError; + + /** Used for built-in method references. */ + var arrayProto = Array.prototype, + funcProto = Function.prototype, + objectProto = Object.prototype; + + /** Used to detect overreaching core-js shims. */ + var coreJsData = context['__core-js_shared__']; + + /** Used to resolve the decompiled source of functions. */ + var funcToString = funcProto.toString; + + /** Used to check objects for own properties. */ + var hasOwnProperty = objectProto.hasOwnProperty; + + /** Used to generate unique IDs. */ + var idCounter = 0; + + /** Used to detect methods masquerading as native. */ + var maskSrcKey = (function() { + var uid = /[^.]+$/.exec(coreJsData && coreJsData.keys && coreJsData.keys.IE_PROTO || ''); + return uid ? ('Symbol(src)_1.' + uid) : ''; + }()); + + /** + * Used to resolve the + * [`toStringTag`](http://ecma-international.org/ecma-262/7.0/#sec-object.prototype.tostring) + * of values. + */ + var nativeObjectToString = objectProto.toString; + + /** Used to infer the `Object` constructor. */ + var objectCtorString = funcToString.call(Object); + + /** Used to restore the original `_` reference in `_.noConflict`. */ + var oldDash = root._; + + /** Used to detect if a method is native. */ + var reIsNative = RegExp('^' + + funcToString.call(hasOwnProperty).replace(reRegExpChar, '\\$&') + .replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g, '$1.*?') + '$' + ); + + /** Built-in value references. */ + var Buffer = moduleExports ? context.Buffer : undefined$1, + Symbol = context.Symbol, + Uint8Array = context.Uint8Array, + allocUnsafe = Buffer ? Buffer.allocUnsafe : undefined$1, + getPrototype = overArg(Object.getPrototypeOf, Object), + objectCreate = Object.create, + propertyIsEnumerable = objectProto.propertyIsEnumerable, + splice = arrayProto.splice, + spreadableSymbol = Symbol ? Symbol.isConcatSpreadable : undefined$1, + symIterator = Symbol ? Symbol.iterator : undefined$1, + symToStringTag = Symbol ? Symbol.toStringTag : undefined$1; + + var defineProperty = (function() { + try { + var func = getNative(Object, 'defineProperty'); + func({}, '', {}); + return func; + } catch (e) {} + }()); + + /** Mocked built-ins. */ + var ctxClearTimeout = context.clearTimeout !== root.clearTimeout && context.clearTimeout, + ctxNow = Date && Date.now !== root.Date.now && Date.now, + ctxSetTimeout = context.setTimeout !== root.setTimeout && context.setTimeout; + + /* Built-in method references for those with the same name as other `lodash` methods. */ + var nativeCeil = Math.ceil, + nativeFloor = Math.floor, + nativeGetSymbols = Object.getOwnPropertySymbols, + nativeIsBuffer = Buffer ? Buffer.isBuffer : undefined$1, + nativeIsFinite = context.isFinite, + nativeJoin = arrayProto.join, + nativeKeys = overArg(Object.keys, Object), + nativeMax = Math.max, + nativeMin = Math.min, + nativeNow = Date.now, + nativeParseInt = context.parseInt, + nativeRandom = Math.random, + nativeReverse = arrayProto.reverse; + + /* Built-in method references that are verified to be native. */ + var DataView = getNative(context, 'DataView'), + Map = getNative(context, 'Map'), + Promise = getNative(context, 'Promise'), + Set = getNative(context, 'Set'), + WeakMap = getNative(context, 'WeakMap'), + nativeCreate = getNative(Object, 'create'); + + /** Used to store function metadata. */ + var metaMap = WeakMap && new WeakMap; + + /** Used to lookup unminified function names. */ + var realNames = {}; + + /** Used to detect maps, sets, and weakmaps. */ + var dataViewCtorString = toSource(DataView), + mapCtorString = toSource(Map), + promiseCtorString = toSource(Promise), + setCtorString = toSource(Set), + weakMapCtorString = toSource(WeakMap); + + /** Used to convert symbols to primitives and strings. */ + var symbolProto = Symbol ? Symbol.prototype : undefined$1, + symbolValueOf = symbolProto ? symbolProto.valueOf : undefined$1, + symbolToString = symbolProto ? symbolProto.toString : undefined$1; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a `lodash` object which wraps `value` to enable implicit method + * chain sequences. Methods that operate on and return arrays, collections, + * and functions can be chained together. Methods that retrieve a single value + * or may return a primitive value will automatically end the chain sequence + * and return the unwrapped value. Otherwise, the value must be unwrapped + * with `_#value`. + * + * Explicit chain sequences, which must be unwrapped with `_#value`, may be + * enabled using `_.chain`. + * + * The execution of chained methods is lazy, that is, it's deferred until + * `_#value` is implicitly or explicitly called. + * + * Lazy evaluation allows several methods to support shortcut fusion. + * Shortcut fusion is an optimization to merge iteratee calls; this avoids + * the creation of intermediate arrays and can greatly reduce the number of + * iteratee executions. Sections of a chain sequence qualify for shortcut + * fusion if the section is applied to an array and iteratees accept only + * one argument. The heuristic for whether a section qualifies for shortcut + * fusion is subject to change. + * + * Chaining is supported in custom builds as long as the `_#value` method is + * directly or indirectly included in the build. + * + * In addition to lodash methods, wrappers have `Array` and `String` methods. + * + * The wrapper `Array` methods are: + * `concat`, `join`, `pop`, `push`, `shift`, `sort`, `splice`, and `unshift` + * + * The wrapper `String` methods are: + * `replace` and `split` + * + * The wrapper methods that support shortcut fusion are: + * `at`, `compact`, `drop`, `dropRight`, `dropWhile`, `filter`, `find`, + * `findLast`, `head`, `initial`, `last`, `map`, `reject`, `reverse`, `slice`, + * `tail`, `take`, `takeRight`, `takeRightWhile`, `takeWhile`, and `toArray` + * + * The chainable wrapper methods are: + * `after`, `ary`, `assign`, `assignIn`, `assignInWith`, `assignWith`, `at`, + * `before`, `bind`, `bindAll`, `bindKey`, `castArray`, `chain`, `chunk`, + * `commit`, `compact`, `concat`, `conforms`, `constant`, `countBy`, `create`, + * `curry`, `debounce`, `defaults`, `defaultsDeep`, `defer`, `delay`, + * `difference`, `differenceBy`, `differenceWith`, `drop`, `dropRight`, + * `dropRightWhile`, `dropWhile`, `extend`, `extendWith`, `fill`, `filter`, + * `flatMap`, `flatMapDeep`, `flatMapDepth`, `flatten`, `flattenDeep`, + * `flattenDepth`, `flip`, `flow`, `flowRight`, `fromPairs`, `functions`, + * `functionsIn`, `groupBy`, `initial`, `intersection`, `intersectionBy`, + * `intersectionWith`, `invert`, `invertBy`, `invokeMap`, `iteratee`, `keyBy`, + * `keys`, `keysIn`, `map`, `mapKeys`, `mapValues`, `matches`, `matchesProperty`, + * `memoize`, `merge`, `mergeWith`, `method`, `methodOf`, `mixin`, `negate`, + * `nthArg`, `omit`, `omitBy`, `once`, `orderBy`, `over`, `overArgs`, + * `overEvery`, `overSome`, `partial`, `partialRight`, `partition`, `pick`, + * `pickBy`, `plant`, `property`, `propertyOf`, `pull`, `pullAll`, `pullAllBy`, + * `pullAllWith`, `pullAt`, `push`, `range`, `rangeRight`, `rearg`, `reject`, + * `remove`, `rest`, `reverse`, `sampleSize`, `set`, `setWith`, `shuffle`, + * `slice`, `sort`, `sortBy`, `splice`, `spread`, `tail`, `take`, `takeRight`, + * `takeRightWhile`, `takeWhile`, `tap`, `throttle`, `thru`, `toArray`, + * `toPairs`, `toPairsIn`, `toPath`, `toPlainObject`, `transform`, `unary`, + * `union`, `unionBy`, `unionWith`, `uniq`, `uniqBy`, `uniqWith`, `unset`, + * `unshift`, `unzip`, `unzipWith`, `update`, `updateWith`, `values`, + * `valuesIn`, `without`, `wrap`, `xor`, `xorBy`, `xorWith`, `zip`, + * `zipObject`, `zipObjectDeep`, and `zipWith` + * + * The wrapper methods that are **not** chainable by default are: + * `add`, `attempt`, `camelCase`, `capitalize`, `ceil`, `clamp`, `clone`, + * `cloneDeep`, `cloneDeepWith`, `cloneWith`, `conformsTo`, `deburr`, + * `defaultTo`, `divide`, `each`, `eachRight`, `endsWith`, `eq`, `escape`, + * `escapeRegExp`, `every`, `find`, `findIndex`, `findKey`, `findLast`, + * `findLastIndex`, `findLastKey`, `first`, `floor`, `forEach`, `forEachRight`, + * `forIn`, `forInRight`, `forOwn`, `forOwnRight`, `get`, `gt`, `gte`, `has`, + * `hasIn`, `head`, `identity`, `includes`, `indexOf`, `inRange`, `invoke`, + * `isArguments`, `isArray`, `isArrayBuffer`, `isArrayLike`, `isArrayLikeObject`, + * `isBoolean`, `isBuffer`, `isDate`, `isElement`, `isEmpty`, `isEqual`, + * `isEqualWith`, `isError`, `isFinite`, `isFunction`, `isInteger`, `isLength`, + * `isMap`, `isMatch`, `isMatchWith`, `isNaN`, `isNative`, `isNil`, `isNull`, + * `isNumber`, `isObject`, `isObjectLike`, `isPlainObject`, `isRegExp`, + * `isSafeInteger`, `isSet`, `isString`, `isUndefined`, `isTypedArray`, + * `isWeakMap`, `isWeakSet`, `join`, `kebabCase`, `last`, `lastIndexOf`, + * `lowerCase`, `lowerFirst`, `lt`, `lte`, `max`, `maxBy`, `mean`, `meanBy`, + * `min`, `minBy`, `multiply`, `noConflict`, `noop`, `now`, `nth`, `pad`, + * `padEnd`, `padStart`, `parseInt`, `pop`, `random`, `reduce`, `reduceRight`, + * `repeat`, `result`, `round`, `runInContext`, `sample`, `shift`, `size`, + * `snakeCase`, `some`, `sortedIndex`, `sortedIndexBy`, `sortedLastIndex`, + * `sortedLastIndexBy`, `startCase`, `startsWith`, `stubArray`, `stubFalse`, + * `stubObject`, `stubString`, `stubTrue`, `subtract`, `sum`, `sumBy`, + * `template`, `times`, `toFinite`, `toInteger`, `toJSON`, `toLength`, + * `toLower`, `toNumber`, `toSafeInteger`, `toString`, `toUpper`, `trim`, + * `trimEnd`, `trimStart`, `truncate`, `unescape`, `uniqueId`, `upperCase`, + * `upperFirst`, `value`, and `words` + * + * @name _ + * @constructor + * @category Seq + * @param {*} value The value to wrap in a `lodash` instance. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * function square(n) { + * return n * n; + * } + * + * var wrapped = _([1, 2, 3]); + * + * // Returns an unwrapped value. + * wrapped.reduce(_.add); + * // => 6 + * + * // Returns a wrapped value. + * var squares = wrapped.map(square); + * + * _.isArray(squares); + * // => false + * + * _.isArray(squares.value()); + * // => true + */ + function lodash(value) { + if (isObjectLike(value) && !isArray(value) && !(value instanceof LazyWrapper)) { + if (value instanceof LodashWrapper) { + return value; + } + if (hasOwnProperty.call(value, '__wrapped__')) { + return wrapperClone(value); + } + } + return new LodashWrapper(value); + } + + /** + * The base implementation of `_.create` without support for assigning + * properties to the created object. + * + * @private + * @param {Object} proto The object to inherit from. + * @returns {Object} Returns the new object. + */ + var baseCreate = (function() { + function object() {} + return function(proto) { + if (!isObject(proto)) { + return {}; + } + if (objectCreate) { + return objectCreate(proto); + } + object.prototype = proto; + var result = new object; + object.prototype = undefined$1; + return result; + }; + }()); + + /** + * The function whose prototype chain sequence wrappers inherit from. + * + * @private + */ + function baseLodash() { + // No operation performed. + } + + /** + * The base constructor for creating `lodash` wrapper objects. + * + * @private + * @param {*} value The value to wrap. + * @param {boolean} [chainAll] Enable explicit method chain sequences. + */ + function LodashWrapper(value, chainAll) { + this.__wrapped__ = value; + this.__actions__ = []; + this.__chain__ = !!chainAll; + this.__index__ = 0; + this.__values__ = undefined$1; + } + + /** + * By default, the template delimiters used by lodash are like those in + * embedded Ruby (ERB) as well as ES2015 template strings. Change the + * following template settings to use alternative delimiters. + * + * @static + * @memberOf _ + * @type {Object} + */ + lodash.templateSettings = { + + /** + * Used to detect `data` property values to be HTML-escaped. + * + * @memberOf _.templateSettings + * @type {RegExp} + */ + 'escape': reEscape, + + /** + * Used to detect code to be evaluated. + * + * @memberOf _.templateSettings + * @type {RegExp} + */ + 'evaluate': reEvaluate, + + /** + * Used to detect `data` property values to inject. + * + * @memberOf _.templateSettings + * @type {RegExp} + */ + 'interpolate': reInterpolate, + + /** + * Used to reference the data object in the template text. + * + * @memberOf _.templateSettings + * @type {string} + */ + 'variable': '', + + /** + * Used to import variables into the compiled template. + * + * @memberOf _.templateSettings + * @type {Object} + */ + 'imports': { + + /** + * A reference to the `lodash` function. + * + * @memberOf _.templateSettings.imports + * @type {Function} + */ + '_': lodash + } + }; + + // Ensure wrappers are instances of `baseLodash`. + lodash.prototype = baseLodash.prototype; + lodash.prototype.constructor = lodash; + + LodashWrapper.prototype = baseCreate(baseLodash.prototype); + LodashWrapper.prototype.constructor = LodashWrapper; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a lazy wrapper object which wraps `value` to enable lazy evaluation. + * + * @private + * @constructor + * @param {*} value The value to wrap. + */ + function LazyWrapper(value) { + this.__wrapped__ = value; + this.__actions__ = []; + this.__dir__ = 1; + this.__filtered__ = false; + this.__iteratees__ = []; + this.__takeCount__ = MAX_ARRAY_LENGTH; + this.__views__ = []; + } + + /** + * Creates a clone of the lazy wrapper object. + * + * @private + * @name clone + * @memberOf LazyWrapper + * @returns {Object} Returns the cloned `LazyWrapper` object. + */ + function lazyClone() { + var result = new LazyWrapper(this.__wrapped__); + result.__actions__ = copyArray(this.__actions__); + result.__dir__ = this.__dir__; + result.__filtered__ = this.__filtered__; + result.__iteratees__ = copyArray(this.__iteratees__); + result.__takeCount__ = this.__takeCount__; + result.__views__ = copyArray(this.__views__); + return result; + } + + /** + * Reverses the direction of lazy iteration. + * + * @private + * @name reverse + * @memberOf LazyWrapper + * @returns {Object} Returns the new reversed `LazyWrapper` object. + */ + function lazyReverse() { + if (this.__filtered__) { + var result = new LazyWrapper(this); + result.__dir__ = -1; + result.__filtered__ = true; + } else { + result = this.clone(); + result.__dir__ *= -1; + } + return result; + } + + /** + * Extracts the unwrapped value from its lazy wrapper. + * + * @private + * @name value + * @memberOf LazyWrapper + * @returns {*} Returns the unwrapped value. + */ + function lazyValue() { + var array = this.__wrapped__.value(), + dir = this.__dir__, + isArr = isArray(array), + isRight = dir < 0, + arrLength = isArr ? array.length : 0, + view = getView(0, arrLength, this.__views__), + start = view.start, + end = view.end, + length = end - start, + index = isRight ? end : (start - 1), + iteratees = this.__iteratees__, + iterLength = iteratees.length, + resIndex = 0, + takeCount = nativeMin(length, this.__takeCount__); + + if (!isArr || (!isRight && arrLength == length && takeCount == length)) { + return baseWrapperValue(array, this.__actions__); + } + var result = []; + + outer: + while (length-- && resIndex < takeCount) { + index += dir; + + var iterIndex = -1, + value = array[index]; + + while (++iterIndex < iterLength) { + var data = iteratees[iterIndex], + iteratee = data.iteratee, + type = data.type, + computed = iteratee(value); + + if (type == LAZY_MAP_FLAG) { + value = computed; + } else if (!computed) { + if (type == LAZY_FILTER_FLAG) { + continue outer; + } else { + break outer; + } + } + } + result[resIndex++] = value; + } + return result; + } + + // Ensure `LazyWrapper` is an instance of `baseLodash`. + LazyWrapper.prototype = baseCreate(baseLodash.prototype); + LazyWrapper.prototype.constructor = LazyWrapper; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a hash object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function Hash(entries) { + var index = -1, + length = entries == null ? 0 : entries.length; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } + } + + /** + * Removes all key-value entries from the hash. + * + * @private + * @name clear + * @memberOf Hash + */ + function hashClear() { + this.__data__ = nativeCreate ? nativeCreate(null) : {}; + this.size = 0; + } + + /** + * Removes `key` and its value from the hash. + * + * @private + * @name delete + * @memberOf Hash + * @param {Object} hash The hash to modify. + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function hashDelete(key) { + var result = this.has(key) && delete this.__data__[key]; + this.size -= result ? 1 : 0; + return result; + } + + /** + * Gets the hash value for `key`. + * + * @private + * @name get + * @memberOf Hash + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function hashGet(key) { + var data = this.__data__; + if (nativeCreate) { + var result = data[key]; + return result === HASH_UNDEFINED ? undefined$1 : result; + } + return hasOwnProperty.call(data, key) ? data[key] : undefined$1; + } + + /** + * Checks if a hash value for `key` exists. + * + * @private + * @name has + * @memberOf Hash + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function hashHas(key) { + var data = this.__data__; + return nativeCreate ? (data[key] !== undefined$1) : hasOwnProperty.call(data, key); + } + + /** + * Sets the hash `key` to `value`. + * + * @private + * @name set + * @memberOf Hash + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the hash instance. + */ + function hashSet(key, value) { + var data = this.__data__; + this.size += this.has(key) ? 0 : 1; + data[key] = (nativeCreate && value === undefined$1) ? HASH_UNDEFINED : value; + return this; + } + + // Add methods to `Hash`. + Hash.prototype.clear = hashClear; + Hash.prototype['delete'] = hashDelete; + Hash.prototype.get = hashGet; + Hash.prototype.has = hashHas; + Hash.prototype.set = hashSet; + + /*------------------------------------------------------------------------*/ + + /** + * Creates an list cache object. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function ListCache(entries) { + var index = -1, + length = entries == null ? 0 : entries.length; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } + } + + /** + * Removes all key-value entries from the list cache. + * + * @private + * @name clear + * @memberOf ListCache + */ + function listCacheClear() { + this.__data__ = []; + this.size = 0; + } + + /** + * Removes `key` and its value from the list cache. + * + * @private + * @name delete + * @memberOf ListCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function listCacheDelete(key) { + var data = this.__data__, + index = assocIndexOf(data, key); + + if (index < 0) { + return false; + } + var lastIndex = data.length - 1; + if (index == lastIndex) { + data.pop(); + } else { + splice.call(data, index, 1); + } + --this.size; + return true; + } + + /** + * Gets the list cache value for `key`. + * + * @private + * @name get + * @memberOf ListCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function listCacheGet(key) { + var data = this.__data__, + index = assocIndexOf(data, key); + + return index < 0 ? undefined$1 : data[index][1]; + } + + /** + * Checks if a list cache value for `key` exists. + * + * @private + * @name has + * @memberOf ListCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function listCacheHas(key) { + return assocIndexOf(this.__data__, key) > -1; + } + + /** + * Sets the list cache `key` to `value`. + * + * @private + * @name set + * @memberOf ListCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the list cache instance. + */ + function listCacheSet(key, value) { + var data = this.__data__, + index = assocIndexOf(data, key); + + if (index < 0) { + ++this.size; + data.push([key, value]); + } else { + data[index][1] = value; + } + return this; + } + + // Add methods to `ListCache`. + ListCache.prototype.clear = listCacheClear; + ListCache.prototype['delete'] = listCacheDelete; + ListCache.prototype.get = listCacheGet; + ListCache.prototype.has = listCacheHas; + ListCache.prototype.set = listCacheSet; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a map cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function MapCache(entries) { + var index = -1, + length = entries == null ? 0 : entries.length; + + this.clear(); + while (++index < length) { + var entry = entries[index]; + this.set(entry[0], entry[1]); + } + } + + /** + * Removes all key-value entries from the map. + * + * @private + * @name clear + * @memberOf MapCache + */ + function mapCacheClear() { + this.size = 0; + this.__data__ = { + 'hash': new Hash, + 'map': new (Map || ListCache), + 'string': new Hash + }; + } + + /** + * Removes `key` and its value from the map. + * + * @private + * @name delete + * @memberOf MapCache + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function mapCacheDelete(key) { + var result = getMapData(this, key)['delete'](key); + this.size -= result ? 1 : 0; + return result; + } + + /** + * Gets the map value for `key`. + * + * @private + * @name get + * @memberOf MapCache + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function mapCacheGet(key) { + return getMapData(this, key).get(key); + } + + /** + * Checks if a map value for `key` exists. + * + * @private + * @name has + * @memberOf MapCache + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function mapCacheHas(key) { + return getMapData(this, key).has(key); + } + + /** + * Sets the map `key` to `value`. + * + * @private + * @name set + * @memberOf MapCache + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the map cache instance. + */ + function mapCacheSet(key, value) { + var data = getMapData(this, key), + size = data.size; + + data.set(key, value); + this.size += data.size == size ? 0 : 1; + return this; + } + + // Add methods to `MapCache`. + MapCache.prototype.clear = mapCacheClear; + MapCache.prototype['delete'] = mapCacheDelete; + MapCache.prototype.get = mapCacheGet; + MapCache.prototype.has = mapCacheHas; + MapCache.prototype.set = mapCacheSet; + + /*------------------------------------------------------------------------*/ + + /** + * + * Creates an array cache object to store unique values. + * + * @private + * @constructor + * @param {Array} [values] The values to cache. + */ + function SetCache(values) { + var index = -1, + length = values == null ? 0 : values.length; + + this.__data__ = new MapCache; + while (++index < length) { + this.add(values[index]); + } + } + + /** + * Adds `value` to the array cache. + * + * @private + * @name add + * @memberOf SetCache + * @alias push + * @param {*} value The value to cache. + * @returns {Object} Returns the cache instance. + */ + function setCacheAdd(value) { + this.__data__.set(value, HASH_UNDEFINED); + return this; + } + + /** + * Checks if `value` is in the array cache. + * + * @private + * @name has + * @memberOf SetCache + * @param {*} value The value to search for. + * @returns {number} Returns `true` if `value` is found, else `false`. + */ + function setCacheHas(value) { + return this.__data__.has(value); + } + + // Add methods to `SetCache`. + SetCache.prototype.add = SetCache.prototype.push = setCacheAdd; + SetCache.prototype.has = setCacheHas; + + /*------------------------------------------------------------------------*/ + + /** + * Creates a stack cache object to store key-value pairs. + * + * @private + * @constructor + * @param {Array} [entries] The key-value pairs to cache. + */ + function Stack(entries) { + var data = this.__data__ = new ListCache(entries); + this.size = data.size; + } + + /** + * Removes all key-value entries from the stack. + * + * @private + * @name clear + * @memberOf Stack + */ + function stackClear() { + this.__data__ = new ListCache; + this.size = 0; + } + + /** + * Removes `key` and its value from the stack. + * + * @private + * @name delete + * @memberOf Stack + * @param {string} key The key of the value to remove. + * @returns {boolean} Returns `true` if the entry was removed, else `false`. + */ + function stackDelete(key) { + var data = this.__data__, + result = data['delete'](key); + + this.size = data.size; + return result; + } + + /** + * Gets the stack value for `key`. + * + * @private + * @name get + * @memberOf Stack + * @param {string} key The key of the value to get. + * @returns {*} Returns the entry value. + */ + function stackGet(key) { + return this.__data__.get(key); + } + + /** + * Checks if a stack value for `key` exists. + * + * @private + * @name has + * @memberOf Stack + * @param {string} key The key of the entry to check. + * @returns {boolean} Returns `true` if an entry for `key` exists, else `false`. + */ + function stackHas(key) { + return this.__data__.has(key); + } + + /** + * Sets the stack `key` to `value`. + * + * @private + * @name set + * @memberOf Stack + * @param {string} key The key of the value to set. + * @param {*} value The value to set. + * @returns {Object} Returns the stack cache instance. + */ + function stackSet(key, value) { + var data = this.__data__; + if (data instanceof ListCache) { + var pairs = data.__data__; + if (!Map || (pairs.length < LARGE_ARRAY_SIZE - 1)) { + pairs.push([key, value]); + this.size = ++data.size; + return this; + } + data = this.__data__ = new MapCache(pairs); + } + data.set(key, value); + this.size = data.size; + return this; + } + + // Add methods to `Stack`. + Stack.prototype.clear = stackClear; + Stack.prototype['delete'] = stackDelete; + Stack.prototype.get = stackGet; + Stack.prototype.has = stackHas; + Stack.prototype.set = stackSet; + + /*------------------------------------------------------------------------*/ + + /** + * Creates an array of the enumerable property names of the array-like `value`. + * + * @private + * @param {*} value The value to query. + * @param {boolean} inherited Specify returning inherited property names. + * @returns {Array} Returns the array of property names. + */ + function arrayLikeKeys(value, inherited) { + var isArr = isArray(value), + isArg = !isArr && isArguments(value), + isBuff = !isArr && !isArg && isBuffer(value), + isType = !isArr && !isArg && !isBuff && isTypedArray(value), + skipIndexes = isArr || isArg || isBuff || isType, + result = skipIndexes ? baseTimes(value.length, String) : [], + length = result.length; + + for (var key in value) { + if ((inherited || hasOwnProperty.call(value, key)) && + !(skipIndexes && ( + // Safari 9 has enumerable `arguments.length` in strict mode. + key == 'length' || + // Node.js 0.10 has enumerable non-index properties on buffers. + (isBuff && (key == 'offset' || key == 'parent')) || + // PhantomJS 2 has enumerable non-index properties on typed arrays. + (isType && (key == 'buffer' || key == 'byteLength' || key == 'byteOffset')) || + // Skip index properties. + isIndex(key, length) + ))) { + result.push(key); + } + } + return result; + } + + /** + * A specialized version of `_.sample` for arrays. + * + * @private + * @param {Array} array The array to sample. + * @returns {*} Returns the random element. + */ + function arraySample(array) { + var length = array.length; + return length ? array[baseRandom(0, length - 1)] : undefined$1; + } + + /** + * A specialized version of `_.sampleSize` for arrays. + * + * @private + * @param {Array} array The array to sample. + * @param {number} n The number of elements to sample. + * @returns {Array} Returns the random elements. + */ + function arraySampleSize(array, n) { + return shuffleSelf(copyArray(array), baseClamp(n, 0, array.length)); + } + + /** + * A specialized version of `_.shuffle` for arrays. + * + * @private + * @param {Array} array The array to shuffle. + * @returns {Array} Returns the new shuffled array. + */ + function arrayShuffle(array) { + return shuffleSelf(copyArray(array)); + } + + /** + * This function is like `assignValue` except that it doesn't assign + * `undefined` values. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function assignMergeValue(object, key, value) { + if ((value !== undefined$1 && !eq(object[key], value)) || + (value === undefined$1 && !(key in object))) { + baseAssignValue(object, key, value); + } + } + + /** + * Assigns `value` to `key` of `object` if the existing value is not equivalent + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function assignValue(object, key, value) { + var objValue = object[key]; + if (!(hasOwnProperty.call(object, key) && eq(objValue, value)) || + (value === undefined$1 && !(key in object))) { + baseAssignValue(object, key, value); + } + } + + /** + * Gets the index at which the `key` is found in `array` of key-value pairs. + * + * @private + * @param {Array} array The array to inspect. + * @param {*} key The key to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + */ + function assocIndexOf(array, key) { + var length = array.length; + while (length--) { + if (eq(array[length][0], key)) { + return length; + } + } + return -1; + } + + /** + * Aggregates elements of `collection` on `accumulator` with keys transformed + * by `iteratee` and values set by `setter`. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform keys. + * @param {Object} accumulator The initial aggregated object. + * @returns {Function} Returns `accumulator`. + */ + function baseAggregator(collection, setter, iteratee, accumulator) { + baseEach(collection, function(value, key, collection) { + setter(accumulator, value, iteratee(value), collection); + }); + return accumulator; + } + + /** + * The base implementation of `_.assign` without support for multiple sources + * or `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ + function baseAssign(object, source) { + return object && copyObject(source, keys(source), object); + } + + /** + * The base implementation of `_.assignIn` without support for multiple sources + * or `customizer` functions. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @returns {Object} Returns `object`. + */ + function baseAssignIn(object, source) { + return object && copyObject(source, keysIn(source), object); + } + + /** + * The base implementation of `assignValue` and `assignMergeValue` without + * value checks. + * + * @private + * @param {Object} object The object to modify. + * @param {string} key The key of the property to assign. + * @param {*} value The value to assign. + */ + function baseAssignValue(object, key, value) { + if (key == '__proto__' && defineProperty) { + defineProperty(object, key, { + 'configurable': true, + 'enumerable': true, + 'value': value, + 'writable': true + }); + } else { + object[key] = value; + } + } + + /** + * The base implementation of `_.at` without support for individual paths. + * + * @private + * @param {Object} object The object to iterate over. + * @param {string[]} paths The property paths to pick. + * @returns {Array} Returns the picked elements. + */ + function baseAt(object, paths) { + var index = -1, + length = paths.length, + result = Array(length), + skip = object == null; + + while (++index < length) { + result[index] = skip ? undefined$1 : get(object, paths[index]); + } + return result; + } + + /** + * The base implementation of `_.clamp` which doesn't coerce arguments. + * + * @private + * @param {number} number The number to clamp. + * @param {number} [lower] The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the clamped number. + */ + function baseClamp(number, lower, upper) { + if (number === number) { + if (upper !== undefined$1) { + number = number <= upper ? number : upper; + } + if (lower !== undefined$1) { + number = number >= lower ? number : lower; + } + } + return number; + } + + /** + * The base implementation of `_.clone` and `_.cloneDeep` which tracks + * traversed objects. + * + * @private + * @param {*} value The value to clone. + * @param {boolean} bitmask The bitmask flags. + * 1 - Deep clone + * 2 - Flatten inherited properties + * 4 - Clone symbols + * @param {Function} [customizer] The function to customize cloning. + * @param {string} [key] The key of `value`. + * @param {Object} [object] The parent object of `value`. + * @param {Object} [stack] Tracks traversed objects and their clone counterparts. + * @returns {*} Returns the cloned value. + */ + function baseClone(value, bitmask, customizer, key, object, stack) { + var result, + isDeep = bitmask & CLONE_DEEP_FLAG, + isFlat = bitmask & CLONE_FLAT_FLAG, + isFull = bitmask & CLONE_SYMBOLS_FLAG; + + if (customizer) { + result = object ? customizer(value, key, object, stack) : customizer(value); + } + if (result !== undefined$1) { + return result; + } + if (!isObject(value)) { + return value; + } + var isArr = isArray(value); + if (isArr) { + result = initCloneArray(value); + if (!isDeep) { + return copyArray(value, result); + } + } else { + var tag = getTag(value), + isFunc = tag == funcTag || tag == genTag; + + if (isBuffer(value)) { + return cloneBuffer(value, isDeep); + } + if (tag == objectTag || tag == argsTag || (isFunc && !object)) { + result = (isFlat || isFunc) ? {} : initCloneObject(value); + if (!isDeep) { + return isFlat + ? copySymbolsIn(value, baseAssignIn(result, value)) + : copySymbols(value, baseAssign(result, value)); + } + } else { + if (!cloneableTags[tag]) { + return object ? value : {}; + } + result = initCloneByTag(value, tag, isDeep); + } + } + // Check for circular references and return its corresponding clone. + stack || (stack = new Stack); + var stacked = stack.get(value); + if (stacked) { + return stacked; + } + stack.set(value, result); + + if (isSet(value)) { + value.forEach(function(subValue) { + result.add(baseClone(subValue, bitmask, customizer, subValue, value, stack)); + }); + } else if (isMap(value)) { + value.forEach(function(subValue, key) { + result.set(key, baseClone(subValue, bitmask, customizer, key, value, stack)); + }); + } + + var keysFunc = isFull + ? (isFlat ? getAllKeysIn : getAllKeys) + : (isFlat ? keysIn : keys); + + var props = isArr ? undefined$1 : keysFunc(value); + arrayEach(props || value, function(subValue, key) { + if (props) { + key = subValue; + subValue = value[key]; + } + // Recursively populate clone (susceptible to call stack limits). + assignValue(result, key, baseClone(subValue, bitmask, customizer, key, value, stack)); + }); + return result; + } + + /** + * The base implementation of `_.conforms` which doesn't clone `source`. + * + * @private + * @param {Object} source The object of property predicates to conform to. + * @returns {Function} Returns the new spec function. + */ + function baseConforms(source) { + var props = keys(source); + return function(object) { + return baseConformsTo(object, source, props); + }; + } + + /** + * The base implementation of `_.conformsTo` which accepts `props` to check. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + */ + function baseConformsTo(object, source, props) { + var length = props.length; + if (object == null) { + return !length; + } + object = Object(object); + while (length--) { + var key = props[length], + predicate = source[key], + value = object[key]; + + if ((value === undefined$1 && !(key in object)) || !predicate(value)) { + return false; + } + } + return true; + } + + /** + * The base implementation of `_.delay` and `_.defer` which accepts `args` + * to provide to `func`. + * + * @private + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @param {Array} args The arguments to provide to `func`. + * @returns {number|Object} Returns the timer id or timeout object. + */ + function baseDelay(func, wait, args) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return setTimeout(function() { func.apply(undefined$1, args); }, wait); + } + + /** + * The base implementation of methods like `_.difference` without support + * for excluding multiple arrays or iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Array} values The values to exclude. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + */ + function baseDifference(array, values, iteratee, comparator) { + var index = -1, + includes = arrayIncludes, + isCommon = true, + length = array.length, + result = [], + valuesLength = values.length; + + if (!length) { + return result; + } + if (iteratee) { + values = arrayMap(values, baseUnary(iteratee)); + } + if (comparator) { + includes = arrayIncludesWith; + isCommon = false; + } + else if (values.length >= LARGE_ARRAY_SIZE) { + includes = cacheHas; + isCommon = false; + values = new SetCache(values); + } + outer: + while (++index < length) { + var value = array[index], + computed = iteratee == null ? value : iteratee(value); + + value = (comparator || value !== 0) ? value : 0; + if (isCommon && computed === computed) { + var valuesIndex = valuesLength; + while (valuesIndex--) { + if (values[valuesIndex] === computed) { + continue outer; + } + } + result.push(value); + } + else if (!includes(values, computed, comparator)) { + result.push(value); + } + } + return result; + } + + /** + * The base implementation of `_.forEach` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + */ + var baseEach = createBaseEach(baseForOwn); + + /** + * The base implementation of `_.forEachRight` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + */ + var baseEachRight = createBaseEach(baseForOwnRight, true); + + /** + * The base implementation of `_.every` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false` + */ + function baseEvery(collection, predicate) { + var result = true; + baseEach(collection, function(value, index, collection) { + result = !!predicate(value, index, collection); + return result; + }); + return result; + } + + /** + * The base implementation of methods like `_.max` and `_.min` which accepts a + * `comparator` to determine the extremum value. + * + * @private + * @param {Array} array The array to iterate over. + * @param {Function} iteratee The iteratee invoked per iteration. + * @param {Function} comparator The comparator used to compare values. + * @returns {*} Returns the extremum value. + */ + function baseExtremum(array, iteratee, comparator) { + var index = -1, + length = array.length; + + while (++index < length) { + var value = array[index], + current = iteratee(value); + + if (current != null && (computed === undefined$1 + ? (current === current && !isSymbol(current)) + : comparator(current, computed) + )) { + var computed = current, + result = value; + } + } + return result; + } + + /** + * The base implementation of `_.fill` without an iteratee call guard. + * + * @private + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + */ + function baseFill(array, value, start, end) { + var length = array.length; + + start = toInteger(start); + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = (end === undefined$1 || end > length) ? length : toInteger(end); + if (end < 0) { + end += length; + } + end = start > end ? 0 : toLength(end); + while (start < end) { + array[start++] = value; + } + return array; + } + + /** + * The base implementation of `_.filter` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + */ + function baseFilter(collection, predicate) { + var result = []; + baseEach(collection, function(value, index, collection) { + if (predicate(value, index, collection)) { + result.push(value); + } + }); + return result; + } + + /** + * The base implementation of `_.flatten` with support for restricting flattening. + * + * @private + * @param {Array} array The array to flatten. + * @param {number} depth The maximum recursion depth. + * @param {boolean} [predicate=isFlattenable] The function invoked per iteration. + * @param {boolean} [isStrict] Restrict to values that pass `predicate` checks. + * @param {Array} [result=[]] The initial result value. + * @returns {Array} Returns the new flattened array. + */ + function baseFlatten(array, depth, predicate, isStrict, result) { + var index = -1, + length = array.length; + + predicate || (predicate = isFlattenable); + result || (result = []); + + while (++index < length) { + var value = array[index]; + if (depth > 0 && predicate(value)) { + if (depth > 1) { + // Recursively flatten arrays (susceptible to call stack limits). + baseFlatten(value, depth - 1, predicate, isStrict, result); + } else { + arrayPush(result, value); + } + } else if (!isStrict) { + result[result.length] = value; + } + } + return result; + } + + /** + * The base implementation of `baseForOwn` which iterates over `object` + * properties returned by `keysFunc` and invokes `iteratee` for each property. + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ + var baseFor = createBaseFor(); + + /** + * This function is like `baseFor` except that it iterates over properties + * in the opposite order. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @param {Function} keysFunc The function to get the keys of `object`. + * @returns {Object} Returns `object`. + */ + var baseForRight = createBaseFor(true); + + /** + * The base implementation of `_.forOwn` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwn(object, iteratee) { + return object && baseFor(object, iteratee, keys); + } + + /** + * The base implementation of `_.forOwnRight` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Object} Returns `object`. + */ + function baseForOwnRight(object, iteratee) { + return object && baseForRight(object, iteratee, keys); + } + + /** + * The base implementation of `_.functions` which creates an array of + * `object` function property names filtered from `props`. + * + * @private + * @param {Object} object The object to inspect. + * @param {Array} props The property names to filter. + * @returns {Array} Returns the function names. + */ + function baseFunctions(object, props) { + return arrayFilter(props, function(key) { + return isFunction(object[key]); + }); + } + + /** + * The base implementation of `_.get` without support for default values. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @returns {*} Returns the resolved value. + */ + function baseGet(object, path) { + path = castPath(path, object); + + var index = 0, + length = path.length; + + while (object != null && index < length) { + object = object[toKey(path[index++])]; + } + return (index && index == length) ? object : undefined$1; + } + + /** + * The base implementation of `getAllKeys` and `getAllKeysIn` which uses + * `keysFunc` and `symbolsFunc` to get the enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Function} keysFunc The function to get the keys of `object`. + * @param {Function} symbolsFunc The function to get the symbols of `object`. + * @returns {Array} Returns the array of property names and symbols. + */ + function baseGetAllKeys(object, keysFunc, symbolsFunc) { + var result = keysFunc(object); + return isArray(object) ? result : arrayPush(result, symbolsFunc(object)); + } + + /** + * The base implementation of `getTag` without fallbacks for buggy environments. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + function baseGetTag(value) { + if (value == null) { + return value === undefined$1 ? undefinedTag : nullTag; + } + return (symToStringTag && symToStringTag in Object(value)) + ? getRawTag(value) + : objectToString(value); + } + + /** + * The base implementation of `_.gt` which doesn't coerce arguments. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + */ + function baseGt(value, other) { + return value > other; + } + + /** + * The base implementation of `_.has` without support for deep paths. + * + * @private + * @param {Object} [object] The object to query. + * @param {Array|string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + */ + function baseHas(object, key) { + return object != null && hasOwnProperty.call(object, key); + } + + /** + * The base implementation of `_.hasIn` without support for deep paths. + * + * @private + * @param {Object} [object] The object to query. + * @param {Array|string} key The key to check. + * @returns {boolean} Returns `true` if `key` exists, else `false`. + */ + function baseHasIn(object, key) { + return object != null && key in Object(object); + } + + /** + * The base implementation of `_.inRange` which doesn't coerce arguments. + * + * @private + * @param {number} number The number to check. + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + */ + function baseInRange(number, start, end) { + return number >= nativeMin(start, end) && number < nativeMax(start, end); + } + + /** + * The base implementation of methods like `_.intersection`, without support + * for iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of shared values. + */ + function baseIntersection(arrays, iteratee, comparator) { + var includes = comparator ? arrayIncludesWith : arrayIncludes, + length = arrays[0].length, + othLength = arrays.length, + othIndex = othLength, + caches = Array(othLength), + maxLength = Infinity, + result = []; + + while (othIndex--) { + var array = arrays[othIndex]; + if (othIndex && iteratee) { + array = arrayMap(array, baseUnary(iteratee)); + } + maxLength = nativeMin(array.length, maxLength); + caches[othIndex] = !comparator && (iteratee || (length >= 120 && array.length >= 120)) + ? new SetCache(othIndex && array) + : undefined$1; + } + array = arrays[0]; + + var index = -1, + seen = caches[0]; + + outer: + while (++index < length && result.length < maxLength) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (!(seen + ? cacheHas(seen, computed) + : includes(result, computed, comparator) + )) { + othIndex = othLength; + while (--othIndex) { + var cache = caches[othIndex]; + if (!(cache + ? cacheHas(cache, computed) + : includes(arrays[othIndex], computed, comparator)) + ) { + continue outer; + } + } + if (seen) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + + /** + * The base implementation of `_.invert` and `_.invertBy` which inverts + * `object` with values transformed by `iteratee` and set by `setter`. + * + * @private + * @param {Object} object The object to iterate over. + * @param {Function} setter The function to set `accumulator` values. + * @param {Function} iteratee The iteratee to transform values. + * @param {Object} accumulator The initial inverted object. + * @returns {Function} Returns `accumulator`. + */ + function baseInverter(object, setter, iteratee, accumulator) { + baseForOwn(object, function(value, key, object) { + setter(accumulator, iteratee(value), key, object); + }); + return accumulator; + } + + /** + * The base implementation of `_.invoke` without support for individual + * method arguments. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path of the method to invoke. + * @param {Array} args The arguments to invoke the method with. + * @returns {*} Returns the result of the invoked method. + */ + function baseInvoke(object, path, args) { + path = castPath(path, object); + object = parent(object, path); + var func = object == null ? object : object[toKey(last(path))]; + return func == null ? undefined$1 : apply(func, object, args); + } + + /** + * The base implementation of `_.isArguments`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + */ + function baseIsArguments(value) { + return isObjectLike(value) && baseGetTag(value) == argsTag; + } + + /** + * The base implementation of `_.isArrayBuffer` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + */ + function baseIsArrayBuffer(value) { + return isObjectLike(value) && baseGetTag(value) == arrayBufferTag; + } + + /** + * The base implementation of `_.isDate` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + */ + function baseIsDate(value) { + return isObjectLike(value) && baseGetTag(value) == dateTag; + } + + /** + * The base implementation of `_.isEqual` which supports partial comparisons + * and tracks traversed objects. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {boolean} bitmask The bitmask flags. + * 1 - Unordered comparison + * 2 - Partial comparison + * @param {Function} [customizer] The function to customize comparisons. + * @param {Object} [stack] Tracks traversed `value` and `other` objects. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + */ + function baseIsEqual(value, other, bitmask, customizer, stack) { + if (value === other) { + return true; + } + if (value == null || other == null || (!isObjectLike(value) && !isObjectLike(other))) { + return value !== value && other !== other; + } + return baseIsEqualDeep(value, other, bitmask, customizer, baseIsEqual, stack); + } + + /** + * A specialized version of `baseIsEqual` for arrays and objects which performs + * deep comparisons and tracks traversed objects enabling objects with circular + * references to be compared. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} [stack] Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ + function baseIsEqualDeep(object, other, bitmask, customizer, equalFunc, stack) { + var objIsArr = isArray(object), + othIsArr = isArray(other), + objTag = objIsArr ? arrayTag : getTag(object), + othTag = othIsArr ? arrayTag : getTag(other); + + objTag = objTag == argsTag ? objectTag : objTag; + othTag = othTag == argsTag ? objectTag : othTag; + + var objIsObj = objTag == objectTag, + othIsObj = othTag == objectTag, + isSameTag = objTag == othTag; + + if (isSameTag && isBuffer(object)) { + if (!isBuffer(other)) { + return false; + } + objIsArr = true; + objIsObj = false; + } + if (isSameTag && !objIsObj) { + stack || (stack = new Stack); + return (objIsArr || isTypedArray(object)) + ? equalArrays(object, other, bitmask, customizer, equalFunc, stack) + : equalByTag(object, other, objTag, bitmask, customizer, equalFunc, stack); + } + if (!(bitmask & COMPARE_PARTIAL_FLAG)) { + var objIsWrapped = objIsObj && hasOwnProperty.call(object, '__wrapped__'), + othIsWrapped = othIsObj && hasOwnProperty.call(other, '__wrapped__'); + + if (objIsWrapped || othIsWrapped) { + var objUnwrapped = objIsWrapped ? object.value() : object, + othUnwrapped = othIsWrapped ? other.value() : other; + + stack || (stack = new Stack); + return equalFunc(objUnwrapped, othUnwrapped, bitmask, customizer, stack); + } + } + if (!isSameTag) { + return false; + } + stack || (stack = new Stack); + return equalObjects(object, other, bitmask, customizer, equalFunc, stack); + } + + /** + * The base implementation of `_.isMap` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + */ + function baseIsMap(value) { + return isObjectLike(value) && getTag(value) == mapTag; + } + + /** + * The base implementation of `_.isMatch` without support for iteratee shorthands. + * + * @private + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @param {Array} matchData The property names, values, and compare flags to match. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + */ + function baseIsMatch(object, source, matchData, customizer) { + var index = matchData.length, + length = index, + noCustomizer = !customizer; + + if (object == null) { + return !length; + } + object = Object(object); + while (index--) { + var data = matchData[index]; + if ((noCustomizer && data[2]) + ? data[1] !== object[data[0]] + : !(data[0] in object) + ) { + return false; + } + } + while (++index < length) { + data = matchData[index]; + var key = data[0], + objValue = object[key], + srcValue = data[1]; + + if (noCustomizer && data[2]) { + if (objValue === undefined$1 && !(key in object)) { + return false; + } + } else { + var stack = new Stack; + if (customizer) { + var result = customizer(objValue, srcValue, key, object, source, stack); + } + if (!(result === undefined$1 + ? baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG, customizer, stack) + : result + )) { + return false; + } + } + } + return true; + } + + /** + * The base implementation of `_.isNative` without bad shim checks. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + */ + function baseIsNative(value) { + if (!isObject(value) || isMasked(value)) { + return false; + } + var pattern = isFunction(value) ? reIsNative : reIsHostCtor; + return pattern.test(toSource(value)); + } + + /** + * The base implementation of `_.isRegExp` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + */ + function baseIsRegExp(value) { + return isObjectLike(value) && baseGetTag(value) == regexpTag; + } + + /** + * The base implementation of `_.isSet` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + */ + function baseIsSet(value) { + return isObjectLike(value) && getTag(value) == setTag; + } + + /** + * The base implementation of `_.isTypedArray` without Node.js optimizations. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + */ + function baseIsTypedArray(value) { + return isObjectLike(value) && + isLength(value.length) && !!typedArrayTags[baseGetTag(value)]; + } + + /** + * The base implementation of `_.iteratee`. + * + * @private + * @param {*} [value=_.identity] The value to convert to an iteratee. + * @returns {Function} Returns the iteratee. + */ + function baseIteratee(value) { + // Don't store the `typeof` result in a variable to avoid a JIT bug in Safari 9. + // See https://bugs.webkit.org/show_bug.cgi?id=156034 for more details. + if (typeof value == 'function') { + return value; + } + if (value == null) { + return identity; + } + if (typeof value == 'object') { + return isArray(value) + ? baseMatchesProperty(value[0], value[1]) + : baseMatches(value); + } + return property(value); + } + + /** + * The base implementation of `_.keys` which doesn't treat sparse arrays as dense. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function baseKeys(object) { + if (!isPrototype(object)) { + return nativeKeys(object); + } + var result = []; + for (var key in Object(object)) { + if (hasOwnProperty.call(object, key) && key != 'constructor') { + result.push(key); + } + } + return result; + } + + /** + * The base implementation of `_.keysIn` which doesn't treat sparse arrays as dense. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function baseKeysIn(object) { + if (!isObject(object)) { + return nativeKeysIn(object); + } + var isProto = isPrototype(object), + result = []; + + for (var key in object) { + if (!(key == 'constructor' && (isProto || !hasOwnProperty.call(object, key)))) { + result.push(key); + } + } + return result; + } + + /** + * The base implementation of `_.lt` which doesn't coerce arguments. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + */ + function baseLt(value, other) { + return value < other; + } + + /** + * The base implementation of `_.map` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} iteratee The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + */ + function baseMap(collection, iteratee) { + var index = -1, + result = isArrayLike(collection) ? Array(collection.length) : []; + + baseEach(collection, function(value, key, collection) { + result[++index] = iteratee(value, key, collection); + }); + return result; + } + + /** + * The base implementation of `_.matches` which doesn't clone `source`. + * + * @private + * @param {Object} source The object of property values to match. + * @returns {Function} Returns the new spec function. + */ + function baseMatches(source) { + var matchData = getMatchData(source); + if (matchData.length == 1 && matchData[0][2]) { + return matchesStrictComparable(matchData[0][0], matchData[0][1]); + } + return function(object) { + return object === source || baseIsMatch(object, source, matchData); + }; + } + + /** + * The base implementation of `_.matchesProperty` which doesn't clone `srcValue`. + * + * @private + * @param {string} path The path of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ + function baseMatchesProperty(path, srcValue) { + if (isKey(path) && isStrictComparable(srcValue)) { + return matchesStrictComparable(toKey(path), srcValue); + } + return function(object) { + var objValue = get(object, path); + return (objValue === undefined$1 && objValue === srcValue) + ? hasIn(object, path) + : baseIsEqual(srcValue, objValue, COMPARE_PARTIAL_FLAG | COMPARE_UNORDERED_FLAG); + }; + } + + /** + * The base implementation of `_.merge` without support for multiple sources. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {number} srcIndex The index of `source`. + * @param {Function} [customizer] The function to customize merged values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ + function baseMerge(object, source, srcIndex, customizer, stack) { + if (object === source) { + return; + } + baseFor(source, function(srcValue, key) { + stack || (stack = new Stack); + if (isObject(srcValue)) { + baseMergeDeep(object, source, key, srcIndex, baseMerge, customizer, stack); + } + else { + var newValue = customizer + ? customizer(safeGet(object, key), srcValue, (key + ''), object, source, stack) + : undefined$1; + + if (newValue === undefined$1) { + newValue = srcValue; + } + assignMergeValue(object, key, newValue); + } + }, keysIn); + } + + /** + * A specialized version of `baseMerge` for arrays and objects which performs + * deep merges and tracks traversed objects enabling objects with circular + * references to be merged. + * + * @private + * @param {Object} object The destination object. + * @param {Object} source The source object. + * @param {string} key The key of the value to merge. + * @param {number} srcIndex The index of `source`. + * @param {Function} mergeFunc The function to merge values. + * @param {Function} [customizer] The function to customize assigned values. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + */ + function baseMergeDeep(object, source, key, srcIndex, mergeFunc, customizer, stack) { + var objValue = safeGet(object, key), + srcValue = safeGet(source, key), + stacked = stack.get(srcValue); + + if (stacked) { + assignMergeValue(object, key, stacked); + return; + } + var newValue = customizer + ? customizer(objValue, srcValue, (key + ''), object, source, stack) + : undefined$1; + + var isCommon = newValue === undefined$1; + + if (isCommon) { + var isArr = isArray(srcValue), + isBuff = !isArr && isBuffer(srcValue), + isTyped = !isArr && !isBuff && isTypedArray(srcValue); + + newValue = srcValue; + if (isArr || isBuff || isTyped) { + if (isArray(objValue)) { + newValue = objValue; + } + else if (isArrayLikeObject(objValue)) { + newValue = copyArray(objValue); + } + else if (isBuff) { + isCommon = false; + newValue = cloneBuffer(srcValue, true); + } + else if (isTyped) { + isCommon = false; + newValue = cloneTypedArray(srcValue, true); + } + else { + newValue = []; + } + } + else if (isPlainObject(srcValue) || isArguments(srcValue)) { + newValue = objValue; + if (isArguments(objValue)) { + newValue = toPlainObject(objValue); + } + else if (!isObject(objValue) || isFunction(objValue)) { + newValue = initCloneObject(srcValue); + } + } + else { + isCommon = false; + } + } + if (isCommon) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, newValue); + mergeFunc(newValue, srcValue, srcIndex, customizer, stack); + stack['delete'](srcValue); + } + assignMergeValue(object, key, newValue); + } + + /** + * The base implementation of `_.nth` which doesn't coerce arguments. + * + * @private + * @param {Array} array The array to query. + * @param {number} n The index of the element to return. + * @returns {*} Returns the nth element of `array`. + */ + function baseNth(array, n) { + var length = array.length; + if (!length) { + return; + } + n += n < 0 ? length : 0; + return isIndex(n, length) ? array[n] : undefined$1; + } + + /** + * The base implementation of `_.orderBy` without param guards. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function[]|Object[]|string[]} iteratees The iteratees to sort by. + * @param {string[]} orders The sort orders of `iteratees`. + * @returns {Array} Returns the new sorted array. + */ + function baseOrderBy(collection, iteratees, orders) { + if (iteratees.length) { + iteratees = arrayMap(iteratees, function(iteratee) { + if (isArray(iteratee)) { + return function(value) { + return baseGet(value, iteratee.length === 1 ? iteratee[0] : iteratee); + } + } + return iteratee; + }); + } else { + iteratees = [identity]; + } + + var index = -1; + iteratees = arrayMap(iteratees, baseUnary(getIteratee())); + + var result = baseMap(collection, function(value, key, collection) { + var criteria = arrayMap(iteratees, function(iteratee) { + return iteratee(value); + }); + return { 'criteria': criteria, 'index': ++index, 'value': value }; + }); + + return baseSortBy(result, function(object, other) { + return compareMultiple(object, other, orders); + }); + } + + /** + * The base implementation of `_.pick` without support for individual + * property identifiers. + * + * @private + * @param {Object} object The source object. + * @param {string[]} paths The property paths to pick. + * @returns {Object} Returns the new object. + */ + function basePick(object, paths) { + return basePickBy(object, paths, function(value, path) { + return hasIn(object, path); + }); + } + + /** + * The base implementation of `_.pickBy` without support for iteratee shorthands. + * + * @private + * @param {Object} object The source object. + * @param {string[]} paths The property paths to pick. + * @param {Function} predicate The function invoked per property. + * @returns {Object} Returns the new object. + */ + function basePickBy(object, paths, predicate) { + var index = -1, + length = paths.length, + result = {}; + + while (++index < length) { + var path = paths[index], + value = baseGet(object, path); + + if (predicate(value, path)) { + baseSet(result, castPath(path, object), value); + } + } + return result; + } + + /** + * A specialized version of `baseProperty` which supports deep paths. + * + * @private + * @param {Array|string} path The path of the property to get. + * @returns {Function} Returns the new accessor function. + */ + function basePropertyDeep(path) { + return function(object) { + return baseGet(object, path); + }; + } + + /** + * The base implementation of `_.pullAllBy` without support for iteratee + * shorthands. + * + * @private + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns `array`. + */ + function basePullAll(array, values, iteratee, comparator) { + var indexOf = comparator ? baseIndexOfWith : baseIndexOf, + index = -1, + length = values.length, + seen = array; + + if (array === values) { + values = copyArray(values); + } + if (iteratee) { + seen = arrayMap(array, baseUnary(iteratee)); + } + while (++index < length) { + var fromIndex = 0, + value = values[index], + computed = iteratee ? iteratee(value) : value; + + while ((fromIndex = indexOf(seen, computed, fromIndex, comparator)) > -1) { + if (seen !== array) { + splice.call(seen, fromIndex, 1); + } + splice.call(array, fromIndex, 1); + } + } + return array; + } + + /** + * The base implementation of `_.pullAt` without support for individual + * indexes or capturing the removed elements. + * + * @private + * @param {Array} array The array to modify. + * @param {number[]} indexes The indexes of elements to remove. + * @returns {Array} Returns `array`. + */ + function basePullAt(array, indexes) { + var length = array ? indexes.length : 0, + lastIndex = length - 1; + + while (length--) { + var index = indexes[length]; + if (length == lastIndex || index !== previous) { + var previous = index; + if (isIndex(index)) { + splice.call(array, index, 1); + } else { + baseUnset(array, index); + } + } + } + return array; + } + + /** + * The base implementation of `_.random` without support for returning + * floating-point numbers. + * + * @private + * @param {number} lower The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the random number. + */ + function baseRandom(lower, upper) { + return lower + nativeFloor(nativeRandom() * (upper - lower + 1)); + } + + /** + * The base implementation of `_.range` and `_.rangeRight` which doesn't + * coerce arguments. + * + * @private + * @param {number} start The start of the range. + * @param {number} end The end of the range. + * @param {number} step The value to increment or decrement by. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the range of numbers. + */ + function baseRange(start, end, step, fromRight) { + var index = -1, + length = nativeMax(nativeCeil((end - start) / (step || 1)), 0), + result = Array(length); + + while (length--) { + result[fromRight ? length : ++index] = start; + start += step; + } + return result; + } + + /** + * The base implementation of `_.repeat` which doesn't coerce arguments. + * + * @private + * @param {string} string The string to repeat. + * @param {number} n The number of times to repeat the string. + * @returns {string} Returns the repeated string. + */ + function baseRepeat(string, n) { + var result = ''; + if (!string || n < 1 || n > MAX_SAFE_INTEGER) { + return result; + } + // Leverage the exponentiation by squaring algorithm for a faster repeat. + // See https://en.wikipedia.org/wiki/Exponentiation_by_squaring for more details. + do { + if (n % 2) { + result += string; + } + n = nativeFloor(n / 2); + if (n) { + string += string; + } + } while (n); + + return result; + } + + /** + * The base implementation of `_.rest` which doesn't validate or coerce arguments. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + */ + function baseRest(func, start) { + return setToString(overRest(func, start, identity), func + ''); + } + + /** + * The base implementation of `_.sample`. + * + * @private + * @param {Array|Object} collection The collection to sample. + * @returns {*} Returns the random element. + */ + function baseSample(collection) { + return arraySample(values(collection)); + } + + /** + * The base implementation of `_.sampleSize` without param guards. + * + * @private + * @param {Array|Object} collection The collection to sample. + * @param {number} n The number of elements to sample. + * @returns {Array} Returns the random elements. + */ + function baseSampleSize(collection, n) { + var array = values(collection); + return shuffleSelf(array, baseClamp(n, 0, array.length)); + } + + /** + * The base implementation of `_.set`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @param {Function} [customizer] The function to customize path creation. + * @returns {Object} Returns `object`. + */ + function baseSet(object, path, value, customizer) { + if (!isObject(object)) { + return object; + } + path = castPath(path, object); + + var index = -1, + length = path.length, + lastIndex = length - 1, + nested = object; + + while (nested != null && ++index < length) { + var key = toKey(path[index]), + newValue = value; + + if (key === '__proto__' || key === 'constructor' || key === 'prototype') { + return object; + } + + if (index != lastIndex) { + var objValue = nested[key]; + newValue = customizer ? customizer(objValue, key, nested) : undefined$1; + if (newValue === undefined$1) { + newValue = isObject(objValue) + ? objValue + : (isIndex(path[index + 1]) ? [] : {}); + } + } + assignValue(nested, key, newValue); + nested = nested[key]; + } + return object; + } + + /** + * The base implementation of `setData` without support for hot loop shorting. + * + * @private + * @param {Function} func The function to associate metadata with. + * @param {*} data The metadata. + * @returns {Function} Returns `func`. + */ + var baseSetData = !metaMap ? identity : function(func, data) { + metaMap.set(func, data); + return func; + }; + + /** + * The base implementation of `setToString` without support for hot loop shorting. + * + * @private + * @param {Function} func The function to modify. + * @param {Function} string The `toString` result. + * @returns {Function} Returns `func`. + */ + var baseSetToString = !defineProperty ? identity : function(func, string) { + return defineProperty(func, 'toString', { + 'configurable': true, + 'enumerable': false, + 'value': constant(string), + 'writable': true + }); + }; + + /** + * The base implementation of `_.shuffle`. + * + * @private + * @param {Array|Object} collection The collection to shuffle. + * @returns {Array} Returns the new shuffled array. + */ + function baseShuffle(collection) { + return shuffleSelf(values(collection)); + } + + /** + * The base implementation of `_.slice` without an iteratee call guard. + * + * @private + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ + function baseSlice(array, start, end) { + var index = -1, + length = array.length; + + if (start < 0) { + start = -start > length ? 0 : (length + start); + } + end = end > length ? length : end; + if (end < 0) { + end += length; + } + length = start > end ? 0 : ((end - start) >>> 0); + start >>>= 0; + + var result = Array(length); + while (++index < length) { + result[index] = array[index + start]; + } + return result; + } + + /** + * The base implementation of `_.some` without support for iteratee shorthands. + * + * @private + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} predicate The function invoked per iteration. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + */ + function baseSome(collection, predicate) { + var result; + + baseEach(collection, function(value, index, collection) { + result = predicate(value, index, collection); + return !result; + }); + return !!result; + } + + /** + * The base implementation of `_.sortedIndex` and `_.sortedLastIndex` which + * performs a binary search of `array` to determine the index at which `value` + * should be inserted into `array` in order to maintain its sort order. + * + * @private + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {boolean} [retHighest] Specify returning the highest qualified index. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndex(array, value, retHighest) { + var low = 0, + high = array == null ? low : array.length; + + if (typeof value == 'number' && value === value && high <= HALF_MAX_ARRAY_LENGTH) { + while (low < high) { + var mid = (low + high) >>> 1, + computed = array[mid]; + + if (computed !== null && !isSymbol(computed) && + (retHighest ? (computed <= value) : (computed < value))) { + low = mid + 1; + } else { + high = mid; + } + } + return high; + } + return baseSortedIndexBy(array, value, identity, retHighest); + } + + /** + * The base implementation of `_.sortedIndexBy` and `_.sortedLastIndexBy` + * which invokes `iteratee` for `value` and each element of `array` to compute + * their sort ranking. The iteratee is invoked with one argument; (value). + * + * @private + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} iteratee The iteratee invoked per element. + * @param {boolean} [retHighest] Specify returning the highest qualified index. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + */ + function baseSortedIndexBy(array, value, iteratee, retHighest) { + var low = 0, + high = array == null ? 0 : array.length; + if (high === 0) { + return 0; + } + + value = iteratee(value); + var valIsNaN = value !== value, + valIsNull = value === null, + valIsSymbol = isSymbol(value), + valIsUndefined = value === undefined$1; + + while (low < high) { + var mid = nativeFloor((low + high) / 2), + computed = iteratee(array[mid]), + othIsDefined = computed !== undefined$1, + othIsNull = computed === null, + othIsReflexive = computed === computed, + othIsSymbol = isSymbol(computed); + + if (valIsNaN) { + var setLow = retHighest || othIsReflexive; + } else if (valIsUndefined) { + setLow = othIsReflexive && (retHighest || othIsDefined); + } else if (valIsNull) { + setLow = othIsReflexive && othIsDefined && (retHighest || !othIsNull); + } else if (valIsSymbol) { + setLow = othIsReflexive && othIsDefined && !othIsNull && (retHighest || !othIsSymbol); + } else if (othIsNull || othIsSymbol) { + setLow = false; + } else { + setLow = retHighest ? (computed <= value) : (computed < value); + } + if (setLow) { + low = mid + 1; + } else { + high = mid; + } + } + return nativeMin(high, MAX_ARRAY_INDEX); + } + + /** + * The base implementation of `_.sortedUniq` and `_.sortedUniqBy` without + * support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + */ + function baseSortedUniq(array, iteratee) { + var index = -1, + length = array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + if (!index || !eq(computed, seen)) { + var seen = computed; + result[resIndex++] = value === 0 ? 0 : value; + } + } + return result; + } + + /** + * The base implementation of `_.toNumber` which doesn't ensure correct + * conversions of binary, hexadecimal, or octal string values. + * + * @private + * @param {*} value The value to process. + * @returns {number} Returns the number. + */ + function baseToNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + return +value; + } + + /** + * The base implementation of `_.toString` which doesn't convert nullish + * values to empty strings. + * + * @private + * @param {*} value The value to process. + * @returns {string} Returns the string. + */ + function baseToString(value) { + // Exit early for strings to avoid a performance hit in some environments. + if (typeof value == 'string') { + return value; + } + if (isArray(value)) { + // Recursively convert values (susceptible to call stack limits). + return arrayMap(value, baseToString) + ''; + } + if (isSymbol(value)) { + return symbolToString ? symbolToString.call(value) : ''; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + } + + /** + * The base implementation of `_.uniqBy` without support for iteratee shorthands. + * + * @private + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new duplicate free array. + */ + function baseUniq(array, iteratee, comparator) { + var index = -1, + includes = arrayIncludes, + length = array.length, + isCommon = true, + result = [], + seen = result; + + if (comparator) { + isCommon = false; + includes = arrayIncludesWith; + } + else if (length >= LARGE_ARRAY_SIZE) { + var set = iteratee ? null : createSet(array); + if (set) { + return setToArray(set); + } + isCommon = false; + includes = cacheHas; + seen = new SetCache; + } + else { + seen = iteratee ? [] : result; + } + outer: + while (++index < length) { + var value = array[index], + computed = iteratee ? iteratee(value) : value; + + value = (comparator || value !== 0) ? value : 0; + if (isCommon && computed === computed) { + var seenIndex = seen.length; + while (seenIndex--) { + if (seen[seenIndex] === computed) { + continue outer; + } + } + if (iteratee) { + seen.push(computed); + } + result.push(value); + } + else if (!includes(seen, computed, comparator)) { + if (seen !== result) { + seen.push(computed); + } + result.push(value); + } + } + return result; + } + + /** + * The base implementation of `_.unset`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The property path to unset. + * @returns {boolean} Returns `true` if the property is deleted, else `false`. + */ + function baseUnset(object, path) { + path = castPath(path, object); + object = parent(object, path); + return object == null || delete object[toKey(last(path))]; + } + + /** + * The base implementation of `_.update`. + * + * @private + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to update. + * @param {Function} updater The function to produce the updated value. + * @param {Function} [customizer] The function to customize path creation. + * @returns {Object} Returns `object`. + */ + function baseUpdate(object, path, updater, customizer) { + return baseSet(object, path, updater(baseGet(object, path)), customizer); + } + + /** + * The base implementation of methods like `_.dropWhile` and `_.takeWhile` + * without support for iteratee shorthands. + * + * @private + * @param {Array} array The array to query. + * @param {Function} predicate The function invoked per iteration. + * @param {boolean} [isDrop] Specify dropping elements instead of taking them. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Array} Returns the slice of `array`. + */ + function baseWhile(array, predicate, isDrop, fromRight) { + var length = array.length, + index = fromRight ? length : -1; + + while ((fromRight ? index-- : ++index < length) && + predicate(array[index], index, array)) {} + + return isDrop + ? baseSlice(array, (fromRight ? 0 : index), (fromRight ? index + 1 : length)) + : baseSlice(array, (fromRight ? index + 1 : 0), (fromRight ? length : index)); + } + + /** + * The base implementation of `wrapperValue` which returns the result of + * performing a sequence of actions on the unwrapped `value`, where each + * successive action is supplied the return value of the previous. + * + * @private + * @param {*} value The unwrapped value. + * @param {Array} actions Actions to perform to resolve the unwrapped value. + * @returns {*} Returns the resolved value. + */ + function baseWrapperValue(value, actions) { + var result = value; + if (result instanceof LazyWrapper) { + result = result.value(); + } + return arrayReduce(actions, function(result, action) { + return action.func.apply(action.thisArg, arrayPush([result], action.args)); + }, result); + } + + /** + * The base implementation of methods like `_.xor`, without support for + * iteratee shorthands, that accepts an array of arrays to inspect. + * + * @private + * @param {Array} arrays The arrays to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of values. + */ + function baseXor(arrays, iteratee, comparator) { + var length = arrays.length; + if (length < 2) { + return length ? baseUniq(arrays[0]) : []; + } + var index = -1, + result = Array(length); + + while (++index < length) { + var array = arrays[index], + othIndex = -1; + + while (++othIndex < length) { + if (othIndex != index) { + result[index] = baseDifference(result[index] || array, arrays[othIndex], iteratee, comparator); + } + } + } + return baseUniq(baseFlatten(result, 1), iteratee, comparator); + } + + /** + * This base implementation of `_.zipObject` which assigns values using `assignFunc`. + * + * @private + * @param {Array} props The property identifiers. + * @param {Array} values The property values. + * @param {Function} assignFunc The function to assign values. + * @returns {Object} Returns the new object. + */ + function baseZipObject(props, values, assignFunc) { + var index = -1, + length = props.length, + valsLength = values.length, + result = {}; + + while (++index < length) { + var value = index < valsLength ? values[index] : undefined$1; + assignFunc(result, props[index], value); + } + return result; + } + + /** + * Casts `value` to an empty array if it's not an array like object. + * + * @private + * @param {*} value The value to inspect. + * @returns {Array|Object} Returns the cast array-like object. + */ + function castArrayLikeObject(value) { + return isArrayLikeObject(value) ? value : []; + } + + /** + * Casts `value` to `identity` if it's not a function. + * + * @private + * @param {*} value The value to inspect. + * @returns {Function} Returns cast function. + */ + function castFunction(value) { + return typeof value == 'function' ? value : identity; + } + + /** + * Casts `value` to a path array if it's not one. + * + * @private + * @param {*} value The value to inspect. + * @param {Object} [object] The object to query keys on. + * @returns {Array} Returns the cast property path array. + */ + function castPath(value, object) { + if (isArray(value)) { + return value; + } + return isKey(value, object) ? [value] : stringToPath(toString(value)); + } + + /** + * A `baseRest` alias which can be replaced with `identity` by module + * replacement plugins. + * + * @private + * @type {Function} + * @param {Function} func The function to apply a rest parameter to. + * @returns {Function} Returns the new function. + */ + var castRest = baseRest; + + /** + * Casts `array` to a slice if it's needed. + * + * @private + * @param {Array} array The array to inspect. + * @param {number} start The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the cast slice. + */ + function castSlice(array, start, end) { + var length = array.length; + end = end === undefined$1 ? length : end; + return (!start && end >= length) ? array : baseSlice(array, start, end); + } + + /** + * A simple wrapper around the global [`clearTimeout`](https://mdn.io/clearTimeout). + * + * @private + * @param {number|Object} id The timer id or timeout object of the timer to clear. + */ + var clearTimeout = ctxClearTimeout || function(id) { + return root.clearTimeout(id); + }; + + /** + * Creates a clone of `buffer`. + * + * @private + * @param {Buffer} buffer The buffer to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Buffer} Returns the cloned buffer. + */ + function cloneBuffer(buffer, isDeep) { + if (isDeep) { + return buffer.slice(); + } + var length = buffer.length, + result = allocUnsafe ? allocUnsafe(length) : new buffer.constructor(length); + + buffer.copy(result); + return result; + } + + /** + * Creates a clone of `arrayBuffer`. + * + * @private + * @param {ArrayBuffer} arrayBuffer The array buffer to clone. + * @returns {ArrayBuffer} Returns the cloned array buffer. + */ + function cloneArrayBuffer(arrayBuffer) { + var result = new arrayBuffer.constructor(arrayBuffer.byteLength); + new Uint8Array(result).set(new Uint8Array(arrayBuffer)); + return result; + } + + /** + * Creates a clone of `dataView`. + * + * @private + * @param {Object} dataView The data view to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned data view. + */ + function cloneDataView(dataView, isDeep) { + var buffer = isDeep ? cloneArrayBuffer(dataView.buffer) : dataView.buffer; + return new dataView.constructor(buffer, dataView.byteOffset, dataView.byteLength); + } + + /** + * Creates a clone of `regexp`. + * + * @private + * @param {Object} regexp The regexp to clone. + * @returns {Object} Returns the cloned regexp. + */ + function cloneRegExp(regexp) { + var result = new regexp.constructor(regexp.source, reFlags.exec(regexp)); + result.lastIndex = regexp.lastIndex; + return result; + } + + /** + * Creates a clone of the `symbol` object. + * + * @private + * @param {Object} symbol The symbol object to clone. + * @returns {Object} Returns the cloned symbol object. + */ + function cloneSymbol(symbol) { + return symbolValueOf ? Object(symbolValueOf.call(symbol)) : {}; + } + + /** + * Creates a clone of `typedArray`. + * + * @private + * @param {Object} typedArray The typed array to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the cloned typed array. + */ + function cloneTypedArray(typedArray, isDeep) { + var buffer = isDeep ? cloneArrayBuffer(typedArray.buffer) : typedArray.buffer; + return new typedArray.constructor(buffer, typedArray.byteOffset, typedArray.length); + } + + /** + * Compares values to sort them in ascending order. + * + * @private + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {number} Returns the sort order indicator for `value`. + */ + function compareAscending(value, other) { + if (value !== other) { + var valIsDefined = value !== undefined$1, + valIsNull = value === null, + valIsReflexive = value === value, + valIsSymbol = isSymbol(value); + + var othIsDefined = other !== undefined$1, + othIsNull = other === null, + othIsReflexive = other === other, + othIsSymbol = isSymbol(other); + + if ((!othIsNull && !othIsSymbol && !valIsSymbol && value > other) || + (valIsSymbol && othIsDefined && othIsReflexive && !othIsNull && !othIsSymbol) || + (valIsNull && othIsDefined && othIsReflexive) || + (!valIsDefined && othIsReflexive) || + !valIsReflexive) { + return 1; + } + if ((!valIsNull && !valIsSymbol && !othIsSymbol && value < other) || + (othIsSymbol && valIsDefined && valIsReflexive && !valIsNull && !valIsSymbol) || + (othIsNull && valIsDefined && valIsReflexive) || + (!othIsDefined && valIsReflexive) || + !othIsReflexive) { + return -1; + } + } + return 0; + } + + /** + * Used by `_.orderBy` to compare multiple properties of a value to another + * and stable sort them. + * + * If `orders` is unspecified, all values are sorted in ascending order. Otherwise, + * specify an order of "desc" for descending or "asc" for ascending sort order + * of corresponding values. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {boolean[]|string[]} orders The order to sort by for each property. + * @returns {number} Returns the sort order indicator for `object`. + */ + function compareMultiple(object, other, orders) { + var index = -1, + objCriteria = object.criteria, + othCriteria = other.criteria, + length = objCriteria.length, + ordersLength = orders.length; + + while (++index < length) { + var result = compareAscending(objCriteria[index], othCriteria[index]); + if (result) { + if (index >= ordersLength) { + return result; + } + var order = orders[index]; + return result * (order == 'desc' ? -1 : 1); + } + } + // Fixes an `Array#sort` bug in the JS engine embedded in Adobe applications + // that causes it, under certain circumstances, to provide the same value for + // `object` and `other`. See https://github.com/jashkenas/underscore/pull/1247 + // for more details. + // + // This also ensures a stable sort in V8 and other engines. + // See https://bugs.chromium.org/p/v8/issues/detail?id=90 for more details. + return object.index - other.index; + } + + /** + * Creates an array that is the composition of partially applied arguments, + * placeholders, and provided arguments into a single array of arguments. + * + * @private + * @param {Array} args The provided arguments. + * @param {Array} partials The arguments to prepend to those provided. + * @param {Array} holders The `partials` placeholder indexes. + * @params {boolean} [isCurried] Specify composing for a curried function. + * @returns {Array} Returns the new array of composed arguments. + */ + function composeArgs(args, partials, holders, isCurried) { + var argsIndex = -1, + argsLength = args.length, + holdersLength = holders.length, + leftIndex = -1, + leftLength = partials.length, + rangeLength = nativeMax(argsLength - holdersLength, 0), + result = Array(leftLength + rangeLength), + isUncurried = !isCurried; + + while (++leftIndex < leftLength) { + result[leftIndex] = partials[leftIndex]; + } + while (++argsIndex < holdersLength) { + if (isUncurried || argsIndex < argsLength) { + result[holders[argsIndex]] = args[argsIndex]; + } + } + while (rangeLength--) { + result[leftIndex++] = args[argsIndex++]; + } + return result; + } + + /** + * This function is like `composeArgs` except that the arguments composition + * is tailored for `_.partialRight`. + * + * @private + * @param {Array} args The provided arguments. + * @param {Array} partials The arguments to append to those provided. + * @param {Array} holders The `partials` placeholder indexes. + * @params {boolean} [isCurried] Specify composing for a curried function. + * @returns {Array} Returns the new array of composed arguments. + */ + function composeArgsRight(args, partials, holders, isCurried) { + var argsIndex = -1, + argsLength = args.length, + holdersIndex = -1, + holdersLength = holders.length, + rightIndex = -1, + rightLength = partials.length, + rangeLength = nativeMax(argsLength - holdersLength, 0), + result = Array(rangeLength + rightLength), + isUncurried = !isCurried; + + while (++argsIndex < rangeLength) { + result[argsIndex] = args[argsIndex]; + } + var offset = argsIndex; + while (++rightIndex < rightLength) { + result[offset + rightIndex] = partials[rightIndex]; + } + while (++holdersIndex < holdersLength) { + if (isUncurried || argsIndex < argsLength) { + result[offset + holders[holdersIndex]] = args[argsIndex++]; + } + } + return result; + } + + /** + * Copies the values of `source` to `array`. + * + * @private + * @param {Array} source The array to copy values from. + * @param {Array} [array=[]] The array to copy values to. + * @returns {Array} Returns `array`. + */ + function copyArray(source, array) { + var index = -1, + length = source.length; + + array || (array = Array(length)); + while (++index < length) { + array[index] = source[index]; + } + return array; + } + + /** + * Copies properties of `source` to `object`. + * + * @private + * @param {Object} source The object to copy properties from. + * @param {Array} props The property identifiers to copy. + * @param {Object} [object={}] The object to copy properties to. + * @param {Function} [customizer] The function to customize copied values. + * @returns {Object} Returns `object`. + */ + function copyObject(source, props, object, customizer) { + var isNew = !object; + object || (object = {}); + + var index = -1, + length = props.length; + + while (++index < length) { + var key = props[index]; + + var newValue = customizer + ? customizer(object[key], source[key], key, object, source) + : undefined$1; + + if (newValue === undefined$1) { + newValue = source[key]; + } + if (isNew) { + baseAssignValue(object, key, newValue); + } else { + assignValue(object, key, newValue); + } + } + return object; + } + + /** + * Copies own symbols of `source` to `object`. + * + * @private + * @param {Object} source The object to copy symbols from. + * @param {Object} [object={}] The object to copy symbols to. + * @returns {Object} Returns `object`. + */ + function copySymbols(source, object) { + return copyObject(source, getSymbols(source), object); + } + + /** + * Copies own and inherited symbols of `source` to `object`. + * + * @private + * @param {Object} source The object to copy symbols from. + * @param {Object} [object={}] The object to copy symbols to. + * @returns {Object} Returns `object`. + */ + function copySymbolsIn(source, object) { + return copyObject(source, getSymbolsIn(source), object); + } + + /** + * Creates a function like `_.groupBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} [initializer] The accumulator object initializer. + * @returns {Function} Returns the new aggregator function. + */ + function createAggregator(setter, initializer) { + return function(collection, iteratee) { + var func = isArray(collection) ? arrayAggregator : baseAggregator, + accumulator = initializer ? initializer() : {}; + + return func(collection, setter, getIteratee(iteratee, 2), accumulator); + }; + } + + /** + * Creates a function like `_.assign`. + * + * @private + * @param {Function} assigner The function to assign values. + * @returns {Function} Returns the new assigner function. + */ + function createAssigner(assigner) { + return baseRest(function(object, sources) { + var index = -1, + length = sources.length, + customizer = length > 1 ? sources[length - 1] : undefined$1, + guard = length > 2 ? sources[2] : undefined$1; + + customizer = (assigner.length > 3 && typeof customizer == 'function') + ? (length--, customizer) + : undefined$1; + + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + customizer = length < 3 ? undefined$1 : customizer; + length = 1; + } + object = Object(object); + while (++index < length) { + var source = sources[index]; + if (source) { + assigner(object, source, index, customizer); + } + } + return object; + }); + } + + /** + * Creates a `baseEach` or `baseEachRight` function. + * + * @private + * @param {Function} eachFunc The function to iterate over a collection. + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + function createBaseEach(eachFunc, fromRight) { + return function(collection, iteratee) { + if (collection == null) { + return collection; + } + if (!isArrayLike(collection)) { + return eachFunc(collection, iteratee); + } + var length = collection.length, + index = fromRight ? length : -1, + iterable = Object(collection); + + while ((fromRight ? index-- : ++index < length)) { + if (iteratee(iterable[index], index, iterable) === false) { + break; + } + } + return collection; + }; + } + + /** + * Creates a base function for methods like `_.forIn` and `_.forOwn`. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new base function. + */ + function createBaseFor(fromRight) { + return function(object, iteratee, keysFunc) { + var index = -1, + iterable = Object(object), + props = keysFunc(object), + length = props.length; + + while (length--) { + var key = props[fromRight ? length : ++index]; + if (iteratee(iterable[key], key, iterable) === false) { + break; + } + } + return object; + }; + } + + /** + * Creates a function that wraps `func` to invoke it with the optional `this` + * binding of `thisArg`. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {*} [thisArg] The `this` binding of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createBind(func, bitmask, thisArg) { + var isBind = bitmask & WRAP_BIND_FLAG, + Ctor = createCtor(func); + + function wrapper() { + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + return fn.apply(isBind ? thisArg : this, arguments); + } + return wrapper; + } + + /** + * Creates a function like `_.lowerFirst`. + * + * @private + * @param {string} methodName The name of the `String` case method to use. + * @returns {Function} Returns the new case function. + */ + function createCaseFirst(methodName) { + return function(string) { + string = toString(string); + + var strSymbols = hasUnicode(string) + ? stringToArray(string) + : undefined$1; + + var chr = strSymbols + ? strSymbols[0] + : string.charAt(0); + + var trailing = strSymbols + ? castSlice(strSymbols, 1).join('') + : string.slice(1); + + return chr[methodName]() + trailing; + }; + } + + /** + * Creates a function like `_.camelCase`. + * + * @private + * @param {Function} callback The function to combine each word. + * @returns {Function} Returns the new compounder function. + */ + function createCompounder(callback) { + return function(string) { + return arrayReduce(words(deburr(string).replace(reApos, '')), callback, ''); + }; + } + + /** + * Creates a function that produces an instance of `Ctor` regardless of + * whether it was invoked as part of a `new` expression or by `call` or `apply`. + * + * @private + * @param {Function} Ctor The constructor to wrap. + * @returns {Function} Returns the new wrapped function. + */ + function createCtor(Ctor) { + return function() { + // Use a `switch` statement to work with class constructors. See + // http://ecma-international.org/ecma-262/7.0/#sec-ecmascript-function-objects-call-thisargument-argumentslist + // for more details. + var args = arguments; + switch (args.length) { + case 0: return new Ctor; + case 1: return new Ctor(args[0]); + case 2: return new Ctor(args[0], args[1]); + case 3: return new Ctor(args[0], args[1], args[2]); + case 4: return new Ctor(args[0], args[1], args[2], args[3]); + case 5: return new Ctor(args[0], args[1], args[2], args[3], args[4]); + case 6: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5]); + case 7: return new Ctor(args[0], args[1], args[2], args[3], args[4], args[5], args[6]); + } + var thisBinding = baseCreate(Ctor.prototype), + result = Ctor.apply(thisBinding, args); + + // Mimic the constructor's `return` behavior. + // See https://es5.github.io/#x13.2.2 for more details. + return isObject(result) ? result : thisBinding; + }; + } + + /** + * Creates a function that wraps `func` to enable currying. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {number} arity The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createCurry(func, bitmask, arity) { + var Ctor = createCtor(func); + + function wrapper() { + var length = arguments.length, + args = Array(length), + index = length, + placeholder = getHolder(wrapper); + + while (index--) { + args[index] = arguments[index]; + } + var holders = (length < 3 && args[0] !== placeholder && args[length - 1] !== placeholder) + ? [] + : replaceHolders(args, placeholder); + + length -= holders.length; + if (length < arity) { + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, undefined$1, + args, holders, undefined$1, undefined$1, arity - length); + } + var fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + return apply(fn, this, args); + } + return wrapper; + } + + /** + * Creates a `_.find` or `_.findLast` function. + * + * @private + * @param {Function} findIndexFunc The function to find the collection index. + * @returns {Function} Returns the new find function. + */ + function createFind(findIndexFunc) { + return function(collection, predicate, fromIndex) { + var iterable = Object(collection); + if (!isArrayLike(collection)) { + var iteratee = getIteratee(predicate, 3); + collection = keys(collection); + predicate = function(key) { return iteratee(iterable[key], key, iterable); }; + } + var index = findIndexFunc(collection, predicate, fromIndex); + return index > -1 ? iterable[iteratee ? collection[index] : index] : undefined$1; + }; + } + + /** + * Creates a `_.flow` or `_.flowRight` function. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new flow function. + */ + function createFlow(fromRight) { + return flatRest(function(funcs) { + var length = funcs.length, + index = length, + prereq = LodashWrapper.prototype.thru; + + if (fromRight) { + funcs.reverse(); + } + while (index--) { + var func = funcs[index]; + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + if (prereq && !wrapper && getFuncName(func) == 'wrapper') { + var wrapper = new LodashWrapper([], true); + } + } + index = wrapper ? index : length; + while (++index < length) { + func = funcs[index]; + + var funcName = getFuncName(func), + data = funcName == 'wrapper' ? getData(func) : undefined$1; + + if (data && isLaziable(data[0]) && + data[1] == (WRAP_ARY_FLAG | WRAP_CURRY_FLAG | WRAP_PARTIAL_FLAG | WRAP_REARG_FLAG) && + !data[4].length && data[9] == 1 + ) { + wrapper = wrapper[getFuncName(data[0])].apply(wrapper, data[3]); + } else { + wrapper = (func.length == 1 && isLaziable(func)) + ? wrapper[funcName]() + : wrapper.thru(func); + } + } + return function() { + var args = arguments, + value = args[0]; + + if (wrapper && args.length == 1 && isArray(value)) { + return wrapper.plant(value).value(); + } + var index = 0, + result = length ? funcs[index].apply(this, args) : value; + + while (++index < length) { + result = funcs[index].call(this, result); + } + return result; + }; + }); + } + + /** + * Creates a function that wraps `func` to invoke it with optional `this` + * binding of `thisArg`, partial application, and currying. + * + * @private + * @param {Function|string} func The function or method name to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. + * @param {Array} [holders] The `partials` placeholder indexes. + * @param {Array} [partialsRight] The arguments to append to those provided + * to the new function. + * @param {Array} [holdersRight] The `partialsRight` placeholder indexes. + * @param {Array} [argPos] The argument positions of the new function. + * @param {number} [ary] The arity cap of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createHybrid(func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, argPos, ary, arity) { + var isAry = bitmask & WRAP_ARY_FLAG, + isBind = bitmask & WRAP_BIND_FLAG, + isBindKey = bitmask & WRAP_BIND_KEY_FLAG, + isCurried = bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG), + isFlip = bitmask & WRAP_FLIP_FLAG, + Ctor = isBindKey ? undefined$1 : createCtor(func); + + function wrapper() { + var length = arguments.length, + args = Array(length), + index = length; + + while (index--) { + args[index] = arguments[index]; + } + if (isCurried) { + var placeholder = getHolder(wrapper), + holdersCount = countHolders(args, placeholder); + } + if (partials) { + args = composeArgs(args, partials, holders, isCurried); + } + if (partialsRight) { + args = composeArgsRight(args, partialsRight, holdersRight, isCurried); + } + length -= holdersCount; + if (isCurried && length < arity) { + var newHolders = replaceHolders(args, placeholder); + return createRecurry( + func, bitmask, createHybrid, wrapper.placeholder, thisArg, + args, newHolders, argPos, ary, arity - length + ); + } + var thisBinding = isBind ? thisArg : this, + fn = isBindKey ? thisBinding[func] : func; + + length = args.length; + if (argPos) { + args = reorder(args, argPos); + } else if (isFlip && length > 1) { + args.reverse(); + } + if (isAry && ary < length) { + args.length = ary; + } + if (this && this !== root && this instanceof wrapper) { + fn = Ctor || createCtor(fn); + } + return fn.apply(thisBinding, args); + } + return wrapper; + } + + /** + * Creates a function like `_.invertBy`. + * + * @private + * @param {Function} setter The function to set accumulator values. + * @param {Function} toIteratee The function to resolve iteratees. + * @returns {Function} Returns the new inverter function. + */ + function createInverter(setter, toIteratee) { + return function(object, iteratee) { + return baseInverter(object, setter, toIteratee(iteratee), {}); + }; + } + + /** + * Creates a function that performs a mathematical operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @param {number} [defaultValue] The value used for `undefined` arguments. + * @returns {Function} Returns the new mathematical operation function. + */ + function createMathOperation(operator, defaultValue) { + return function(value, other) { + var result; + if (value === undefined$1 && other === undefined$1) { + return defaultValue; + } + if (value !== undefined$1) { + result = value; + } + if (other !== undefined$1) { + if (result === undefined$1) { + return other; + } + if (typeof value == 'string' || typeof other == 'string') { + value = baseToString(value); + other = baseToString(other); + } else { + value = baseToNumber(value); + other = baseToNumber(other); + } + result = operator(value, other); + } + return result; + }; + } + + /** + * Creates a function like `_.over`. + * + * @private + * @param {Function} arrayFunc The function to iterate over iteratees. + * @returns {Function} Returns the new over function. + */ + function createOver(arrayFunc) { + return flatRest(function(iteratees) { + iteratees = arrayMap(iteratees, baseUnary(getIteratee())); + return baseRest(function(args) { + var thisArg = this; + return arrayFunc(iteratees, function(iteratee) { + return apply(iteratee, thisArg, args); + }); + }); + }); + } + + /** + * Creates the padding for `string` based on `length`. The `chars` string + * is truncated if the number of characters exceeds `length`. + * + * @private + * @param {number} length The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padding for `string`. + */ + function createPadding(length, chars) { + chars = chars === undefined$1 ? ' ' : baseToString(chars); + + var charsLength = chars.length; + if (charsLength < 2) { + return charsLength ? baseRepeat(chars, length) : chars; + } + var result = baseRepeat(chars, nativeCeil(length / stringSize(chars))); + return hasUnicode(chars) + ? castSlice(stringToArray(result), 0, length).join('') + : result.slice(0, length); + } + + /** + * Creates a function that wraps `func` to invoke it with the `this` binding + * of `thisArg` and `partials` prepended to the arguments it receives. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {*} thisArg The `this` binding of `func`. + * @param {Array} partials The arguments to prepend to those provided to + * the new function. + * @returns {Function} Returns the new wrapped function. + */ + function createPartial(func, bitmask, thisArg, partials) { + var isBind = bitmask & WRAP_BIND_FLAG, + Ctor = createCtor(func); + + function wrapper() { + var argsIndex = -1, + argsLength = arguments.length, + leftIndex = -1, + leftLength = partials.length, + args = Array(leftLength + argsLength), + fn = (this && this !== root && this instanceof wrapper) ? Ctor : func; + + while (++leftIndex < leftLength) { + args[leftIndex] = partials[leftIndex]; + } + while (argsLength--) { + args[leftIndex++] = arguments[++argsIndex]; + } + return apply(fn, isBind ? thisArg : this, args); + } + return wrapper; + } + + /** + * Creates a `_.range` or `_.rangeRight` function. + * + * @private + * @param {boolean} [fromRight] Specify iterating from right to left. + * @returns {Function} Returns the new range function. + */ + function createRange(fromRight) { + return function(start, end, step) { + if (step && typeof step != 'number' && isIterateeCall(start, end, step)) { + end = step = undefined$1; + } + // Ensure the sign of `-0` is preserved. + start = toFinite(start); + if (end === undefined$1) { + end = start; + start = 0; + } else { + end = toFinite(end); + } + step = step === undefined$1 ? (start < end ? 1 : -1) : toFinite(step); + return baseRange(start, end, step, fromRight); + }; + } + + /** + * Creates a function that performs a relational operation on two values. + * + * @private + * @param {Function} operator The function to perform the operation. + * @returns {Function} Returns the new relational operation function. + */ + function createRelationalOperation(operator) { + return function(value, other) { + if (!(typeof value == 'string' && typeof other == 'string')) { + value = toNumber(value); + other = toNumber(other); + } + return operator(value, other); + }; + } + + /** + * Creates a function that wraps `func` to continue currying. + * + * @private + * @param {Function} func The function to wrap. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @param {Function} wrapFunc The function to create the `func` wrapper. + * @param {*} placeholder The placeholder value. + * @param {*} [thisArg] The `this` binding of `func`. + * @param {Array} [partials] The arguments to prepend to those provided to + * the new function. + * @param {Array} [holders] The `partials` placeholder indexes. + * @param {Array} [argPos] The argument positions of the new function. + * @param {number} [ary] The arity cap of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createRecurry(func, bitmask, wrapFunc, placeholder, thisArg, partials, holders, argPos, ary, arity) { + var isCurry = bitmask & WRAP_CURRY_FLAG, + newHolders = isCurry ? holders : undefined$1, + newHoldersRight = isCurry ? undefined$1 : holders, + newPartials = isCurry ? partials : undefined$1, + newPartialsRight = isCurry ? undefined$1 : partials; + + bitmask |= (isCurry ? WRAP_PARTIAL_FLAG : WRAP_PARTIAL_RIGHT_FLAG); + bitmask &= ~(isCurry ? WRAP_PARTIAL_RIGHT_FLAG : WRAP_PARTIAL_FLAG); + + if (!(bitmask & WRAP_CURRY_BOUND_FLAG)) { + bitmask &= ~(WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG); + } + var newData = [ + func, bitmask, thisArg, newPartials, newHolders, newPartialsRight, + newHoldersRight, argPos, ary, arity + ]; + + var result = wrapFunc.apply(undefined$1, newData); + if (isLaziable(func)) { + setData(result, newData); + } + result.placeholder = placeholder; + return setWrapToString(result, func, bitmask); + } + + /** + * Creates a function like `_.round`. + * + * @private + * @param {string} methodName The name of the `Math` method to use when rounding. + * @returns {Function} Returns the new round function. + */ + function createRound(methodName) { + var func = Math[methodName]; + return function(number, precision) { + number = toNumber(number); + precision = precision == null ? 0 : nativeMin(toInteger(precision), 292); + if (precision && nativeIsFinite(number)) { + // Shift with exponential notation to avoid floating-point issues. + // See [MDN](https://mdn.io/round#Examples) for more details. + var pair = (toString(number) + 'e').split('e'), + value = func(pair[0] + 'e' + (+pair[1] + precision)); + + pair = (toString(value) + 'e').split('e'); + return +(pair[0] + 'e' + (+pair[1] - precision)); + } + return func(number); + }; + } + + /** + * Creates a set object of `values`. + * + * @private + * @param {Array} values The values to add to the set. + * @returns {Object} Returns the new set. + */ + var createSet = !(Set && (1 / setToArray(new Set([,-0]))[1]) == INFINITY) ? noop : function(values) { + return new Set(values); + }; + + /** + * Creates a `_.toPairs` or `_.toPairsIn` function. + * + * @private + * @param {Function} keysFunc The function to get the keys of a given object. + * @returns {Function} Returns the new pairs function. + */ + function createToPairs(keysFunc) { + return function(object) { + var tag = getTag(object); + if (tag == mapTag) { + return mapToArray(object); + } + if (tag == setTag) { + return setToPairs(object); + } + return baseToPairs(object, keysFunc(object)); + }; + } + + /** + * Creates a function that either curries or invokes `func` with optional + * `this` binding and partially applied arguments. + * + * @private + * @param {Function|string} func The function or method name to wrap. + * @param {number} bitmask The bitmask flags. + * 1 - `_.bind` + * 2 - `_.bindKey` + * 4 - `_.curry` or `_.curryRight` of a bound function + * 8 - `_.curry` + * 16 - `_.curryRight` + * 32 - `_.partial` + * 64 - `_.partialRight` + * 128 - `_.rearg` + * 256 - `_.ary` + * 512 - `_.flip` + * @param {*} [thisArg] The `this` binding of `func`. + * @param {Array} [partials] The arguments to be partially applied. + * @param {Array} [holders] The `partials` placeholder indexes. + * @param {Array} [argPos] The argument positions of the new function. + * @param {number} [ary] The arity cap of `func`. + * @param {number} [arity] The arity of `func`. + * @returns {Function} Returns the new wrapped function. + */ + function createWrap(func, bitmask, thisArg, partials, holders, argPos, ary, arity) { + var isBindKey = bitmask & WRAP_BIND_KEY_FLAG; + if (!isBindKey && typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + var length = partials ? partials.length : 0; + if (!length) { + bitmask &= ~(WRAP_PARTIAL_FLAG | WRAP_PARTIAL_RIGHT_FLAG); + partials = holders = undefined$1; + } + ary = ary === undefined$1 ? ary : nativeMax(toInteger(ary), 0); + arity = arity === undefined$1 ? arity : toInteger(arity); + length -= holders ? holders.length : 0; + + if (bitmask & WRAP_PARTIAL_RIGHT_FLAG) { + var partialsRight = partials, + holdersRight = holders; + + partials = holders = undefined$1; + } + var data = isBindKey ? undefined$1 : getData(func); + + var newData = [ + func, bitmask, thisArg, partials, holders, partialsRight, holdersRight, + argPos, ary, arity + ]; + + if (data) { + mergeData(newData, data); + } + func = newData[0]; + bitmask = newData[1]; + thisArg = newData[2]; + partials = newData[3]; + holders = newData[4]; + arity = newData[9] = newData[9] === undefined$1 + ? (isBindKey ? 0 : func.length) + : nativeMax(newData[9] - length, 0); + + if (!arity && bitmask & (WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG)) { + bitmask &= ~(WRAP_CURRY_FLAG | WRAP_CURRY_RIGHT_FLAG); + } + if (!bitmask || bitmask == WRAP_BIND_FLAG) { + var result = createBind(func, bitmask, thisArg); + } else if (bitmask == WRAP_CURRY_FLAG || bitmask == WRAP_CURRY_RIGHT_FLAG) { + result = createCurry(func, bitmask, arity); + } else if ((bitmask == WRAP_PARTIAL_FLAG || bitmask == (WRAP_BIND_FLAG | WRAP_PARTIAL_FLAG)) && !holders.length) { + result = createPartial(func, bitmask, thisArg, partials); + } else { + result = createHybrid.apply(undefined$1, newData); + } + var setter = data ? baseSetData : setData; + return setWrapToString(setter(result, newData), func, bitmask); + } + + /** + * Used by `_.defaults` to customize its `_.assignIn` use to assign properties + * of source objects to the destination object for all destination properties + * that resolve to `undefined`. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to assign. + * @param {Object} object The parent object of `objValue`. + * @returns {*} Returns the value to assign. + */ + function customDefaultsAssignIn(objValue, srcValue, key, object) { + if (objValue === undefined$1 || + (eq(objValue, objectProto[key]) && !hasOwnProperty.call(object, key))) { + return srcValue; + } + return objValue; + } + + /** + * Used by `_.defaultsDeep` to customize its `_.merge` use to merge source + * objects into destination objects that are passed thru. + * + * @private + * @param {*} objValue The destination value. + * @param {*} srcValue The source value. + * @param {string} key The key of the property to merge. + * @param {Object} object The parent object of `objValue`. + * @param {Object} source The parent object of `srcValue`. + * @param {Object} [stack] Tracks traversed source values and their merged + * counterparts. + * @returns {*} Returns the value to assign. + */ + function customDefaultsMerge(objValue, srcValue, key, object, source, stack) { + if (isObject(objValue) && isObject(srcValue)) { + // Recursively merge objects and arrays (susceptible to call stack limits). + stack.set(srcValue, objValue); + baseMerge(objValue, srcValue, undefined$1, customDefaultsMerge, stack); + stack['delete'](srcValue); + } + return objValue; + } + + /** + * Used by `_.omit` to customize its `_.cloneDeep` use to only clone plain + * objects. + * + * @private + * @param {*} value The value to inspect. + * @param {string} key The key of the property to inspect. + * @returns {*} Returns the uncloned value or `undefined` to defer cloning to `_.cloneDeep`. + */ + function customOmitClone(value) { + return isPlainObject(value) ? undefined$1 : value; + } + + /** + * A specialized version of `baseIsEqualDeep` for arrays with support for + * partial deep comparisons. + * + * @private + * @param {Array} array The array to compare. + * @param {Array} other The other array to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `array` and `other` objects. + * @returns {boolean} Returns `true` if the arrays are equivalent, else `false`. + */ + function equalArrays(array, other, bitmask, customizer, equalFunc, stack) { + var isPartial = bitmask & COMPARE_PARTIAL_FLAG, + arrLength = array.length, + othLength = other.length; + + if (arrLength != othLength && !(isPartial && othLength > arrLength)) { + return false; + } + // Check that cyclic values are equal. + var arrStacked = stack.get(array); + var othStacked = stack.get(other); + if (arrStacked && othStacked) { + return arrStacked == other && othStacked == array; + } + var index = -1, + result = true, + seen = (bitmask & COMPARE_UNORDERED_FLAG) ? new SetCache : undefined$1; + + stack.set(array, other); + stack.set(other, array); + + // Ignore non-index properties. + while (++index < arrLength) { + var arrValue = array[index], + othValue = other[index]; + + if (customizer) { + var compared = isPartial + ? customizer(othValue, arrValue, index, other, array, stack) + : customizer(arrValue, othValue, index, array, other, stack); + } + if (compared !== undefined$1) { + if (compared) { + continue; + } + result = false; + break; + } + // Recursively compare arrays (susceptible to call stack limits). + if (seen) { + if (!arraySome(other, function(othValue, othIndex) { + if (!cacheHas(seen, othIndex) && + (arrValue === othValue || equalFunc(arrValue, othValue, bitmask, customizer, stack))) { + return seen.push(othIndex); + } + })) { + result = false; + break; + } + } else if (!( + arrValue === othValue || + equalFunc(arrValue, othValue, bitmask, customizer, stack) + )) { + result = false; + break; + } + } + stack['delete'](array); + stack['delete'](other); + return result; + } + + /** + * A specialized version of `baseIsEqualDeep` for comparing objects of + * the same `toStringTag`. + * + * **Note:** This function only supports comparing values with tags of + * `Boolean`, `Date`, `Error`, `Number`, `RegExp`, or `String`. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {string} tag The `toStringTag` of the objects to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ + function equalByTag(object, other, tag, bitmask, customizer, equalFunc, stack) { + switch (tag) { + case dataViewTag: + if ((object.byteLength != other.byteLength) || + (object.byteOffset != other.byteOffset)) { + return false; + } + object = object.buffer; + other = other.buffer; + + case arrayBufferTag: + if ((object.byteLength != other.byteLength) || + !equalFunc(new Uint8Array(object), new Uint8Array(other))) { + return false; + } + return true; + + case boolTag: + case dateTag: + case numberTag: + // Coerce booleans to `1` or `0` and dates to milliseconds. + // Invalid dates are coerced to `NaN`. + return eq(+object, +other); + + case errorTag: + return object.name == other.name && object.message == other.message; + + case regexpTag: + case stringTag: + // Coerce regexes to strings and treat strings, primitives and objects, + // as equal. See http://www.ecma-international.org/ecma-262/7.0/#sec-regexp.prototype.tostring + // for more details. + return object == (other + ''); + + case mapTag: + var convert = mapToArray; + + case setTag: + var isPartial = bitmask & COMPARE_PARTIAL_FLAG; + convert || (convert = setToArray); + + if (object.size != other.size && !isPartial) { + return false; + } + // Assume cyclic values are equal. + var stacked = stack.get(object); + if (stacked) { + return stacked == other; + } + bitmask |= COMPARE_UNORDERED_FLAG; + + // Recursively compare objects (susceptible to call stack limits). + stack.set(object, other); + var result = equalArrays(convert(object), convert(other), bitmask, customizer, equalFunc, stack); + stack['delete'](object); + return result; + + case symbolTag: + if (symbolValueOf) { + return symbolValueOf.call(object) == symbolValueOf.call(other); + } + } + return false; + } + + /** + * A specialized version of `baseIsEqualDeep` for objects with support for + * partial deep comparisons. + * + * @private + * @param {Object} object The object to compare. + * @param {Object} other The other object to compare. + * @param {number} bitmask The bitmask flags. See `baseIsEqual` for more details. + * @param {Function} customizer The function to customize comparisons. + * @param {Function} equalFunc The function to determine equivalents of values. + * @param {Object} stack Tracks traversed `object` and `other` objects. + * @returns {boolean} Returns `true` if the objects are equivalent, else `false`. + */ + function equalObjects(object, other, bitmask, customizer, equalFunc, stack) { + var isPartial = bitmask & COMPARE_PARTIAL_FLAG, + objProps = getAllKeys(object), + objLength = objProps.length, + othProps = getAllKeys(other), + othLength = othProps.length; + + if (objLength != othLength && !isPartial) { + return false; + } + var index = objLength; + while (index--) { + var key = objProps[index]; + if (!(isPartial ? key in other : hasOwnProperty.call(other, key))) { + return false; + } + } + // Check that cyclic values are equal. + var objStacked = stack.get(object); + var othStacked = stack.get(other); + if (objStacked && othStacked) { + return objStacked == other && othStacked == object; + } + var result = true; + stack.set(object, other); + stack.set(other, object); + + var skipCtor = isPartial; + while (++index < objLength) { + key = objProps[index]; + var objValue = object[key], + othValue = other[key]; + + if (customizer) { + var compared = isPartial + ? customizer(othValue, objValue, key, other, object, stack) + : customizer(objValue, othValue, key, object, other, stack); + } + // Recursively compare objects (susceptible to call stack limits). + if (!(compared === undefined$1 + ? (objValue === othValue || equalFunc(objValue, othValue, bitmask, customizer, stack)) + : compared + )) { + result = false; + break; + } + skipCtor || (skipCtor = key == 'constructor'); + } + if (result && !skipCtor) { + var objCtor = object.constructor, + othCtor = other.constructor; + + // Non `Object` object instances with different constructors are not equal. + if (objCtor != othCtor && + ('constructor' in object && 'constructor' in other) && + !(typeof objCtor == 'function' && objCtor instanceof objCtor && + typeof othCtor == 'function' && othCtor instanceof othCtor)) { + result = false; + } + } + stack['delete'](object); + stack['delete'](other); + return result; + } + + /** + * A specialized version of `baseRest` which flattens the rest array. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @returns {Function} Returns the new function. + */ + function flatRest(func) { + return setToString(overRest(func, undefined$1, flatten), func + ''); + } + + /** + * Creates an array of own enumerable property names and symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeys(object) { + return baseGetAllKeys(object, keys, getSymbols); + } + + /** + * Creates an array of own and inherited enumerable property names and + * symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names and symbols. + */ + function getAllKeysIn(object) { + return baseGetAllKeys(object, keysIn, getSymbolsIn); + } + + /** + * Gets metadata for `func`. + * + * @private + * @param {Function} func The function to query. + * @returns {*} Returns the metadata for `func`. + */ + var getData = !metaMap ? noop : function(func) { + return metaMap.get(func); + }; + + /** + * Gets the name of `func`. + * + * @private + * @param {Function} func The function to query. + * @returns {string} Returns the function name. + */ + function getFuncName(func) { + var result = (func.name + ''), + array = realNames[result], + length = hasOwnProperty.call(realNames, result) ? array.length : 0; + + while (length--) { + var data = array[length], + otherFunc = data.func; + if (otherFunc == null || otherFunc == func) { + return data.name; + } + } + return result; + } + + /** + * Gets the argument placeholder value for `func`. + * + * @private + * @param {Function} func The function to inspect. + * @returns {*} Returns the placeholder value. + */ + function getHolder(func) { + var object = hasOwnProperty.call(lodash, 'placeholder') ? lodash : func; + return object.placeholder; + } + + /** + * Gets the appropriate "iteratee" function. If `_.iteratee` is customized, + * this function returns the custom method, otherwise it returns `baseIteratee`. + * If arguments are provided, the chosen function is invoked with them and + * its result is returned. + * + * @private + * @param {*} [value] The value to convert to an iteratee. + * @param {number} [arity] The arity of the created iteratee. + * @returns {Function} Returns the chosen function or its result. + */ + function getIteratee() { + var result = lodash.iteratee || iteratee; + result = result === iteratee ? baseIteratee : result; + return arguments.length ? result(arguments[0], arguments[1]) : result; + } + + /** + * Gets the data for `map`. + * + * @private + * @param {Object} map The map to query. + * @param {string} key The reference key. + * @returns {*} Returns the map data. + */ + function getMapData(map, key) { + var data = map.__data__; + return isKeyable(key) + ? data[typeof key == 'string' ? 'string' : 'hash'] + : data.map; + } + + /** + * Gets the property names, values, and compare flags of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the match data of `object`. + */ + function getMatchData(object) { + var result = keys(object), + length = result.length; + + while (length--) { + var key = result[length], + value = object[key]; + + result[length] = [key, value, isStrictComparable(value)]; + } + return result; + } + + /** + * Gets the native function at `key` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the method to get. + * @returns {*} Returns the function if it's native, else `undefined`. + */ + function getNative(object, key) { + var value = getValue(object, key); + return baseIsNative(value) ? value : undefined$1; + } + + /** + * A specialized version of `baseGetTag` which ignores `Symbol.toStringTag` values. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the raw `toStringTag`. + */ + function getRawTag(value) { + var isOwn = hasOwnProperty.call(value, symToStringTag), + tag = value[symToStringTag]; + + try { + value[symToStringTag] = undefined$1; + var unmasked = true; + } catch (e) {} + + var result = nativeObjectToString.call(value); + if (unmasked) { + if (isOwn) { + value[symToStringTag] = tag; + } else { + delete value[symToStringTag]; + } + } + return result; + } + + /** + * Creates an array of the own enumerable symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ + var getSymbols = !nativeGetSymbols ? stubArray : function(object) { + if (object == null) { + return []; + } + object = Object(object); + return arrayFilter(nativeGetSymbols(object), function(symbol) { + return propertyIsEnumerable.call(object, symbol); + }); + }; + + /** + * Creates an array of the own and inherited enumerable symbols of `object`. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of symbols. + */ + var getSymbolsIn = !nativeGetSymbols ? stubArray : function(object) { + var result = []; + while (object) { + arrayPush(result, getSymbols(object)); + object = getPrototype(object); + } + return result; + }; + + /** + * Gets the `toStringTag` of `value`. + * + * @private + * @param {*} value The value to query. + * @returns {string} Returns the `toStringTag`. + */ + var getTag = baseGetTag; + + // Fallback for data views, maps, sets, and weak maps in IE 11 and promises in Node.js < 6. + if ((DataView && getTag(new DataView(new ArrayBuffer(1))) != dataViewTag) || + (Map && getTag(new Map) != mapTag) || + (Promise && getTag(Promise.resolve()) != promiseTag) || + (Set && getTag(new Set) != setTag) || + (WeakMap && getTag(new WeakMap) != weakMapTag)) { + getTag = function(value) { + var result = baseGetTag(value), + Ctor = result == objectTag ? value.constructor : undefined$1, + ctorString = Ctor ? toSource(Ctor) : ''; + + if (ctorString) { + switch (ctorString) { + case dataViewCtorString: return dataViewTag; + case mapCtorString: return mapTag; + case promiseCtorString: return promiseTag; + case setCtorString: return setTag; + case weakMapCtorString: return weakMapTag; + } + } + return result; + }; + } + + /** + * Gets the view, applying any `transforms` to the `start` and `end` positions. + * + * @private + * @param {number} start The start of the view. + * @param {number} end The end of the view. + * @param {Array} transforms The transformations to apply to the view. + * @returns {Object} Returns an object containing the `start` and `end` + * positions of the view. + */ + function getView(start, end, transforms) { + var index = -1, + length = transforms.length; + + while (++index < length) { + var data = transforms[index], + size = data.size; + + switch (data.type) { + case 'drop': start += size; break; + case 'dropRight': end -= size; break; + case 'take': end = nativeMin(end, start + size); break; + case 'takeRight': start = nativeMax(start, end - size); break; + } + } + return { 'start': start, 'end': end }; + } + + /** + * Extracts wrapper details from the `source` body comment. + * + * @private + * @param {string} source The source to inspect. + * @returns {Array} Returns the wrapper details. + */ + function getWrapDetails(source) { + var match = source.match(reWrapDetails); + return match ? match[1].split(reSplitDetails) : []; + } + + /** + * Checks if `path` exists on `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @param {Function} hasFunc The function to check properties. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + */ + function hasPath(object, path, hasFunc) { + path = castPath(path, object); + + var index = -1, + length = path.length, + result = false; + + while (++index < length) { + var key = toKey(path[index]); + if (!(result = object != null && hasFunc(object, key))) { + break; + } + object = object[key]; + } + if (result || ++index != length) { + return result; + } + length = object == null ? 0 : object.length; + return !!length && isLength(length) && isIndex(key, length) && + (isArray(object) || isArguments(object)); + } + + /** + * Initializes an array clone. + * + * @private + * @param {Array} array The array to clone. + * @returns {Array} Returns the initialized clone. + */ + function initCloneArray(array) { + var length = array.length, + result = new array.constructor(length); + + // Add properties assigned by `RegExp#exec`. + if (length && typeof array[0] == 'string' && hasOwnProperty.call(array, 'index')) { + result.index = array.index; + result.input = array.input; + } + return result; + } + + /** + * Initializes an object clone. + * + * @private + * @param {Object} object The object to clone. + * @returns {Object} Returns the initialized clone. + */ + function initCloneObject(object) { + return (typeof object.constructor == 'function' && !isPrototype(object)) + ? baseCreate(getPrototype(object)) + : {}; + } + + /** + * Initializes an object clone based on its `toStringTag`. + * + * **Note:** This function only supports cloning values with tags of + * `Boolean`, `Date`, `Error`, `Map`, `Number`, `RegExp`, `Set`, or `String`. + * + * @private + * @param {Object} object The object to clone. + * @param {string} tag The `toStringTag` of the object to clone. + * @param {boolean} [isDeep] Specify a deep clone. + * @returns {Object} Returns the initialized clone. + */ + function initCloneByTag(object, tag, isDeep) { + var Ctor = object.constructor; + switch (tag) { + case arrayBufferTag: + return cloneArrayBuffer(object); + + case boolTag: + case dateTag: + return new Ctor(+object); + + case dataViewTag: + return cloneDataView(object, isDeep); + + case float32Tag: case float64Tag: + case int8Tag: case int16Tag: case int32Tag: + case uint8Tag: case uint8ClampedTag: case uint16Tag: case uint32Tag: + return cloneTypedArray(object, isDeep); + + case mapTag: + return new Ctor; + + case numberTag: + case stringTag: + return new Ctor(object); + + case regexpTag: + return cloneRegExp(object); + + case setTag: + return new Ctor; + + case symbolTag: + return cloneSymbol(object); + } + } + + /** + * Inserts wrapper `details` in a comment at the top of the `source` body. + * + * @private + * @param {string} source The source to modify. + * @returns {Array} details The details to insert. + * @returns {string} Returns the modified source. + */ + function insertWrapDetails(source, details) { + var length = details.length; + if (!length) { + return source; + } + var lastIndex = length - 1; + details[lastIndex] = (length > 1 ? '& ' : '') + details[lastIndex]; + details = details.join(length > 2 ? ', ' : ' '); + return source.replace(reWrapComment, '{\n/* [wrapped with ' + details + '] */\n'); + } + + /** + * Checks if `value` is a flattenable `arguments` object or array. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is flattenable, else `false`. + */ + function isFlattenable(value) { + return isArray(value) || isArguments(value) || + !!(spreadableSymbol && value && value[spreadableSymbol]); + } + + /** + * Checks if `value` is a valid array-like index. + * + * @private + * @param {*} value The value to check. + * @param {number} [length=MAX_SAFE_INTEGER] The upper bounds of a valid index. + * @returns {boolean} Returns `true` if `value` is a valid index, else `false`. + */ + function isIndex(value, length) { + var type = typeof value; + length = length == null ? MAX_SAFE_INTEGER : length; + + return !!length && + (type == 'number' || + (type != 'symbol' && reIsUint.test(value))) && + (value > -1 && value % 1 == 0 && value < length); + } + + /** + * Checks if the given arguments are from an iteratee call. + * + * @private + * @param {*} value The potential iteratee value argument. + * @param {*} index The potential iteratee index or key argument. + * @param {*} object The potential iteratee object argument. + * @returns {boolean} Returns `true` if the arguments are from an iteratee call, + * else `false`. + */ + function isIterateeCall(value, index, object) { + if (!isObject(object)) { + return false; + } + var type = typeof index; + if (type == 'number' + ? (isArrayLike(object) && isIndex(index, object.length)) + : (type == 'string' && index in object) + ) { + return eq(object[index], value); + } + return false; + } + + /** + * Checks if `value` is a property name and not a property path. + * + * @private + * @param {*} value The value to check. + * @param {Object} [object] The object to query keys on. + * @returns {boolean} Returns `true` if `value` is a property name, else `false`. + */ + function isKey(value, object) { + if (isArray(value)) { + return false; + } + var type = typeof value; + if (type == 'number' || type == 'symbol' || type == 'boolean' || + value == null || isSymbol(value)) { + return true; + } + return reIsPlainProp.test(value) || !reIsDeepProp.test(value) || + (object != null && value in Object(object)); + } + + /** + * Checks if `value` is suitable for use as unique object key. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is suitable, else `false`. + */ + function isKeyable(value) { + var type = typeof value; + return (type == 'string' || type == 'number' || type == 'symbol' || type == 'boolean') + ? (value !== '__proto__') + : (value === null); + } + + /** + * Checks if `func` has a lazy counterpart. + * + * @private + * @param {Function} func The function to check. + * @returns {boolean} Returns `true` if `func` has a lazy counterpart, + * else `false`. + */ + function isLaziable(func) { + var funcName = getFuncName(func), + other = lodash[funcName]; + + if (typeof other != 'function' || !(funcName in LazyWrapper.prototype)) { + return false; + } + if (func === other) { + return true; + } + var data = getData(other); + return !!data && func === data[0]; + } + + /** + * Checks if `func` has its source masked. + * + * @private + * @param {Function} func The function to check. + * @returns {boolean} Returns `true` if `func` is masked, else `false`. + */ + function isMasked(func) { + return !!maskSrcKey && (maskSrcKey in func); + } + + /** + * Checks if `func` is capable of being masked. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `func` is maskable, else `false`. + */ + var isMaskable = coreJsData ? isFunction : stubFalse; + + /** + * Checks if `value` is likely a prototype object. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a prototype, else `false`. + */ + function isPrototype(value) { + var Ctor = value && value.constructor, + proto = (typeof Ctor == 'function' && Ctor.prototype) || objectProto; + + return value === proto; + } + + /** + * Checks if `value` is suitable for strict equality comparisons, i.e. `===`. + * + * @private + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` if suitable for strict + * equality comparisons, else `false`. + */ + function isStrictComparable(value) { + return value === value && !isObject(value); + } + + /** + * A specialized version of `matchesProperty` for source values suitable + * for strict equality comparisons, i.e. `===`. + * + * @private + * @param {string} key The key of the property to get. + * @param {*} srcValue The value to match. + * @returns {Function} Returns the new spec function. + */ + function matchesStrictComparable(key, srcValue) { + return function(object) { + if (object == null) { + return false; + } + return object[key] === srcValue && + (srcValue !== undefined$1 || (key in Object(object))); + }; + } + + /** + * A specialized version of `_.memoize` which clears the memoized function's + * cache when it exceeds `MAX_MEMOIZE_SIZE`. + * + * @private + * @param {Function} func The function to have its output memoized. + * @returns {Function} Returns the new memoized function. + */ + function memoizeCapped(func) { + var result = memoize(func, function(key) { + if (cache.size === MAX_MEMOIZE_SIZE) { + cache.clear(); + } + return key; + }); + + var cache = result.cache; + return result; + } + + /** + * Merges the function metadata of `source` into `data`. + * + * Merging metadata reduces the number of wrappers used to invoke a function. + * This is possible because methods like `_.bind`, `_.curry`, and `_.partial` + * may be applied regardless of execution order. Methods like `_.ary` and + * `_.rearg` modify function arguments, making the order in which they are + * executed important, preventing the merging of metadata. However, we make + * an exception for a safe combined case where curried functions have `_.ary` + * and or `_.rearg` applied. + * + * @private + * @param {Array} data The destination metadata. + * @param {Array} source The source metadata. + * @returns {Array} Returns `data`. + */ + function mergeData(data, source) { + var bitmask = data[1], + srcBitmask = source[1], + newBitmask = bitmask | srcBitmask, + isCommon = newBitmask < (WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG | WRAP_ARY_FLAG); + + var isCombo = + ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_CURRY_FLAG)) || + ((srcBitmask == WRAP_ARY_FLAG) && (bitmask == WRAP_REARG_FLAG) && (data[7].length <= source[8])) || + ((srcBitmask == (WRAP_ARY_FLAG | WRAP_REARG_FLAG)) && (source[7].length <= source[8]) && (bitmask == WRAP_CURRY_FLAG)); + + // Exit early if metadata can't be merged. + if (!(isCommon || isCombo)) { + return data; + } + // Use source `thisArg` if available. + if (srcBitmask & WRAP_BIND_FLAG) { + data[2] = source[2]; + // Set when currying a bound function. + newBitmask |= bitmask & WRAP_BIND_FLAG ? 0 : WRAP_CURRY_BOUND_FLAG; + } + // Compose partial arguments. + var value = source[3]; + if (value) { + var partials = data[3]; + data[3] = partials ? composeArgs(partials, value, source[4]) : value; + data[4] = partials ? replaceHolders(data[3], PLACEHOLDER) : source[4]; + } + // Compose partial right arguments. + value = source[5]; + if (value) { + partials = data[5]; + data[5] = partials ? composeArgsRight(partials, value, source[6]) : value; + data[6] = partials ? replaceHolders(data[5], PLACEHOLDER) : source[6]; + } + // Use source `argPos` if available. + value = source[7]; + if (value) { + data[7] = value; + } + // Use source `ary` if it's smaller. + if (srcBitmask & WRAP_ARY_FLAG) { + data[8] = data[8] == null ? source[8] : nativeMin(data[8], source[8]); + } + // Use source `arity` if one is not provided. + if (data[9] == null) { + data[9] = source[9]; + } + // Use source `func` and merge bitmasks. + data[0] = source[0]; + data[1] = newBitmask; + + return data; + } + + /** + * This function is like + * [`Object.keys`](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * except that it includes inherited enumerable properties. + * + * @private + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + */ + function nativeKeysIn(object) { + var result = []; + if (object != null) { + for (var key in Object(object)) { + result.push(key); + } + } + return result; + } + + /** + * Converts `value` to a string using `Object.prototype.toString`. + * + * @private + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + */ + function objectToString(value) { + return nativeObjectToString.call(value); + } + + /** + * A specialized version of `baseRest` which transforms the rest array. + * + * @private + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @param {Function} transform The rest array transform. + * @returns {Function} Returns the new function. + */ + function overRest(func, start, transform) { + start = nativeMax(start === undefined$1 ? (func.length - 1) : start, 0); + return function() { + var args = arguments, + index = -1, + length = nativeMax(args.length - start, 0), + array = Array(length); + + while (++index < length) { + array[index] = args[start + index]; + } + index = -1; + var otherArgs = Array(start + 1); + while (++index < start) { + otherArgs[index] = args[index]; + } + otherArgs[start] = transform(array); + return apply(func, this, otherArgs); + }; + } + + /** + * Gets the parent value at `path` of `object`. + * + * @private + * @param {Object} object The object to query. + * @param {Array} path The path to get the parent value of. + * @returns {*} Returns the parent value. + */ + function parent(object, path) { + return path.length < 2 ? object : baseGet(object, baseSlice(path, 0, -1)); + } + + /** + * Reorder `array` according to the specified indexes where the element at + * the first index is assigned as the first element, the element at + * the second index is assigned as the second element, and so on. + * + * @private + * @param {Array} array The array to reorder. + * @param {Array} indexes The arranged array indexes. + * @returns {Array} Returns `array`. + */ + function reorder(array, indexes) { + var arrLength = array.length, + length = nativeMin(indexes.length, arrLength), + oldArray = copyArray(array); + + while (length--) { + var index = indexes[length]; + array[length] = isIndex(index, arrLength) ? oldArray[index] : undefined$1; + } + return array; + } + + /** + * Gets the value at `key`, unless `key` is "__proto__" or "constructor". + * + * @private + * @param {Object} object The object to query. + * @param {string} key The key of the property to get. + * @returns {*} Returns the property value. + */ + function safeGet(object, key) { + if (key === 'constructor' && typeof object[key] === 'function') { + return; + } + + if (key == '__proto__') { + return; + } + + return object[key]; + } + + /** + * Sets metadata for `func`. + * + * **Note:** If this function becomes hot, i.e. is invoked a lot in a short + * period of time, it will trip its breaker and transition to an identity + * function to avoid garbage collection pauses in V8. See + * [V8 issue 2070](https://bugs.chromium.org/p/v8/issues/detail?id=2070) + * for more details. + * + * @private + * @param {Function} func The function to associate metadata with. + * @param {*} data The metadata. + * @returns {Function} Returns `func`. + */ + var setData = shortOut(baseSetData); + + /** + * A simple wrapper around the global [`setTimeout`](https://mdn.io/setTimeout). + * + * @private + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @returns {number|Object} Returns the timer id or timeout object. + */ + var setTimeout = ctxSetTimeout || function(func, wait) { + return root.setTimeout(func, wait); + }; + + /** + * Sets the `toString` method of `func` to return `string`. + * + * @private + * @param {Function} func The function to modify. + * @param {Function} string The `toString` result. + * @returns {Function} Returns `func`. + */ + var setToString = shortOut(baseSetToString); + + /** + * Sets the `toString` method of `wrapper` to mimic the source of `reference` + * with wrapper details in a comment at the top of the source body. + * + * @private + * @param {Function} wrapper The function to modify. + * @param {Function} reference The reference function. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Function} Returns `wrapper`. + */ + function setWrapToString(wrapper, reference, bitmask) { + var source = (reference + ''); + return setToString(wrapper, insertWrapDetails(source, updateWrapDetails(getWrapDetails(source), bitmask))); + } + + /** + * Creates a function that'll short out and invoke `identity` instead + * of `func` when it's called `HOT_COUNT` or more times in `HOT_SPAN` + * milliseconds. + * + * @private + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new shortable function. + */ + function shortOut(func) { + var count = 0, + lastCalled = 0; + + return function() { + var stamp = nativeNow(), + remaining = HOT_SPAN - (stamp - lastCalled); + + lastCalled = stamp; + if (remaining > 0) { + if (++count >= HOT_COUNT) { + return arguments[0]; + } + } else { + count = 0; + } + return func.apply(undefined$1, arguments); + }; + } + + /** + * A specialized version of `_.shuffle` which mutates and sets the size of `array`. + * + * @private + * @param {Array} array The array to shuffle. + * @param {number} [size=array.length] The size of `array`. + * @returns {Array} Returns `array`. + */ + function shuffleSelf(array, size) { + var index = -1, + length = array.length, + lastIndex = length - 1; + + size = size === undefined$1 ? length : size; + while (++index < size) { + var rand = baseRandom(index, lastIndex), + value = array[rand]; + + array[rand] = array[index]; + array[index] = value; + } + array.length = size; + return array; + } + + /** + * Converts `string` to a property path array. + * + * @private + * @param {string} string The string to convert. + * @returns {Array} Returns the property path array. + */ + var stringToPath = memoizeCapped(function(string) { + var result = []; + if (string.charCodeAt(0) === 46 /* . */) { + result.push(''); + } + string.replace(rePropName, function(match, number, quote, subString) { + result.push(quote ? subString.replace(reEscapeChar, '$1') : (number || match)); + }); + return result; + }); + + /** + * Converts `value` to a string key if it's not a string or symbol. + * + * @private + * @param {*} value The value to inspect. + * @returns {string|symbol} Returns the key. + */ + function toKey(value) { + if (typeof value == 'string' || isSymbol(value)) { + return value; + } + var result = (value + ''); + return (result == '0' && (1 / value) == -INFINITY) ? '-0' : result; + } + + /** + * Converts `func` to its source code. + * + * @private + * @param {Function} func The function to convert. + * @returns {string} Returns the source code. + */ + function toSource(func) { + if (func != null) { + try { + return funcToString.call(func); + } catch (e) {} + try { + return (func + ''); + } catch (e) {} + } + return ''; + } + + /** + * Updates wrapper `details` based on `bitmask` flags. + * + * @private + * @returns {Array} details The details to modify. + * @param {number} bitmask The bitmask flags. See `createWrap` for more details. + * @returns {Array} Returns `details`. + */ + function updateWrapDetails(details, bitmask) { + arrayEach(wrapFlags, function(pair) { + var value = '_.' + pair[0]; + if ((bitmask & pair[1]) && !arrayIncludes(details, value)) { + details.push(value); + } + }); + return details.sort(); + } + + /** + * Creates a clone of `wrapper`. + * + * @private + * @param {Object} wrapper The wrapper to clone. + * @returns {Object} Returns the cloned wrapper. + */ + function wrapperClone(wrapper) { + if (wrapper instanceof LazyWrapper) { + return wrapper.clone(); + } + var result = new LodashWrapper(wrapper.__wrapped__, wrapper.__chain__); + result.__actions__ = copyArray(wrapper.__actions__); + result.__index__ = wrapper.__index__; + result.__values__ = wrapper.__values__; + return result; + } + + /*------------------------------------------------------------------------*/ + + /** + * Creates an array of elements split into groups the length of `size`. + * If `array` can't be split evenly, the final chunk will be the remaining + * elements. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to process. + * @param {number} [size=1] The length of each chunk + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the new array of chunks. + * @example + * + * _.chunk(['a', 'b', 'c', 'd'], 2); + * // => [['a', 'b'], ['c', 'd']] + * + * _.chunk(['a', 'b', 'c', 'd'], 3); + * // => [['a', 'b', 'c'], ['d']] + */ + function chunk(array, size, guard) { + if ((guard ? isIterateeCall(array, size, guard) : size === undefined$1)) { + size = 1; + } else { + size = nativeMax(toInteger(size), 0); + } + var length = array == null ? 0 : array.length; + if (!length || size < 1) { + return []; + } + var index = 0, + resIndex = 0, + result = Array(nativeCeil(length / size)); + + while (index < length) { + result[resIndex++] = baseSlice(array, index, (index += size)); + } + return result; + } + + /** + * Creates an array with all falsey values removed. The values `false`, `null`, + * `0`, `""`, `undefined`, and `NaN` are falsey. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to compact. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.compact([0, 1, false, 2, '', 3]); + * // => [1, 2, 3] + */ + function compact(array) { + var index = -1, + length = array == null ? 0 : array.length, + resIndex = 0, + result = []; + + while (++index < length) { + var value = array[index]; + if (value) { + result[resIndex++] = value; + } + } + return result; + } + + /** + * Creates a new array concatenating `array` with any additional arrays + * and/or values. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to concatenate. + * @param {...*} [values] The values to concatenate. + * @returns {Array} Returns the new concatenated array. + * @example + * + * var array = [1]; + * var other = _.concat(array, 2, [3], [[4]]); + * + * console.log(other); + * // => [1, 2, 3, [4]] + * + * console.log(array); + * // => [1] + */ + function concat() { + var length = arguments.length; + if (!length) { + return []; + } + var args = Array(length - 1), + array = arguments[0], + index = length; + + while (index--) { + args[index - 1] = arguments[index]; + } + return arrayPush(isArray(array) ? copyArray(array) : [array], baseFlatten(args, 1)); + } + + /** + * Creates an array of `array` values not included in the other given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * **Note:** Unlike `_.pullAll`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see _.without, _.xor + * @example + * + * _.difference([2, 1], [2, 3]); + * // => [1] + */ + var difference = baseRest(function(array, values) { + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true)) + : []; + }); + + /** + * This method is like `_.difference` except that it accepts `iteratee` which + * is invoked for each element of `array` and `values` to generate the criterion + * by which they're compared. The order and references of result values are + * determined by the first array. The iteratee is invoked with one argument: + * (value). + * + * **Note:** Unlike `_.pullAllBy`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.differenceBy([2.1, 1.2], [2.3, 3.4], Math.floor); + * // => [1.2] + * + * // The `_.property` iteratee shorthand. + * _.differenceBy([{ 'x': 2 }, { 'x': 1 }], [{ 'x': 1 }], 'x'); + * // => [{ 'x': 2 }] + */ + var differenceBy = baseRest(function(array, values) { + var iteratee = last(values); + if (isArrayLikeObject(iteratee)) { + iteratee = undefined$1; + } + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)) + : []; + }); + + /** + * This method is like `_.difference` except that it accepts `comparator` + * which is invoked to compare elements of `array` to `values`. The order and + * references of result values are determined by the first array. The comparator + * is invoked with two arguments: (arrVal, othVal). + * + * **Note:** Unlike `_.pullAllWith`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...Array} [values] The values to exclude. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * + * _.differenceWith(objects, [{ 'x': 1, 'y': 2 }], _.isEqual); + * // => [{ 'x': 2, 'y': 1 }] + */ + var differenceWith = baseRest(function(array, values) { + var comparator = last(values); + if (isArrayLikeObject(comparator)) { + comparator = undefined$1; + } + return isArrayLikeObject(array) + ? baseDifference(array, baseFlatten(values, 1, isArrayLikeObject, true), undefined$1, comparator) + : []; + }); + + /** + * Creates a slice of `array` with `n` elements dropped from the beginning. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.drop([1, 2, 3]); + * // => [2, 3] + * + * _.drop([1, 2, 3], 2); + * // => [3] + * + * _.drop([1, 2, 3], 5); + * // => [] + * + * _.drop([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function drop(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined$1) ? 1 : toInteger(n); + return baseSlice(array, n < 0 ? 0 : n, length); + } + + /** + * Creates a slice of `array` with `n` elements dropped from the end. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to drop. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.dropRight([1, 2, 3]); + * // => [1, 2] + * + * _.dropRight([1, 2, 3], 2); + * // => [1] + * + * _.dropRight([1, 2, 3], 5); + * // => [] + * + * _.dropRight([1, 2, 3], 0); + * // => [1, 2, 3] + */ + function dropRight(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined$1) ? 1 : toInteger(n); + n = length - n; + return baseSlice(array, 0, n < 0 ? 0 : n); + } + + /** + * Creates a slice of `array` excluding elements dropped from the end. + * Elements are dropped until `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ]; + * + * _.dropRightWhile(users, function(o) { return !o.active; }); + * // => objects for ['barney'] + * + * // The `_.matches` iteratee shorthand. + * _.dropRightWhile(users, { 'user': 'pebbles', 'active': false }); + * // => objects for ['barney', 'fred'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.dropRightWhile(users, ['active', false]); + * // => objects for ['barney'] + * + * // The `_.property` iteratee shorthand. + * _.dropRightWhile(users, 'active'); + * // => objects for ['barney', 'fred', 'pebbles'] + */ + function dropRightWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3), true, true) + : []; + } + + /** + * Creates a slice of `array` excluding elements dropped from the beginning. + * Elements are dropped until `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.dropWhile(users, function(o) { return !o.active; }); + * // => objects for ['pebbles'] + * + * // The `_.matches` iteratee shorthand. + * _.dropWhile(users, { 'user': 'barney', 'active': false }); + * // => objects for ['fred', 'pebbles'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.dropWhile(users, ['active', false]); + * // => objects for ['pebbles'] + * + * // The `_.property` iteratee shorthand. + * _.dropWhile(users, 'active'); + * // => objects for ['barney', 'fred', 'pebbles'] + */ + function dropWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3), true) + : []; + } + + /** + * Fills elements of `array` with `value` from `start` up to, but not + * including, `end`. + * + * **Note:** This method mutates `array`. + * + * @static + * @memberOf _ + * @since 3.2.0 + * @category Array + * @param {Array} array The array to fill. + * @param {*} value The value to fill `array` with. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns `array`. + * @example + * + * var array = [1, 2, 3]; + * + * _.fill(array, 'a'); + * console.log(array); + * // => ['a', 'a', 'a'] + * + * _.fill(Array(3), 2); + * // => [2, 2, 2] + * + * _.fill([4, 6, 8, 10], '*', 1, 3); + * // => [4, '*', '*', 10] + */ + function fill(array, value, start, end) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + if (start && typeof start != 'number' && isIterateeCall(array, value, start)) { + start = 0; + end = length; + } + return baseFill(array, value, start, end); + } + + /** + * This method is like `_.find` except that it returns the index of the first + * element `predicate` returns truthy for instead of the element itself. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the found element, else `-1`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.findIndex(users, function(o) { return o.user == 'barney'; }); + * // => 0 + * + * // The `_.matches` iteratee shorthand. + * _.findIndex(users, { 'user': 'fred', 'active': false }); + * // => 1 + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findIndex(users, ['active', false]); + * // => 0 + * + * // The `_.property` iteratee shorthand. + * _.findIndex(users, 'active'); + * // => 2 + */ + function findIndex(array, predicate, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = fromIndex == null ? 0 : toInteger(fromIndex); + if (index < 0) { + index = nativeMax(length + index, 0); + } + return baseFindIndex(array, getIteratee(predicate, 3), index); + } + + /** + * This method is like `_.findIndex` except that it iterates over elements + * of `collection` from right to left. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=array.length-1] The index to search from. + * @returns {number} Returns the index of the found element, else `-1`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ]; + * + * _.findLastIndex(users, function(o) { return o.user == 'pebbles'; }); + * // => 2 + * + * // The `_.matches` iteratee shorthand. + * _.findLastIndex(users, { 'user': 'barney', 'active': true }); + * // => 0 + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findLastIndex(users, ['active', false]); + * // => 2 + * + * // The `_.property` iteratee shorthand. + * _.findLastIndex(users, 'active'); + * // => 0 + */ + function findLastIndex(array, predicate, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = length - 1; + if (fromIndex !== undefined$1) { + index = toInteger(fromIndex); + index = fromIndex < 0 + ? nativeMax(length + index, 0) + : nativeMin(index, length - 1); + } + return baseFindIndex(array, getIteratee(predicate, 3), index, true); + } + + /** + * Flattens `array` a single level deep. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to flatten. + * @returns {Array} Returns the new flattened array. + * @example + * + * _.flatten([1, [2, [3, [4]], 5]]); + * // => [1, 2, [3, [4]], 5] + */ + function flatten(array) { + var length = array == null ? 0 : array.length; + return length ? baseFlatten(array, 1) : []; + } + + /** + * Recursively flattens `array`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to flatten. + * @returns {Array} Returns the new flattened array. + * @example + * + * _.flattenDeep([1, [2, [3, [4]], 5]]); + * // => [1, 2, 3, 4, 5] + */ + function flattenDeep(array) { + var length = array == null ? 0 : array.length; + return length ? baseFlatten(array, INFINITY) : []; + } + + /** + * Recursively flatten `array` up to `depth` times. + * + * @static + * @memberOf _ + * @since 4.4.0 + * @category Array + * @param {Array} array The array to flatten. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * var array = [1, [2, [3, [4]], 5]]; + * + * _.flattenDepth(array, 1); + * // => [1, 2, [3, [4]], 5] + * + * _.flattenDepth(array, 2); + * // => [1, 2, 3, [4], 5] + */ + function flattenDepth(array, depth) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + depth = depth === undefined$1 ? 1 : toInteger(depth); + return baseFlatten(array, depth); + } + + /** + * The inverse of `_.toPairs`; this method returns an object composed + * from key-value `pairs`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} pairs The key-value pairs. + * @returns {Object} Returns the new object. + * @example + * + * _.fromPairs([['a', 1], ['b', 2]]); + * // => { 'a': 1, 'b': 2 } + */ + function fromPairs(pairs) { + var index = -1, + length = pairs == null ? 0 : pairs.length, + result = {}; + + while (++index < length) { + var pair = pairs[index]; + result[pair[0]] = pair[1]; + } + return result; + } + + /** + * Gets the first element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @alias first + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the first element of `array`. + * @example + * + * _.head([1, 2, 3]); + * // => 1 + * + * _.head([]); + * // => undefined + */ + function head(array) { + return (array && array.length) ? array[0] : undefined$1; + } + + /** + * Gets the index at which the first occurrence of `value` is found in `array` + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. If `fromIndex` is negative, it's used as the + * offset from the end of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.indexOf([1, 2, 1, 2], 2); + * // => 1 + * + * // Search from the `fromIndex`. + * _.indexOf([1, 2, 1, 2], 2, 2); + * // => 3 + */ + function indexOf(array, value, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = fromIndex == null ? 0 : toInteger(fromIndex); + if (index < 0) { + index = nativeMax(length + index, 0); + } + return baseIndexOf(array, value, index); + } + + /** + * Gets all but the last element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.initial([1, 2, 3]); + * // => [1, 2] + */ + function initial(array) { + var length = array == null ? 0 : array.length; + return length ? baseSlice(array, 0, -1) : []; + } + + /** + * Creates an array of unique values that are included in all given arrays + * using [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. The order and references of result values are + * determined by the first array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersection([2, 1], [2, 3]); + * // => [2] + */ + var intersection = baseRest(function(arrays) { + var mapped = arrayMap(arrays, castArrayLikeObject); + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped) + : []; + }); + + /** + * This method is like `_.intersection` except that it accepts `iteratee` + * which is invoked for each element of each `arrays` to generate the criterion + * by which they're compared. The order and references of result values are + * determined by the first array. The iteratee is invoked with one argument: + * (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * _.intersectionBy([2.1, 1.2], [2.3, 3.4], Math.floor); + * // => [2.1] + * + * // The `_.property` iteratee shorthand. + * _.intersectionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }] + */ + var intersectionBy = baseRest(function(arrays) { + var iteratee = last(arrays), + mapped = arrayMap(arrays, castArrayLikeObject); + + if (iteratee === last(mapped)) { + iteratee = undefined$1; + } else { + mapped.pop(); + } + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped, getIteratee(iteratee, 2)) + : []; + }); + + /** + * This method is like `_.intersection` except that it accepts `comparator` + * which is invoked to compare elements of `arrays`. The order and references + * of result values are determined by the first array. The comparator is + * invoked with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of intersecting values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.intersectionWith(objects, others, _.isEqual); + * // => [{ 'x': 1, 'y': 2 }] + */ + var intersectionWith = baseRest(function(arrays) { + var comparator = last(arrays), + mapped = arrayMap(arrays, castArrayLikeObject); + + comparator = typeof comparator == 'function' ? comparator : undefined$1; + if (comparator) { + mapped.pop(); + } + return (mapped.length && mapped[0] === arrays[0]) + ? baseIntersection(mapped, undefined$1, comparator) + : []; + }); + + /** + * Converts all elements in `array` into a string separated by `separator`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to convert. + * @param {string} [separator=','] The element separator. + * @returns {string} Returns the joined string. + * @example + * + * _.join(['a', 'b', 'c'], '~'); + * // => 'a~b~c' + */ + function join(array, separator) { + return array == null ? '' : nativeJoin.call(array, separator); + } + + /** + * Gets the last element of `array`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @returns {*} Returns the last element of `array`. + * @example + * + * _.last([1, 2, 3]); + * // => 3 + */ + function last(array) { + var length = array == null ? 0 : array.length; + return length ? array[length - 1] : undefined$1; + } + + /** + * This method is like `_.indexOf` except that it iterates over elements of + * `array` from right to left. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=array.length-1] The index to search from. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.lastIndexOf([1, 2, 1, 2], 2); + * // => 3 + * + * // Search from the `fromIndex`. + * _.lastIndexOf([1, 2, 1, 2], 2, 2); + * // => 1 + */ + function lastIndexOf(array, value, fromIndex) { + var length = array == null ? 0 : array.length; + if (!length) { + return -1; + } + var index = length; + if (fromIndex !== undefined$1) { + index = toInteger(fromIndex); + index = index < 0 ? nativeMax(length + index, 0) : nativeMin(index, length - 1); + } + return value === value + ? strictLastIndexOf(array, value, index) + : baseFindIndex(array, baseIsNaN, index, true); + } + + /** + * Gets the element at index `n` of `array`. If `n` is negative, the nth + * element from the end is returned. + * + * @static + * @memberOf _ + * @since 4.11.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=0] The index of the element to return. + * @returns {*} Returns the nth element of `array`. + * @example + * + * var array = ['a', 'b', 'c', 'd']; + * + * _.nth(array, 1); + * // => 'b' + * + * _.nth(array, -2); + * // => 'c'; + */ + function nth(array, n) { + return (array && array.length) ? baseNth(array, toInteger(n)) : undefined$1; + } + + /** + * Removes all given values from `array` using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * **Note:** Unlike `_.without`, this method mutates `array`. Use `_.remove` + * to remove elements from an array by predicate. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {...*} [values] The values to remove. + * @returns {Array} Returns `array`. + * @example + * + * var array = ['a', 'b', 'c', 'a', 'b', 'c']; + * + * _.pull(array, 'a', 'c'); + * console.log(array); + * // => ['b', 'b'] + */ + var pull = baseRest(pullAll); + + /** + * This method is like `_.pull` except that it accepts an array of values to remove. + * + * **Note:** Unlike `_.difference`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @returns {Array} Returns `array`. + * @example + * + * var array = ['a', 'b', 'c', 'a', 'b', 'c']; + * + * _.pullAll(array, ['a', 'c']); + * console.log(array); + * // => ['b', 'b'] + */ + function pullAll(array, values) { + return (array && array.length && values && values.length) + ? basePullAll(array, values) + : array; + } + + /** + * This method is like `_.pullAll` except that it accepts `iteratee` which is + * invoked for each element of `array` and `values` to generate the criterion + * by which they're compared. The iteratee is invoked with one argument: (value). + * + * **Note:** Unlike `_.differenceBy`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns `array`. + * @example + * + * var array = [{ 'x': 1 }, { 'x': 2 }, { 'x': 3 }, { 'x': 1 }]; + * + * _.pullAllBy(array, [{ 'x': 1 }, { 'x': 3 }], 'x'); + * console.log(array); + * // => [{ 'x': 2 }] + */ + function pullAllBy(array, values, iteratee) { + return (array && array.length && values && values.length) + ? basePullAll(array, values, getIteratee(iteratee, 2)) + : array; + } + + /** + * This method is like `_.pullAll` except that it accepts `comparator` which + * is invoked to compare elements of `array` to `values`. The comparator is + * invoked with two arguments: (arrVal, othVal). + * + * **Note:** Unlike `_.differenceWith`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 4.6.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Array} values The values to remove. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns `array`. + * @example + * + * var array = [{ 'x': 1, 'y': 2 }, { 'x': 3, 'y': 4 }, { 'x': 5, 'y': 6 }]; + * + * _.pullAllWith(array, [{ 'x': 3, 'y': 4 }], _.isEqual); + * console.log(array); + * // => [{ 'x': 1, 'y': 2 }, { 'x': 5, 'y': 6 }] + */ + function pullAllWith(array, values, comparator) { + return (array && array.length && values && values.length) + ? basePullAll(array, values, undefined$1, comparator) + : array; + } + + /** + * Removes elements from `array` corresponding to `indexes` and returns an + * array of removed elements. + * + * **Note:** Unlike `_.at`, this method mutates `array`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {...(number|number[])} [indexes] The indexes of elements to remove. + * @returns {Array} Returns the new array of removed elements. + * @example + * + * var array = ['a', 'b', 'c', 'd']; + * var pulled = _.pullAt(array, [1, 3]); + * + * console.log(array); + * // => ['a', 'c'] + * + * console.log(pulled); + * // => ['b', 'd'] + */ + var pullAt = flatRest(function(array, indexes) { + var length = array == null ? 0 : array.length, + result = baseAt(array, indexes); + + basePullAt(array, arrayMap(indexes, function(index) { + return isIndex(index, length) ? +index : index; + }).sort(compareAscending)); + + return result; + }); + + /** + * Removes all elements from `array` that `predicate` returns truthy for + * and returns an array of the removed elements. The predicate is invoked + * with three arguments: (value, index, array). + * + * **Note:** Unlike `_.filter`, this method mutates `array`. Use `_.pull` + * to pull elements from an array by value. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Array + * @param {Array} array The array to modify. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new array of removed elements. + * @example + * + * var array = [1, 2, 3, 4]; + * var evens = _.remove(array, function(n) { + * return n % 2 == 0; + * }); + * + * console.log(array); + * // => [1, 3] + * + * console.log(evens); + * // => [2, 4] + */ + function remove(array, predicate) { + var result = []; + if (!(array && array.length)) { + return result; + } + var index = -1, + indexes = [], + length = array.length; + + predicate = getIteratee(predicate, 3); + while (++index < length) { + var value = array[index]; + if (predicate(value, index, array)) { + result.push(value); + indexes.push(index); + } + } + basePullAt(array, indexes); + return result; + } + + /** + * Reverses `array` so that the first element becomes the last, the second + * element becomes the second to last, and so on. + * + * **Note:** This method mutates `array` and is based on + * [`Array#reverse`](https://mdn.io/Array/reverse). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to modify. + * @returns {Array} Returns `array`. + * @example + * + * var array = [1, 2, 3]; + * + * _.reverse(array); + * // => [3, 2, 1] + * + * console.log(array); + * // => [3, 2, 1] + */ + function reverse(array) { + return array == null ? array : nativeReverse.call(array); + } + + /** + * Creates a slice of `array` from `start` up to, but not including, `end`. + * + * **Note:** This method is used instead of + * [`Array#slice`](https://mdn.io/Array/slice) to ensure dense arrays are + * returned. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to slice. + * @param {number} [start=0] The start position. + * @param {number} [end=array.length] The end position. + * @returns {Array} Returns the slice of `array`. + */ + function slice(array, start, end) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + if (end && typeof end != 'number' && isIterateeCall(array, start, end)) { + start = 0; + end = length; + } + else { + start = start == null ? 0 : toInteger(start); + end = end === undefined$1 ? length : toInteger(end); + } + return baseSlice(array, start, end); + } + + /** + * Uses a binary search to determine the lowest index at which `value` + * should be inserted into `array` in order to maintain its sort order. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * _.sortedIndex([30, 50], 40); + * // => 1 + */ + function sortedIndex(array, value) { + return baseSortedIndex(array, value); + } + + /** + * This method is like `_.sortedIndex` except that it accepts `iteratee` + * which is invoked for `value` and each element of `array` to compute their + * sort ranking. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * var objects = [{ 'x': 4 }, { 'x': 5 }]; + * + * _.sortedIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); + * // => 0 + * + * // The `_.property` iteratee shorthand. + * _.sortedIndexBy(objects, { 'x': 4 }, 'x'); + * // => 0 + */ + function sortedIndexBy(array, value, iteratee) { + return baseSortedIndexBy(array, value, getIteratee(iteratee, 2)); + } + + /** + * This method is like `_.indexOf` except that it performs a binary + * search on a sorted `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.sortedIndexOf([4, 5, 5, 5, 6], 5); + * // => 1 + */ + function sortedIndexOf(array, value) { + var length = array == null ? 0 : array.length; + if (length) { + var index = baseSortedIndex(array, value); + if (index < length && eq(array[index], value)) { + return index; + } + } + return -1; + } + + /** + * This method is like `_.sortedIndex` except that it returns the highest + * index at which `value` should be inserted into `array` in order to + * maintain its sort order. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * _.sortedLastIndex([4, 5, 5, 5, 6], 5); + * // => 4 + */ + function sortedLastIndex(array, value) { + return baseSortedIndex(array, value, true); + } + + /** + * This method is like `_.sortedLastIndex` except that it accepts `iteratee` + * which is invoked for `value` and each element of `array` to compute their + * sort ranking. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The sorted array to inspect. + * @param {*} value The value to evaluate. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {number} Returns the index at which `value` should be inserted + * into `array`. + * @example + * + * var objects = [{ 'x': 4 }, { 'x': 5 }]; + * + * _.sortedLastIndexBy(objects, { 'x': 4 }, function(o) { return o.x; }); + * // => 1 + * + * // The `_.property` iteratee shorthand. + * _.sortedLastIndexBy(objects, { 'x': 4 }, 'x'); + * // => 1 + */ + function sortedLastIndexBy(array, value, iteratee) { + return baseSortedIndexBy(array, value, getIteratee(iteratee, 2), true); + } + + /** + * This method is like `_.lastIndexOf` except that it performs a binary + * search on a sorted `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {*} value The value to search for. + * @returns {number} Returns the index of the matched value, else `-1`. + * @example + * + * _.sortedLastIndexOf([4, 5, 5, 5, 6], 5); + * // => 3 + */ + function sortedLastIndexOf(array, value) { + var length = array == null ? 0 : array.length; + if (length) { + var index = baseSortedIndex(array, value, true) - 1; + if (eq(array[index], value)) { + return index; + } + } + return -1; + } + + /** + * This method is like `_.uniq` except that it's designed and optimized + * for sorted arrays. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.sortedUniq([1, 1, 2]); + * // => [1, 2] + */ + function sortedUniq(array) { + return (array && array.length) + ? baseSortedUniq(array) + : []; + } + + /** + * This method is like `_.uniqBy` except that it's designed and optimized + * for sorted arrays. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [iteratee] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.sortedUniqBy([1.1, 1.2, 2.3, 2.4], Math.floor); + * // => [1.1, 2.3] + */ + function sortedUniqBy(array, iteratee) { + return (array && array.length) + ? baseSortedUniq(array, getIteratee(iteratee, 2)) + : []; + } + + /** + * Gets all but the first element of `array`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to query. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.tail([1, 2, 3]); + * // => [2, 3] + */ + function tail(array) { + var length = array == null ? 0 : array.length; + return length ? baseSlice(array, 1, length) : []; + } + + /** + * Creates a slice of `array` with `n` elements taken from the beginning. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.take([1, 2, 3]); + * // => [1] + * + * _.take([1, 2, 3], 2); + * // => [1, 2] + * + * _.take([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.take([1, 2, 3], 0); + * // => [] + */ + function take(array, n, guard) { + if (!(array && array.length)) { + return []; + } + n = (guard || n === undefined$1) ? 1 : toInteger(n); + return baseSlice(array, 0, n < 0 ? 0 : n); + } + + /** + * Creates a slice of `array` with `n` elements taken from the end. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {number} [n=1] The number of elements to take. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the slice of `array`. + * @example + * + * _.takeRight([1, 2, 3]); + * // => [3] + * + * _.takeRight([1, 2, 3], 2); + * // => [2, 3] + * + * _.takeRight([1, 2, 3], 5); + * // => [1, 2, 3] + * + * _.takeRight([1, 2, 3], 0); + * // => [] + */ + function takeRight(array, n, guard) { + var length = array == null ? 0 : array.length; + if (!length) { + return []; + } + n = (guard || n === undefined$1) ? 1 : toInteger(n); + n = length - n; + return baseSlice(array, n < 0 ? 0 : n, length); + } + + /** + * Creates a slice of `array` with elements taken from the end. Elements are + * taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': false } + * ]; + * + * _.takeRightWhile(users, function(o) { return !o.active; }); + * // => objects for ['fred', 'pebbles'] + * + * // The `_.matches` iteratee shorthand. + * _.takeRightWhile(users, { 'user': 'pebbles', 'active': false }); + * // => objects for ['pebbles'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.takeRightWhile(users, ['active', false]); + * // => objects for ['fred', 'pebbles'] + * + * // The `_.property` iteratee shorthand. + * _.takeRightWhile(users, 'active'); + * // => [] + */ + function takeRightWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3), false, true) + : []; + } + + /** + * Creates a slice of `array` with elements taken from the beginning. Elements + * are taken until `predicate` returns falsey. The predicate is invoked with + * three arguments: (value, index, array). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Array + * @param {Array} array The array to query. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the slice of `array`. + * @example + * + * var users = [ + * { 'user': 'barney', 'active': false }, + * { 'user': 'fred', 'active': false }, + * { 'user': 'pebbles', 'active': true } + * ]; + * + * _.takeWhile(users, function(o) { return !o.active; }); + * // => objects for ['barney', 'fred'] + * + * // The `_.matches` iteratee shorthand. + * _.takeWhile(users, { 'user': 'barney', 'active': false }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.takeWhile(users, ['active', false]); + * // => objects for ['barney', 'fred'] + * + * // The `_.property` iteratee shorthand. + * _.takeWhile(users, 'active'); + * // => [] + */ + function takeWhile(array, predicate) { + return (array && array.length) + ? baseWhile(array, getIteratee(predicate, 3)) + : []; + } + + /** + * Creates an array of unique values, in order, from all given arrays using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.union([2], [1, 2]); + * // => [2, 1] + */ + var union = baseRest(function(arrays) { + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true)); + }); + + /** + * This method is like `_.union` except that it accepts `iteratee` which is + * invoked for each element of each `arrays` to generate the criterion by + * which uniqueness is computed. Result values are chosen from the first + * array in which the value occurs. The iteratee is invoked with one argument: + * (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of combined values. + * @example + * + * _.unionBy([2.1], [1.2, 2.3], Math.floor); + * // => [2.1, 1.2] + * + * // The `_.property` iteratee shorthand. + * _.unionBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] + */ + var unionBy = baseRest(function(arrays) { + var iteratee = last(arrays); + if (isArrayLikeObject(iteratee)) { + iteratee = undefined$1; + } + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), getIteratee(iteratee, 2)); + }); + + /** + * This method is like `_.union` except that it accepts `comparator` which + * is invoked to compare elements of `arrays`. Result values are chosen from + * the first array in which the value occurs. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of combined values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.unionWith(objects, others, _.isEqual); + * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] + */ + var unionWith = baseRest(function(arrays) { + var comparator = last(arrays); + comparator = typeof comparator == 'function' ? comparator : undefined$1; + return baseUniq(baseFlatten(arrays, 1, isArrayLikeObject, true), undefined$1, comparator); + }); + + /** + * Creates a duplicate-free version of an array, using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons, in which only the first occurrence of each element + * is kept. The order of result values is determined by the order they occur + * in the array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.uniq([2, 1, 2]); + * // => [2, 1] + */ + function uniq(array) { + return (array && array.length) ? baseUniq(array) : []; + } + + /** + * This method is like `_.uniq` except that it accepts `iteratee` which is + * invoked for each element in `array` to generate the criterion by which + * uniqueness is computed. The order of result values is determined by the + * order they occur in the array. The iteratee is invoked with one argument: + * (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * _.uniqBy([2.1, 1.2, 2.3], Math.floor); + * // => [2.1, 1.2] + * + * // The `_.property` iteratee shorthand. + * _.uniqBy([{ 'x': 1 }, { 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 1 }, { 'x': 2 }] + */ + function uniqBy(array, iteratee) { + return (array && array.length) ? baseUniq(array, getIteratee(iteratee, 2)) : []; + } + + /** + * This method is like `_.uniq` except that it accepts `comparator` which + * is invoked to compare elements of `array`. The order of result values is + * determined by the order they occur in the array.The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new duplicate free array. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.uniqWith(objects, _.isEqual); + * // => [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }] + */ + function uniqWith(array, comparator) { + comparator = typeof comparator == 'function' ? comparator : undefined$1; + return (array && array.length) ? baseUniq(array, undefined$1, comparator) : []; + } + + /** + * This method is like `_.zip` except that it accepts an array of grouped + * elements and creates an array regrouping the elements to their pre-zip + * configuration. + * + * @static + * @memberOf _ + * @since 1.2.0 + * @category Array + * @param {Array} array The array of grouped elements to process. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * var zipped = _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] + * + * _.unzip(zipped); + * // => [['a', 'b'], [1, 2], [true, false]] + */ + function unzip(array) { + if (!(array && array.length)) { + return []; + } + var length = 0; + array = arrayFilter(array, function(group) { + if (isArrayLikeObject(group)) { + length = nativeMax(group.length, length); + return true; + } + }); + return baseTimes(length, function(index) { + return arrayMap(array, baseProperty(index)); + }); + } + + /** + * This method is like `_.unzip` except that it accepts `iteratee` to specify + * how regrouped values should be combined. The iteratee is invoked with the + * elements of each group: (...group). + * + * @static + * @memberOf _ + * @since 3.8.0 + * @category Array + * @param {Array} array The array of grouped elements to process. + * @param {Function} [iteratee=_.identity] The function to combine + * regrouped values. + * @returns {Array} Returns the new array of regrouped elements. + * @example + * + * var zipped = _.zip([1, 2], [10, 20], [100, 200]); + * // => [[1, 10, 100], [2, 20, 200]] + * + * _.unzipWith(zipped, _.add); + * // => [3, 30, 300] + */ + function unzipWith(array, iteratee) { + if (!(array && array.length)) { + return []; + } + var result = unzip(array); + if (iteratee == null) { + return result; + } + return arrayMap(result, function(group) { + return apply(iteratee, undefined$1, group); + }); + } + + /** + * Creates an array excluding all given values using + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * for equality comparisons. + * + * **Note:** Unlike `_.pull`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {Array} array The array to inspect. + * @param {...*} [values] The values to exclude. + * @returns {Array} Returns the new array of filtered values. + * @see _.difference, _.xor + * @example + * + * _.without([2, 1, 2, 3], 1, 2); + * // => [3] + */ + var without = baseRest(function(array, values) { + return isArrayLikeObject(array) + ? baseDifference(array, values) + : []; + }); + + /** + * Creates an array of unique values that is the + * [symmetric difference](https://en.wikipedia.org/wiki/Symmetric_difference) + * of the given arrays. The order of result values is determined by the order + * they occur in the arrays. + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @returns {Array} Returns the new array of filtered values. + * @see _.difference, _.without + * @example + * + * _.xor([2, 1], [2, 3]); + * // => [1, 3] + */ + var xor = baseRest(function(arrays) { + return baseXor(arrayFilter(arrays, isArrayLikeObject)); + }); + + /** + * This method is like `_.xor` except that it accepts `iteratee` which is + * invoked for each element of each `arrays` to generate the criterion by + * which by which they're compared. The order of result values is determined + * by the order they occur in the arrays. The iteratee is invoked with one + * argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * _.xorBy([2.1, 1.2], [2.3, 3.4], Math.floor); + * // => [1.2, 3.4] + * + * // The `_.property` iteratee shorthand. + * _.xorBy([{ 'x': 1 }], [{ 'x': 2 }, { 'x': 1 }], 'x'); + * // => [{ 'x': 2 }] + */ + var xorBy = baseRest(function(arrays) { + var iteratee = last(arrays); + if (isArrayLikeObject(iteratee)) { + iteratee = undefined$1; + } + return baseXor(arrayFilter(arrays, isArrayLikeObject), getIteratee(iteratee, 2)); + }); + + /** + * This method is like `_.xor` except that it accepts `comparator` which is + * invoked to compare elements of `arrays`. The order of result values is + * determined by the order they occur in the arrays. The comparator is invoked + * with two arguments: (arrVal, othVal). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Array + * @param {...Array} [arrays] The arrays to inspect. + * @param {Function} [comparator] The comparator invoked per element. + * @returns {Array} Returns the new array of filtered values. + * @example + * + * var objects = [{ 'x': 1, 'y': 2 }, { 'x': 2, 'y': 1 }]; + * var others = [{ 'x': 1, 'y': 1 }, { 'x': 1, 'y': 2 }]; + * + * _.xorWith(objects, others, _.isEqual); + * // => [{ 'x': 2, 'y': 1 }, { 'x': 1, 'y': 1 }] + */ + var xorWith = baseRest(function(arrays) { + var comparator = last(arrays); + comparator = typeof comparator == 'function' ? comparator : undefined$1; + return baseXor(arrayFilter(arrays, isArrayLikeObject), undefined$1, comparator); + }); + + /** + * Creates an array of grouped elements, the first of which contains the + * first elements of the given arrays, the second of which contains the + * second elements of the given arrays, and so on. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @returns {Array} Returns the new array of grouped elements. + * @example + * + * _.zip(['a', 'b'], [1, 2], [true, false]); + * // => [['a', 1, true], ['b', 2, false]] + */ + var zip = baseRest(unzip); + + /** + * This method is like `_.fromPairs` except that it accepts two arrays, + * one of property identifiers and one of corresponding values. + * + * @static + * @memberOf _ + * @since 0.4.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObject(['a', 'b'], [1, 2]); + * // => { 'a': 1, 'b': 2 } + */ + function zipObject(props, values) { + return baseZipObject(props || [], values || [], assignValue); + } + + /** + * This method is like `_.zipObject` except that it supports property paths. + * + * @static + * @memberOf _ + * @since 4.1.0 + * @category Array + * @param {Array} [props=[]] The property identifiers. + * @param {Array} [values=[]] The property values. + * @returns {Object} Returns the new object. + * @example + * + * _.zipObjectDeep(['a.b[0].c', 'a.b[1].d'], [1, 2]); + * // => { 'a': { 'b': [{ 'c': 1 }, { 'd': 2 }] } } + */ + function zipObjectDeep(props, values) { + return baseZipObject(props || [], values || [], baseSet); + } + + /** + * This method is like `_.zip` except that it accepts `iteratee` to specify + * how grouped values should be combined. The iteratee is invoked with the + * elements of each group: (...group). + * + * @static + * @memberOf _ + * @since 3.8.0 + * @category Array + * @param {...Array} [arrays] The arrays to process. + * @param {Function} [iteratee=_.identity] The function to combine + * grouped values. + * @returns {Array} Returns the new array of grouped elements. + * @example + * + * _.zipWith([1, 2], [10, 20], [100, 200], function(a, b, c) { + * return a + b + c; + * }); + * // => [111, 222] + */ + var zipWith = baseRest(function(arrays) { + var length = arrays.length, + iteratee = length > 1 ? arrays[length - 1] : undefined$1; + + iteratee = typeof iteratee == 'function' ? (arrays.pop(), iteratee) : undefined$1; + return unzipWith(arrays, iteratee); + }); + + /*------------------------------------------------------------------------*/ + + /** + * Creates a `lodash` wrapper instance that wraps `value` with explicit method + * chain sequences enabled. The result of such sequences must be unwrapped + * with `_#value`. + * + * @static + * @memberOf _ + * @since 1.3.0 + * @category Seq + * @param {*} value The value to wrap. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36 }, + * { 'user': 'fred', 'age': 40 }, + * { 'user': 'pebbles', 'age': 1 } + * ]; + * + * var youngest = _ + * .chain(users) + * .sortBy('age') + * .map(function(o) { + * return o.user + ' is ' + o.age; + * }) + * .head() + * .value(); + * // => 'pebbles is 1' + */ + function chain(value) { + var result = lodash(value); + result.__chain__ = true; + return result; + } + + /** + * This method invokes `interceptor` and returns `value`. The interceptor + * is invoked with one argument; (value). The purpose of this method is to + * "tap into" a method chain sequence in order to modify intermediate results. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @param {*} value The value to provide to `interceptor`. + * @param {Function} interceptor The function to invoke. + * @returns {*} Returns `value`. + * @example + * + * _([1, 2, 3]) + * .tap(function(array) { + * // Mutate input array. + * array.pop(); + * }) + * .reverse() + * .value(); + * // => [2, 1] + */ + function tap(value, interceptor) { + interceptor(value); + return value; + } + + /** + * This method is like `_.tap` except that it returns the result of `interceptor`. + * The purpose of this method is to "pass thru" values replacing intermediate + * results in a method chain sequence. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Seq + * @param {*} value The value to provide to `interceptor`. + * @param {Function} interceptor The function to invoke. + * @returns {*} Returns the result of `interceptor`. + * @example + * + * _(' abc ') + * .chain() + * .trim() + * .thru(function(value) { + * return [value]; + * }) + * .value(); + * // => ['abc'] + */ + function thru(value, interceptor) { + return interceptor(value); + } + + /** + * This method is the wrapper version of `_.at`. + * + * @name at + * @memberOf _ + * @since 1.0.0 + * @category Seq + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; + * + * _(object).at(['a[0].b.c', 'a[1]']).value(); + * // => [3, 4] + */ + var wrapperAt = flatRest(function(paths) { + var length = paths.length, + start = length ? paths[0] : 0, + value = this.__wrapped__, + interceptor = function(object) { return baseAt(object, paths); }; + + if (length > 1 || this.__actions__.length || + !(value instanceof LazyWrapper) || !isIndex(start)) { + return this.thru(interceptor); + } + value = value.slice(start, +start + (length ? 1 : 0)); + value.__actions__.push({ + 'func': thru, + 'args': [interceptor], + 'thisArg': undefined$1 + }); + return new LodashWrapper(value, this.__chain__).thru(function(array) { + if (length && !array.length) { + array.push(undefined$1); + } + return array; + }); + }); + + /** + * Creates a `lodash` wrapper instance with explicit method chain sequences enabled. + * + * @name chain + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36 }, + * { 'user': 'fred', 'age': 40 } + * ]; + * + * // A sequence without explicit chaining. + * _(users).head(); + * // => { 'user': 'barney', 'age': 36 } + * + * // A sequence with explicit chaining. + * _(users) + * .chain() + * .head() + * .pick('user') + * .value(); + * // => { 'user': 'barney' } + */ + function wrapperChain() { + return chain(this); + } + + /** + * Executes the chain sequence and returns the wrapped result. + * + * @name commit + * @memberOf _ + * @since 3.2.0 + * @category Seq + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2]; + * var wrapped = _(array).push(3); + * + * console.log(array); + * // => [1, 2] + * + * wrapped = wrapped.commit(); + * console.log(array); + * // => [1, 2, 3] + * + * wrapped.last(); + * // => 3 + * + * console.log(array); + * // => [1, 2, 3] + */ + function wrapperCommit() { + return new LodashWrapper(this.value(), this.__chain__); + } + + /** + * Gets the next value on a wrapped object following the + * [iterator protocol](https://mdn.io/iteration_protocols#iterator). + * + * @name next + * @memberOf _ + * @since 4.0.0 + * @category Seq + * @returns {Object} Returns the next iterator value. + * @example + * + * var wrapped = _([1, 2]); + * + * wrapped.next(); + * // => { 'done': false, 'value': 1 } + * + * wrapped.next(); + * // => { 'done': false, 'value': 2 } + * + * wrapped.next(); + * // => { 'done': true, 'value': undefined } + */ + function wrapperNext() { + if (this.__values__ === undefined$1) { + this.__values__ = toArray(this.value()); + } + var done = this.__index__ >= this.__values__.length, + value = done ? undefined$1 : this.__values__[this.__index__++]; + + return { 'done': done, 'value': value }; + } + + /** + * Enables the wrapper to be iterable. + * + * @name Symbol.iterator + * @memberOf _ + * @since 4.0.0 + * @category Seq + * @returns {Object} Returns the wrapper object. + * @example + * + * var wrapped = _([1, 2]); + * + * wrapped[Symbol.iterator]() === wrapped; + * // => true + * + * Array.from(wrapped); + * // => [1, 2] + */ + function wrapperToIterator() { + return this; + } + + /** + * Creates a clone of the chain sequence planting `value` as the wrapped value. + * + * @name plant + * @memberOf _ + * @since 3.2.0 + * @category Seq + * @param {*} value The value to plant. + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * function square(n) { + * return n * n; + * } + * + * var wrapped = _([1, 2]).map(square); + * var other = wrapped.plant([3, 4]); + * + * other.value(); + * // => [9, 16] + * + * wrapped.value(); + * // => [1, 4] + */ + function wrapperPlant(value) { + var result, + parent = this; + + while (parent instanceof baseLodash) { + var clone = wrapperClone(parent); + clone.__index__ = 0; + clone.__values__ = undefined$1; + if (result) { + previous.__wrapped__ = clone; + } else { + result = clone; + } + var previous = clone; + parent = parent.__wrapped__; + } + previous.__wrapped__ = value; + return result; + } + + /** + * This method is the wrapper version of `_.reverse`. + * + * **Note:** This method mutates the wrapped array. + * + * @name reverse + * @memberOf _ + * @since 0.1.0 + * @category Seq + * @returns {Object} Returns the new `lodash` wrapper instance. + * @example + * + * var array = [1, 2, 3]; + * + * _(array).reverse().value() + * // => [3, 2, 1] + * + * console.log(array); + * // => [3, 2, 1] + */ + function wrapperReverse() { + var value = this.__wrapped__; + if (value instanceof LazyWrapper) { + var wrapped = value; + if (this.__actions__.length) { + wrapped = new LazyWrapper(this); + } + wrapped = wrapped.reverse(); + wrapped.__actions__.push({ + 'func': thru, + 'args': [reverse], + 'thisArg': undefined$1 + }); + return new LodashWrapper(wrapped, this.__chain__); + } + return this.thru(reverse); + } + + /** + * Executes the chain sequence to resolve the unwrapped value. + * + * @name value + * @memberOf _ + * @since 0.1.0 + * @alias toJSON, valueOf + * @category Seq + * @returns {*} Returns the resolved unwrapped value. + * @example + * + * _([1, 2, 3]).value(); + * // => [1, 2, 3] + */ + function wrapperValue() { + return baseWrapperValue(this.__wrapped__, this.__actions__); + } + + /*------------------------------------------------------------------------*/ + + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the number of times the key was returned by `iteratee`. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.countBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': 1, '6': 2 } + * + * // The `_.property` iteratee shorthand. + * _.countBy(['one', 'two', 'three'], 'length'); + * // => { '3': 2, '5': 1 } + */ + var countBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + ++result[key]; + } else { + baseAssignValue(result, key, 1); + } + }); + + /** + * Checks if `predicate` returns truthy for **all** elements of `collection`. + * Iteration is stopped once `predicate` returns falsey. The predicate is + * invoked with three arguments: (value, index|key, collection). + * + * **Note:** This method returns `true` for + * [empty collections](https://en.wikipedia.org/wiki/Empty_set) because + * [everything is true](https://en.wikipedia.org/wiki/Vacuous_truth) of + * elements of empty collections. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {boolean} Returns `true` if all elements pass the predicate check, + * else `false`. + * @example + * + * _.every([true, 1, null, 'yes'], Boolean); + * // => false + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': false } + * ]; + * + * // The `_.matches` iteratee shorthand. + * _.every(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // The `_.matchesProperty` iteratee shorthand. + * _.every(users, ['active', false]); + * // => true + * + * // The `_.property` iteratee shorthand. + * _.every(users, 'active'); + * // => false + */ + function every(collection, predicate, guard) { + var func = isArray(collection) ? arrayEvery : baseEvery; + if (guard && isIterateeCall(collection, predicate, guard)) { + predicate = undefined$1; + } + return func(collection, getIteratee(predicate, 3)); + } + + /** + * Iterates over elements of `collection`, returning an array of all elements + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). + * + * **Note:** Unlike `_.remove`, this method returns a new array. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.reject + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false } + * ]; + * + * _.filter(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.filter(users, { 'age': 36, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.filter(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.filter(users, 'active'); + * // => objects for ['barney'] + * + * // Combining several predicates using `_.overEvery` or `_.overSome`. + * _.filter(users, _.overSome([{ 'age': 36 }, ['age', 40]])); + * // => objects for ['fred', 'barney'] + */ + function filter(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, getIteratee(predicate, 3)); + } + + /** + * Iterates over elements of `collection`, returning the first element + * `predicate` returns truthy for. The predicate is invoked with three + * arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=0] The index to search from. + * @returns {*} Returns the matched element, else `undefined`. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': true }, + * { 'user': 'fred', 'age': 40, 'active': false }, + * { 'user': 'pebbles', 'age': 1, 'active': true } + * ]; + * + * _.find(users, function(o) { return o.age < 40; }); + * // => object for 'barney' + * + * // The `_.matches` iteratee shorthand. + * _.find(users, { 'age': 1, 'active': true }); + * // => object for 'pebbles' + * + * // The `_.matchesProperty` iteratee shorthand. + * _.find(users, ['active', false]); + * // => object for 'fred' + * + * // The `_.property` iteratee shorthand. + * _.find(users, 'active'); + * // => object for 'barney' + */ + var find = createFind(findIndex); + + /** + * This method is like `_.find` except that it iterates over elements of + * `collection` from right to left. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Collection + * @param {Array|Object} collection The collection to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param {number} [fromIndex=collection.length-1] The index to search from. + * @returns {*} Returns the matched element, else `undefined`. + * @example + * + * _.findLast([1, 2, 3, 4], function(n) { + * return n % 2 == 1; + * }); + * // => 3 + */ + var findLast = createFind(findLastIndex); + + /** + * Creates a flattened array of values by running each element in `collection` + * thru `iteratee` and flattening the mapped results. The iteratee is invoked + * with three arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [n, n]; + * } + * + * _.flatMap([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMap(collection, iteratee) { + return baseFlatten(map(collection, iteratee), 1); + } + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDeep([1, 2], duplicate); + * // => [1, 1, 2, 2] + */ + function flatMapDeep(collection, iteratee) { + return baseFlatten(map(collection, iteratee), INFINITY); + } + + /** + * This method is like `_.flatMap` except that it recursively flattens the + * mapped results up to `depth` times. + * + * @static + * @memberOf _ + * @since 4.7.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {number} [depth=1] The maximum recursion depth. + * @returns {Array} Returns the new flattened array. + * @example + * + * function duplicate(n) { + * return [[[n, n]]]; + * } + * + * _.flatMapDepth([1, 2], duplicate, 2); + * // => [[1, 1], [2, 2]] + */ + function flatMapDepth(collection, iteratee, depth) { + depth = depth === undefined$1 ? 1 : toInteger(depth); + return baseFlatten(map(collection, iteratee), depth); + } + + /** + * Iterates over elements of `collection` and invokes `iteratee` for each element. + * The iteratee is invoked with three arguments: (value, index|key, collection). + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * **Note:** As with other "Collections" methods, objects with a "length" + * property are iterated like arrays. To avoid this behavior use `_.forIn` + * or `_.forOwn` for object iteration. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @alias each + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @see _.forEachRight + * @example + * + * _.forEach([1, 2], function(value) { + * console.log(value); + * }); + * // => Logs `1` then `2`. + * + * _.forEach({ 'a': 1, 'b': 2 }, function(value, key) { + * console.log(key); + * }); + * // => Logs 'a' then 'b' (iteration order is not guaranteed). + */ + function forEach(collection, iteratee) { + var func = isArray(collection) ? arrayEach : baseEach; + return func(collection, getIteratee(iteratee, 3)); + } + + /** + * This method is like `_.forEach` except that it iterates over elements of + * `collection` from right to left. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @alias eachRight + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array|Object} Returns `collection`. + * @see _.forEach + * @example + * + * _.forEachRight([1, 2], function(value) { + * console.log(value); + * }); + * // => Logs `2` then `1`. + */ + function forEachRight(collection, iteratee) { + var func = isArray(collection) ? arrayEachRight : baseEachRight; + return func(collection, getIteratee(iteratee, 3)); + } + + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The order of grouped values + * is determined by the order they occur in `collection`. The corresponding + * value of each key is an array of elements responsible for generating the + * key. The iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * _.groupBy([6.1, 4.2, 6.3], Math.floor); + * // => { '4': [4.2], '6': [6.1, 6.3] } + * + * // The `_.property` iteratee shorthand. + * _.groupBy(['one', 'two', 'three'], 'length'); + * // => { '3': ['one', 'two'], '5': ['three'] } + */ + var groupBy = createAggregator(function(result, value, key) { + if (hasOwnProperty.call(result, key)) { + result[key].push(value); + } else { + baseAssignValue(result, key, [value]); + } + }); + + /** + * Checks if `value` is in `collection`. If `collection` is a string, it's + * checked for a substring of `value`, otherwise + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * is used for equality comparisons. If `fromIndex` is negative, it's used as + * the offset from the end of `collection`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object|string} collection The collection to inspect. + * @param {*} value The value to search for. + * @param {number} [fromIndex=0] The index to search from. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. + * @returns {boolean} Returns `true` if `value` is found, else `false`. + * @example + * + * _.includes([1, 2, 3], 1); + * // => true + * + * _.includes([1, 2, 3], 1, 2); + * // => false + * + * _.includes({ 'a': 1, 'b': 2 }, 1); + * // => true + * + * _.includes('abcd', 'bc'); + * // => true + */ + function includes(collection, value, fromIndex, guard) { + collection = isArrayLike(collection) ? collection : values(collection); + fromIndex = (fromIndex && !guard) ? toInteger(fromIndex) : 0; + + var length = collection.length; + if (fromIndex < 0) { + fromIndex = nativeMax(length + fromIndex, 0); + } + return isString(collection) + ? (fromIndex <= length && collection.indexOf(value, fromIndex) > -1) + : (!!length && baseIndexOf(collection, value, fromIndex) > -1); + } + + /** + * Invokes the method at `path` of each element in `collection`, returning + * an array of the results of each invoked method. Any additional arguments + * are provided to each invoked method. If `path` is a function, it's invoked + * for, and `this` bound to, each element in `collection`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array|Function|string} path The path of the method to invoke or + * the function invoked per iteration. + * @param {...*} [args] The arguments to invoke each method with. + * @returns {Array} Returns the array of results. + * @example + * + * _.invokeMap([[5, 1, 7], [3, 2, 1]], 'sort'); + * // => [[1, 5, 7], [1, 2, 3]] + * + * _.invokeMap([123, 456], String.prototype.split, ''); + * // => [['1', '2', '3'], ['4', '5', '6']] + */ + var invokeMap = baseRest(function(collection, path, args) { + var index = -1, + isFunc = typeof path == 'function', + result = isArrayLike(collection) ? Array(collection.length) : []; + + baseEach(collection, function(value) { + result[++index] = isFunc ? apply(path, value, args) : baseInvoke(value, path, args); + }); + return result; + }); + + /** + * Creates an object composed of keys generated from the results of running + * each element of `collection` thru `iteratee`. The corresponding value of + * each key is the last element responsible for generating the key. The + * iteratee is invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The iteratee to transform keys. + * @returns {Object} Returns the composed aggregate object. + * @example + * + * var array = [ + * { 'dir': 'left', 'code': 97 }, + * { 'dir': 'right', 'code': 100 } + * ]; + * + * _.keyBy(array, function(o) { + * return String.fromCharCode(o.code); + * }); + * // => { 'a': { 'dir': 'left', 'code': 97 }, 'd': { 'dir': 'right', 'code': 100 } } + * + * _.keyBy(array, 'dir'); + * // => { 'left': { 'dir': 'left', 'code': 97 }, 'right': { 'dir': 'right', 'code': 100 } } + */ + var keyBy = createAggregator(function(result, value, key) { + baseAssignValue(result, key, value); + }); + + /** + * Creates an array of values by running each element in `collection` thru + * `iteratee`. The iteratee is invoked with three arguments: + * (value, index|key, collection). + * + * Many lodash methods are guarded to work as iteratees for methods like + * `_.every`, `_.filter`, `_.map`, `_.mapValues`, `_.reject`, and `_.some`. + * + * The guarded methods are: + * `ary`, `chunk`, `curry`, `curryRight`, `drop`, `dropRight`, `every`, + * `fill`, `invert`, `parseInt`, `random`, `range`, `rangeRight`, `repeat`, + * `sampleSize`, `slice`, `some`, `sortBy`, `split`, `take`, `takeRight`, + * `template`, `trim`, `trimEnd`, `trimStart`, and `words` + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new mapped array. + * @example + * + * function square(n) { + * return n * n; + * } + * + * _.map([4, 8], square); + * // => [16, 64] + * + * _.map({ 'a': 4, 'b': 8 }, square); + * // => [16, 64] (iteration order is not guaranteed) + * + * var users = [ + * { 'user': 'barney' }, + * { 'user': 'fred' } + * ]; + * + * // The `_.property` iteratee shorthand. + * _.map(users, 'user'); + * // => ['barney', 'fred'] + */ + function map(collection, iteratee) { + var func = isArray(collection) ? arrayMap : baseMap; + return func(collection, getIteratee(iteratee, 3)); + } + + /** + * This method is like `_.sortBy` except that it allows specifying the sort + * orders of the iteratees to sort by. If `orders` is unspecified, all values + * are sorted in ascending order. Otherwise, specify an order of "desc" for + * descending or "asc" for ascending sort order of corresponding values. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Array[]|Function[]|Object[]|string[]} [iteratees=[_.identity]] + * The iteratees to sort by. + * @param {string[]} [orders] The sort orders of `iteratees`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.reduce`. + * @returns {Array} Returns the new sorted array. + * @example + * + * var users = [ + * { 'user': 'fred', 'age': 48 }, + * { 'user': 'barney', 'age': 34 }, + * { 'user': 'fred', 'age': 40 }, + * { 'user': 'barney', 'age': 36 } + * ]; + * + * // Sort by `user` in ascending order and by `age` in descending order. + * _.orderBy(users, ['user', 'age'], ['asc', 'desc']); + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 40]] + */ + function orderBy(collection, iteratees, orders, guard) { + if (collection == null) { + return []; + } + if (!isArray(iteratees)) { + iteratees = iteratees == null ? [] : [iteratees]; + } + orders = guard ? undefined$1 : orders; + if (!isArray(orders)) { + orders = orders == null ? [] : [orders]; + } + return baseOrderBy(collection, iteratees, orders); + } + + /** + * Creates an array of elements split into two groups, the first of which + * contains elements `predicate` returns truthy for, the second of which + * contains elements `predicate` returns falsey for. The predicate is + * invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the array of grouped elements. + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true }, + * { 'user': 'pebbles', 'age': 1, 'active': false } + * ]; + * + * _.partition(users, function(o) { return o.active; }); + * // => objects for [['fred'], ['barney', 'pebbles']] + * + * // The `_.matches` iteratee shorthand. + * _.partition(users, { 'age': 1, 'active': false }); + * // => objects for [['pebbles'], ['barney', 'fred']] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.partition(users, ['active', false]); + * // => objects for [['barney', 'pebbles'], ['fred']] + * + * // The `_.property` iteratee shorthand. + * _.partition(users, 'active'); + * // => objects for [['fred'], ['barney', 'pebbles']] + */ + var partition = createAggregator(function(result, value, key) { + result[key ? 0 : 1].push(value); + }, function() { return [[], []]; }); + + /** + * Reduces `collection` to a value which is the accumulated result of running + * each element in `collection` thru `iteratee`, where each successive + * invocation is supplied the return value of the previous. If `accumulator` + * is not given, the first element of `collection` is used as the initial + * value. The iteratee is invoked with four arguments: + * (accumulator, value, index|key, collection). + * + * Many lodash methods are guarded to work as iteratees for methods like + * `_.reduce`, `_.reduceRight`, and `_.transform`. + * + * The guarded methods are: + * `assign`, `defaults`, `defaultsDeep`, `includes`, `merge`, `orderBy`, + * and `sortBy` + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @see _.reduceRight + * @example + * + * _.reduce([1, 2], function(sum, n) { + * return sum + n; + * }, 0); + * // => 3 + * + * _.reduce({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { + * (result[value] || (result[value] = [])).push(key); + * return result; + * }, {}); + * // => { '1': ['a', 'c'], '2': ['b'] } (iteration order is not guaranteed) + */ + function reduce(collection, iteratee, accumulator) { + var func = isArray(collection) ? arrayReduce : baseReduce, + initAccum = arguments.length < 3; + + return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEach); + } + + /** + * This method is like `_.reduce` except that it iterates over elements of + * `collection` from right to left. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The initial value. + * @returns {*} Returns the accumulated value. + * @see _.reduce + * @example + * + * var array = [[0, 1], [2, 3], [4, 5]]; + * + * _.reduceRight(array, function(flattened, other) { + * return flattened.concat(other); + * }, []); + * // => [4, 5, 2, 3, 0, 1] + */ + function reduceRight(collection, iteratee, accumulator) { + var func = isArray(collection) ? arrayReduceRight : baseReduce, + initAccum = arguments.length < 3; + + return func(collection, getIteratee(iteratee, 4), accumulator, initAccum, baseEachRight); + } + + /** + * The opposite of `_.filter`; this method returns the elements of `collection` + * that `predicate` does **not** return truthy for. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {Array} Returns the new filtered array. + * @see _.filter + * @example + * + * var users = [ + * { 'user': 'barney', 'age': 36, 'active': false }, + * { 'user': 'fred', 'age': 40, 'active': true } + * ]; + * + * _.reject(users, function(o) { return !o.active; }); + * // => objects for ['fred'] + * + * // The `_.matches` iteratee shorthand. + * _.reject(users, { 'age': 40, 'active': true }); + * // => objects for ['barney'] + * + * // The `_.matchesProperty` iteratee shorthand. + * _.reject(users, ['active', false]); + * // => objects for ['fred'] + * + * // The `_.property` iteratee shorthand. + * _.reject(users, 'active'); + * // => objects for ['barney'] + */ + function reject(collection, predicate) { + var func = isArray(collection) ? arrayFilter : baseFilter; + return func(collection, negate(getIteratee(predicate, 3))); + } + + /** + * Gets a random element from `collection`. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Collection + * @param {Array|Object} collection The collection to sample. + * @returns {*} Returns the random element. + * @example + * + * _.sample([1, 2, 3, 4]); + * // => 2 + */ + function sample(collection) { + var func = isArray(collection) ? arraySample : baseSample; + return func(collection); + } + + /** + * Gets `n` random elements at unique keys from `collection` up to the + * size of `collection`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Collection + * @param {Array|Object} collection The collection to sample. + * @param {number} [n=1] The number of elements to sample. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Array} Returns the random elements. + * @example + * + * _.sampleSize([1, 2, 3], 2); + * // => [3, 1] + * + * _.sampleSize([1, 2, 3], 4); + * // => [2, 3, 1] + */ + function sampleSize(collection, n, guard) { + if ((guard ? isIterateeCall(collection, n, guard) : n === undefined$1)) { + n = 1; + } else { + n = toInteger(n); + } + var func = isArray(collection) ? arraySampleSize : baseSampleSize; + return func(collection, n); + } + + /** + * Creates an array of shuffled values, using a version of the + * [Fisher-Yates shuffle](https://en.wikipedia.org/wiki/Fisher-Yates_shuffle). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to shuffle. + * @returns {Array} Returns the new shuffled array. + * @example + * + * _.shuffle([1, 2, 3, 4]); + * // => [4, 1, 3, 2] + */ + function shuffle(collection) { + var func = isArray(collection) ? arrayShuffle : baseShuffle; + return func(collection); + } + + /** + * Gets the size of `collection` by returning its length for array-like + * values or the number of own enumerable string keyed properties for objects. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object|string} collection The collection to inspect. + * @returns {number} Returns the collection size. + * @example + * + * _.size([1, 2, 3]); + * // => 3 + * + * _.size({ 'a': 1, 'b': 2 }); + * // => 2 + * + * _.size('pebbles'); + * // => 7 + */ + function size(collection) { + if (collection == null) { + return 0; + } + if (isArrayLike(collection)) { + return isString(collection) ? stringSize(collection) : collection.length; + } + var tag = getTag(collection); + if (tag == mapTag || tag == setTag) { + return collection.size; + } + return baseKeys(collection).length; + } + + /** + * Checks if `predicate` returns truthy for **any** element of `collection`. + * Iteration is stopped once `predicate` returns truthy. The predicate is + * invoked with three arguments: (value, index|key, collection). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {boolean} Returns `true` if any element passes the predicate check, + * else `false`. + * @example + * + * _.some([null, 0, 'yes', false], Boolean); + * // => true + * + * var users = [ + * { 'user': 'barney', 'active': true }, + * { 'user': 'fred', 'active': false } + * ]; + * + * // The `_.matches` iteratee shorthand. + * _.some(users, { 'user': 'barney', 'active': false }); + * // => false + * + * // The `_.matchesProperty` iteratee shorthand. + * _.some(users, ['active', false]); + * // => true + * + * // The `_.property` iteratee shorthand. + * _.some(users, 'active'); + * // => true + */ + function some(collection, predicate, guard) { + var func = isArray(collection) ? arraySome : baseSome; + if (guard && isIterateeCall(collection, predicate, guard)) { + predicate = undefined$1; + } + return func(collection, getIteratee(predicate, 3)); + } + + /** + * Creates an array of elements, sorted in ascending order by the results of + * running each element in a collection thru each iteratee. This method + * performs a stable sort, that is, it preserves the original sort order of + * equal elements. The iteratees are invoked with one argument: (value). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Collection + * @param {Array|Object} collection The collection to iterate over. + * @param {...(Function|Function[])} [iteratees=[_.identity]] + * The iteratees to sort by. + * @returns {Array} Returns the new sorted array. + * @example + * + * var users = [ + * { 'user': 'fred', 'age': 48 }, + * { 'user': 'barney', 'age': 36 }, + * { 'user': 'fred', 'age': 30 }, + * { 'user': 'barney', 'age': 34 } + * ]; + * + * _.sortBy(users, [function(o) { return o.user; }]); + * // => objects for [['barney', 36], ['barney', 34], ['fred', 48], ['fred', 30]] + * + * _.sortBy(users, ['user', 'age']); + * // => objects for [['barney', 34], ['barney', 36], ['fred', 30], ['fred', 48]] + */ + var sortBy = baseRest(function(collection, iteratees) { + if (collection == null) { + return []; + } + var length = iteratees.length; + if (length > 1 && isIterateeCall(collection, iteratees[0], iteratees[1])) { + iteratees = []; + } else if (length > 2 && isIterateeCall(iteratees[0], iteratees[1], iteratees[2])) { + iteratees = [iteratees[0]]; + } + return baseOrderBy(collection, baseFlatten(iteratees, 1), []); + }); + + /*------------------------------------------------------------------------*/ + + /** + * Gets the timestamp of the number of milliseconds that have elapsed since + * the Unix epoch (1 January 1970 00:00:00 UTC). + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Date + * @returns {number} Returns the timestamp. + * @example + * + * _.defer(function(stamp) { + * console.log(_.now() - stamp); + * }, _.now()); + * // => Logs the number of milliseconds it took for the deferred invocation. + */ + var now = ctxNow || function() { + return root.Date.now(); + }; + + /*------------------------------------------------------------------------*/ + + /** + * The opposite of `_.before`; this method creates a function that invokes + * `func` once it's called `n` or more times. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {number} n The number of calls before `func` is invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * var saves = ['profile', 'settings']; + * + * var done = _.after(saves.length, function() { + * console.log('done saving!'); + * }); + * + * _.forEach(saves, function(type) { + * asyncSave({ 'type': type, 'complete': done }); + * }); + * // => Logs 'done saving!' after the two async saves have completed. + */ + function after(n, func) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + n = toInteger(n); + return function() { + if (--n < 1) { + return func.apply(this, arguments); + } + }; + } + + /** + * Creates a function that invokes `func`, with up to `n` arguments, + * ignoring any additional arguments. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} func The function to cap arguments for. + * @param {number} [n=func.length] The arity cap. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the new capped function. + * @example + * + * _.map(['6', '8', '10'], _.ary(parseInt, 1)); + * // => [6, 8, 10] + */ + function ary(func, n, guard) { + n = guard ? undefined$1 : n; + n = (func && n == null) ? func.length : n; + return createWrap(func, WRAP_ARY_FLAG, undefined$1, undefined$1, undefined$1, undefined$1, n); + } + + /** + * Creates a function that invokes `func`, with the `this` binding and arguments + * of the created function, while it's called less than `n` times. Subsequent + * calls to the created function return the result of the last `func` invocation. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {number} n The number of calls at which `func` is no longer invoked. + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * jQuery(element).on('click', _.before(5, addContactToList)); + * // => Allows adding up to 4 contacts to the list. + */ + function before(n, func) { + var result; + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + n = toInteger(n); + return function() { + if (--n > 0) { + result = func.apply(this, arguments); + } + if (n <= 1) { + func = undefined$1; + } + return result; + }; + } + + /** + * Creates a function that invokes `func` with the `this` binding of `thisArg` + * and `partials` prepended to the arguments it receives. + * + * The `_.bind.placeholder` value, which defaults to `_` in monolithic builds, + * may be used as a placeholder for partially applied arguments. + * + * **Note:** Unlike native `Function#bind`, this method doesn't set the "length" + * property of bound functions. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to bind. + * @param {*} thisArg The `this` binding of `func`. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new bound function. + * @example + * + * function greet(greeting, punctuation) { + * return greeting + ' ' + this.user + punctuation; + * } + * + * var object = { 'user': 'fred' }; + * + * var bound = _.bind(greet, object, 'hi'); + * bound('!'); + * // => 'hi fred!' + * + * // Bound with placeholders. + * var bound = _.bind(greet, object, _, '!'); + * bound('hi'); + * // => 'hi fred!' + */ + var bind = baseRest(function(func, thisArg, partials) { + var bitmask = WRAP_BIND_FLAG; + if (partials.length) { + var holders = replaceHolders(partials, getHolder(bind)); + bitmask |= WRAP_PARTIAL_FLAG; + } + return createWrap(func, bitmask, thisArg, partials, holders); + }); + + /** + * Creates a function that invokes the method at `object[key]` with `partials` + * prepended to the arguments it receives. + * + * This method differs from `_.bind` by allowing bound functions to reference + * methods that may be redefined or don't yet exist. See + * [Peter Michaux's article](http://peter.michaux.ca/articles/lazy-function-definition-pattern) + * for more details. + * + * The `_.bindKey.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for partially applied arguments. + * + * @static + * @memberOf _ + * @since 0.10.0 + * @category Function + * @param {Object} object The object to invoke the method on. + * @param {string} key The key of the method. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new bound function. + * @example + * + * var object = { + * 'user': 'fred', + * 'greet': function(greeting, punctuation) { + * return greeting + ' ' + this.user + punctuation; + * } + * }; + * + * var bound = _.bindKey(object, 'greet', 'hi'); + * bound('!'); + * // => 'hi fred!' + * + * object.greet = function(greeting, punctuation) { + * return greeting + 'ya ' + this.user + punctuation; + * }; + * + * bound('!'); + * // => 'hiya fred!' + * + * // Bound with placeholders. + * var bound = _.bindKey(object, 'greet', _, '!'); + * bound('hi'); + * // => 'hiya fred!' + */ + var bindKey = baseRest(function(object, key, partials) { + var bitmask = WRAP_BIND_FLAG | WRAP_BIND_KEY_FLAG; + if (partials.length) { + var holders = replaceHolders(partials, getHolder(bindKey)); + bitmask |= WRAP_PARTIAL_FLAG; + } + return createWrap(key, bitmask, object, partials, holders); + }); + + /** + * Creates a function that accepts arguments of `func` and either invokes + * `func` returning its result, if at least `arity` number of arguments have + * been provided, or returns a function that accepts the remaining `func` + * arguments, and so on. The arity of `func` may be specified if `func.length` + * is not sufficient. + * + * The `_.curry.placeholder` value, which defaults to `_` in monolithic builds, + * may be used as a placeholder for provided arguments. + * + * **Note:** This method doesn't set the "length" property of curried functions. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Function + * @param {Function} func The function to curry. + * @param {number} [arity=func.length] The arity of `func`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the new curried function. + * @example + * + * var abc = function(a, b, c) { + * return [a, b, c]; + * }; + * + * var curried = _.curry(abc); + * + * curried(1)(2)(3); + * // => [1, 2, 3] + * + * curried(1, 2)(3); + * // => [1, 2, 3] + * + * curried(1, 2, 3); + * // => [1, 2, 3] + * + * // Curried with placeholders. + * curried(1)(_, 3)(2); + * // => [1, 2, 3] + */ + function curry(func, arity, guard) { + arity = guard ? undefined$1 : arity; + var result = createWrap(func, WRAP_CURRY_FLAG, undefined$1, undefined$1, undefined$1, undefined$1, undefined$1, arity); + result.placeholder = curry.placeholder; + return result; + } + + /** + * This method is like `_.curry` except that arguments are applied to `func` + * in the manner of `_.partialRight` instead of `_.partial`. + * + * The `_.curryRight.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for provided arguments. + * + * **Note:** This method doesn't set the "length" property of curried functions. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} func The function to curry. + * @param {number} [arity=func.length] The arity of `func`. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the new curried function. + * @example + * + * var abc = function(a, b, c) { + * return [a, b, c]; + * }; + * + * var curried = _.curryRight(abc); + * + * curried(3)(2)(1); + * // => [1, 2, 3] + * + * curried(2, 3)(1); + * // => [1, 2, 3] + * + * curried(1, 2, 3); + * // => [1, 2, 3] + * + * // Curried with placeholders. + * curried(3)(1, _)(2); + * // => [1, 2, 3] + */ + function curryRight(func, arity, guard) { + arity = guard ? undefined$1 : arity; + var result = createWrap(func, WRAP_CURRY_RIGHT_FLAG, undefined$1, undefined$1, undefined$1, undefined$1, undefined$1, arity); + result.placeholder = curryRight.placeholder; + return result; + } + + /** + * Creates a debounced function that delays invoking `func` until after `wait` + * milliseconds have elapsed since the last time the debounced function was + * invoked. The debounced function comes with a `cancel` method to cancel + * delayed `func` invocations and a `flush` method to immediately invoke them. + * Provide `options` to indicate whether `func` should be invoked on the + * leading and/or trailing edge of the `wait` timeout. The `func` is invoked + * with the last arguments provided to the debounced function. Subsequent + * calls to the debounced function return the result of the last `func` + * invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the debounced function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until to the next tick, similar to `setTimeout` with a timeout of `0`. + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `_.debounce` and `_.throttle`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to debounce. + * @param {number} [wait=0] The number of milliseconds to delay. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=false] + * Specify invoking on the leading edge of the timeout. + * @param {number} [options.maxWait] + * The maximum time `func` is allowed to be delayed before it's invoked. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new debounced function. + * @example + * + * // Avoid costly calculations while the window size is in flux. + * jQuery(window).on('resize', _.debounce(calculateLayout, 150)); + * + * // Invoke `sendMail` when clicked, debouncing subsequent calls. + * jQuery(element).on('click', _.debounce(sendMail, 300, { + * 'leading': true, + * 'trailing': false + * })); + * + * // Ensure `batchLog` is invoked once after 1 second of debounced calls. + * var debounced = _.debounce(batchLog, 250, { 'maxWait': 1000 }); + * var source = new EventSource('/stream'); + * jQuery(source).on('message', debounced); + * + * // Cancel the trailing debounced invocation. + * jQuery(window).on('popstate', debounced.cancel); + */ + function debounce(func, wait, options) { + var lastArgs, + lastThis, + maxWait, + result, + timerId, + lastCallTime, + lastInvokeTime = 0, + leading = false, + maxing = false, + trailing = true; + + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + wait = toNumber(wait) || 0; + if (isObject(options)) { + leading = !!options.leading; + maxing = 'maxWait' in options; + maxWait = maxing ? nativeMax(toNumber(options.maxWait) || 0, wait) : maxWait; + trailing = 'trailing' in options ? !!options.trailing : trailing; + } + + function invokeFunc(time) { + var args = lastArgs, + thisArg = lastThis; + + lastArgs = lastThis = undefined$1; + lastInvokeTime = time; + result = func.apply(thisArg, args); + return result; + } + + function leadingEdge(time) { + // Reset any `maxWait` timer. + lastInvokeTime = time; + // Start the timer for the trailing edge. + timerId = setTimeout(timerExpired, wait); + // Invoke the leading edge. + return leading ? invokeFunc(time) : result; + } + + function remainingWait(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime, + timeWaiting = wait - timeSinceLastCall; + + return maxing + ? nativeMin(timeWaiting, maxWait - timeSinceLastInvoke) + : timeWaiting; + } + + function shouldInvoke(time) { + var timeSinceLastCall = time - lastCallTime, + timeSinceLastInvoke = time - lastInvokeTime; + + // Either this is the first call, activity has stopped and we're at the + // trailing edge, the system time has gone backwards and we're treating + // it as the trailing edge, or we've hit the `maxWait` limit. + return (lastCallTime === undefined$1 || (timeSinceLastCall >= wait) || + (timeSinceLastCall < 0) || (maxing && timeSinceLastInvoke >= maxWait)); + } + + function timerExpired() { + var time = now(); + if (shouldInvoke(time)) { + return trailingEdge(time); + } + // Restart the timer. + timerId = setTimeout(timerExpired, remainingWait(time)); + } + + function trailingEdge(time) { + timerId = undefined$1; + + // Only invoke if we have `lastArgs` which means `func` has been + // debounced at least once. + if (trailing && lastArgs) { + return invokeFunc(time); + } + lastArgs = lastThis = undefined$1; + return result; + } + + function cancel() { + if (timerId !== undefined$1) { + clearTimeout(timerId); + } + lastInvokeTime = 0; + lastArgs = lastCallTime = lastThis = timerId = undefined$1; + } + + function flush() { + return timerId === undefined$1 ? result : trailingEdge(now()); + } + + function debounced() { + var time = now(), + isInvoking = shouldInvoke(time); + + lastArgs = arguments; + lastThis = this; + lastCallTime = time; + + if (isInvoking) { + if (timerId === undefined$1) { + return leadingEdge(lastCallTime); + } + if (maxing) { + // Handle invocations in a tight loop. + clearTimeout(timerId); + timerId = setTimeout(timerExpired, wait); + return invokeFunc(lastCallTime); + } + } + if (timerId === undefined$1) { + timerId = setTimeout(timerExpired, wait); + } + return result; + } + debounced.cancel = cancel; + debounced.flush = flush; + return debounced; + } + + /** + * Defers invoking the `func` until the current call stack has cleared. Any + * additional arguments are provided to `func` when it's invoked. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to defer. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {number} Returns the timer id. + * @example + * + * _.defer(function(text) { + * console.log(text); + * }, 'deferred'); + * // => Logs 'deferred' after one millisecond. + */ + var defer = baseRest(function(func, args) { + return baseDelay(func, 1, args); + }); + + /** + * Invokes `func` after `wait` milliseconds. Any additional arguments are + * provided to `func` when it's invoked. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to delay. + * @param {number} wait The number of milliseconds to delay invocation. + * @param {...*} [args] The arguments to invoke `func` with. + * @returns {number} Returns the timer id. + * @example + * + * _.delay(function(text) { + * console.log(text); + * }, 1000, 'later'); + * // => Logs 'later' after one second. + */ + var delay = baseRest(function(func, wait, args) { + return baseDelay(func, toNumber(wait) || 0, args); + }); + + /** + * Creates a function that invokes `func` with arguments reversed. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to flip arguments for. + * @returns {Function} Returns the new flipped function. + * @example + * + * var flipped = _.flip(function() { + * return _.toArray(arguments); + * }); + * + * flipped('a', 'b', 'c', 'd'); + * // => ['d', 'c', 'b', 'a'] + */ + function flip(func) { + return createWrap(func, WRAP_FLIP_FLAG); + } + + /** + * Creates a function that memoizes the result of `func`. If `resolver` is + * provided, it determines the cache key for storing the result based on the + * arguments provided to the memoized function. By default, the first argument + * provided to the memoized function is used as the map cache key. The `func` + * is invoked with the `this` binding of the memoized function. + * + * **Note:** The cache is exposed as the `cache` property on the memoized + * function. Its creation may be customized by replacing the `_.memoize.Cache` + * constructor with one whose instances implement the + * [`Map`](http://ecma-international.org/ecma-262/7.0/#sec-properties-of-the-map-prototype-object) + * method interface of `clear`, `delete`, `get`, `has`, and `set`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to have its output memoized. + * @param {Function} [resolver] The function to resolve the cache key. + * @returns {Function} Returns the new memoized function. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * var other = { 'c': 3, 'd': 4 }; + * + * var values = _.memoize(_.values); + * values(object); + * // => [1, 2] + * + * values(other); + * // => [3, 4] + * + * object.a = 2; + * values(object); + * // => [1, 2] + * + * // Modify the result cache. + * values.cache.set(object, ['a', 'b']); + * values(object); + * // => ['a', 'b'] + * + * // Replace `_.memoize.Cache`. + * _.memoize.Cache = WeakMap; + */ + function memoize(func, resolver) { + if (typeof func != 'function' || (resolver != null && typeof resolver != 'function')) { + throw new TypeError(FUNC_ERROR_TEXT); + } + var memoized = function() { + var args = arguments, + key = resolver ? resolver.apply(this, args) : args[0], + cache = memoized.cache; + + if (cache.has(key)) { + return cache.get(key); + } + var result = func.apply(this, args); + memoized.cache = cache.set(key, result) || cache; + return result; + }; + memoized.cache = new (memoize.Cache || MapCache); + return memoized; + } + + // Expose `MapCache`. + memoize.Cache = MapCache; + + /** + * Creates a function that negates the result of the predicate `func`. The + * `func` predicate is invoked with the `this` binding and arguments of the + * created function. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} predicate The predicate to negate. + * @returns {Function} Returns the new negated function. + * @example + * + * function isEven(n) { + * return n % 2 == 0; + * } + * + * _.filter([1, 2, 3, 4, 5, 6], _.negate(isEven)); + * // => [1, 3, 5] + */ + function negate(predicate) { + if (typeof predicate != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + return function() { + var args = arguments; + switch (args.length) { + case 0: return !predicate.call(this); + case 1: return !predicate.call(this, args[0]); + case 2: return !predicate.call(this, args[0], args[1]); + case 3: return !predicate.call(this, args[0], args[1], args[2]); + } + return !predicate.apply(this, args); + }; + } + + /** + * Creates a function that is restricted to invoking `func` once. Repeat calls + * to the function return the value of the first invocation. The `func` is + * invoked with the `this` binding and arguments of the created function. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to restrict. + * @returns {Function} Returns the new restricted function. + * @example + * + * var initialize = _.once(createApplication); + * initialize(); + * initialize(); + * // => `createApplication` is invoked once + */ + function once(func) { + return before(2, func); + } + + /** + * Creates a function that invokes `func` with its arguments transformed. + * + * @static + * @since 4.0.0 + * @memberOf _ + * @category Function + * @param {Function} func The function to wrap. + * @param {...(Function|Function[])} [transforms=[_.identity]] + * The argument transforms. + * @returns {Function} Returns the new function. + * @example + * + * function doubled(n) { + * return n * 2; + * } + * + * function square(n) { + * return n * n; + * } + * + * var func = _.overArgs(function(x, y) { + * return [x, y]; + * }, [square, doubled]); + * + * func(9, 3); + * // => [81, 6] + * + * func(10, 5); + * // => [100, 10] + */ + var overArgs = castRest(function(func, transforms) { + transforms = (transforms.length == 1 && isArray(transforms[0])) + ? arrayMap(transforms[0], baseUnary(getIteratee())) + : arrayMap(baseFlatten(transforms, 1), baseUnary(getIteratee())); + + var funcsLength = transforms.length; + return baseRest(function(args) { + var index = -1, + length = nativeMin(args.length, funcsLength); + + while (++index < length) { + args[index] = transforms[index].call(this, args[index]); + } + return apply(func, this, args); + }); + }); + + /** + * Creates a function that invokes `func` with `partials` prepended to the + * arguments it receives. This method is like `_.bind` except it does **not** + * alter the `this` binding. + * + * The `_.partial.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for partially applied arguments. + * + * **Note:** This method doesn't set the "length" property of partially + * applied functions. + * + * @static + * @memberOf _ + * @since 0.2.0 + * @category Function + * @param {Function} func The function to partially apply arguments to. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new partially applied function. + * @example + * + * function greet(greeting, name) { + * return greeting + ' ' + name; + * } + * + * var sayHelloTo = _.partial(greet, 'hello'); + * sayHelloTo('fred'); + * // => 'hello fred' + * + * // Partially applied with placeholders. + * var greetFred = _.partial(greet, _, 'fred'); + * greetFred('hi'); + * // => 'hi fred' + */ + var partial = baseRest(function(func, partials) { + var holders = replaceHolders(partials, getHolder(partial)); + return createWrap(func, WRAP_PARTIAL_FLAG, undefined$1, partials, holders); + }); + + /** + * This method is like `_.partial` except that partially applied arguments + * are appended to the arguments it receives. + * + * The `_.partialRight.placeholder` value, which defaults to `_` in monolithic + * builds, may be used as a placeholder for partially applied arguments. + * + * **Note:** This method doesn't set the "length" property of partially + * applied functions. + * + * @static + * @memberOf _ + * @since 1.0.0 + * @category Function + * @param {Function} func The function to partially apply arguments to. + * @param {...*} [partials] The arguments to be partially applied. + * @returns {Function} Returns the new partially applied function. + * @example + * + * function greet(greeting, name) { + * return greeting + ' ' + name; + * } + * + * var greetFred = _.partialRight(greet, 'fred'); + * greetFred('hi'); + * // => 'hi fred' + * + * // Partially applied with placeholders. + * var sayHelloTo = _.partialRight(greet, 'hello', _); + * sayHelloTo('fred'); + * // => 'hello fred' + */ + var partialRight = baseRest(function(func, partials) { + var holders = replaceHolders(partials, getHolder(partialRight)); + return createWrap(func, WRAP_PARTIAL_RIGHT_FLAG, undefined$1, partials, holders); + }); + + /** + * Creates a function that invokes `func` with arguments arranged according + * to the specified `indexes` where the argument value at the first index is + * provided as the first argument, the argument value at the second index is + * provided as the second argument, and so on. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Function + * @param {Function} func The function to rearrange arguments for. + * @param {...(number|number[])} indexes The arranged argument indexes. + * @returns {Function} Returns the new function. + * @example + * + * var rearged = _.rearg(function(a, b, c) { + * return [a, b, c]; + * }, [2, 0, 1]); + * + * rearged('b', 'c', 'a') + * // => ['a', 'b', 'c'] + */ + var rearg = flatRest(function(func, indexes) { + return createWrap(func, WRAP_REARG_FLAG, undefined$1, undefined$1, undefined$1, indexes); + }); + + /** + * Creates a function that invokes `func` with the `this` binding of the + * created function and arguments from `start` and beyond provided as + * an array. + * + * **Note:** This method is based on the + * [rest parameter](https://mdn.io/rest_parameters). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to apply a rest parameter to. + * @param {number} [start=func.length-1] The start position of the rest parameter. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.rest(function(what, names) { + * return what + ' ' + _.initial(names).join(', ') + + * (_.size(names) > 1 ? ', & ' : '') + _.last(names); + * }); + * + * say('hello', 'fred', 'barney', 'pebbles'); + * // => 'hello fred, barney, & pebbles' + */ + function rest(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = start === undefined$1 ? start : toInteger(start); + return baseRest(func, start); + } + + /** + * Creates a function that invokes `func` with the `this` binding of the + * create function and an array of arguments much like + * [`Function#apply`](http://www.ecma-international.org/ecma-262/7.0/#sec-function.prototype.apply). + * + * **Note:** This method is based on the + * [spread operator](https://mdn.io/spread_operator). + * + * @static + * @memberOf _ + * @since 3.2.0 + * @category Function + * @param {Function} func The function to spread arguments over. + * @param {number} [start=0] The start position of the spread. + * @returns {Function} Returns the new function. + * @example + * + * var say = _.spread(function(who, what) { + * return who + ' says ' + what; + * }); + * + * say(['fred', 'hello']); + * // => 'fred says hello' + * + * var numbers = Promise.all([ + * Promise.resolve(40), + * Promise.resolve(36) + * ]); + * + * numbers.then(_.spread(function(x, y) { + * return x + y; + * })); + * // => a Promise of 76 + */ + function spread(func, start) { + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + start = start == null ? 0 : nativeMax(toInteger(start), 0); + return baseRest(function(args) { + var array = args[start], + otherArgs = castSlice(args, 0, start); + + if (array) { + arrayPush(otherArgs, array); + } + return apply(func, this, otherArgs); + }); + } + + /** + * Creates a throttled function that only invokes `func` at most once per + * every `wait` milliseconds. The throttled function comes with a `cancel` + * method to cancel delayed `func` invocations and a `flush` method to + * immediately invoke them. Provide `options` to indicate whether `func` + * should be invoked on the leading and/or trailing edge of the `wait` + * timeout. The `func` is invoked with the last arguments provided to the + * throttled function. Subsequent calls to the throttled function return the + * result of the last `func` invocation. + * + * **Note:** If `leading` and `trailing` options are `true`, `func` is + * invoked on the trailing edge of the timeout only if the throttled function + * is invoked more than once during the `wait` timeout. + * + * If `wait` is `0` and `leading` is `false`, `func` invocation is deferred + * until to the next tick, similar to `setTimeout` with a timeout of `0`. + * + * See [David Corbacho's article](https://css-tricks.com/debouncing-throttling-explained-examples/) + * for details over the differences between `_.throttle` and `_.debounce`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {Function} func The function to throttle. + * @param {number} [wait=0] The number of milliseconds to throttle invocations to. + * @param {Object} [options={}] The options object. + * @param {boolean} [options.leading=true] + * Specify invoking on the leading edge of the timeout. + * @param {boolean} [options.trailing=true] + * Specify invoking on the trailing edge of the timeout. + * @returns {Function} Returns the new throttled function. + * @example + * + * // Avoid excessively updating the position while scrolling. + * jQuery(window).on('scroll', _.throttle(updatePosition, 100)); + * + * // Invoke `renewToken` when the click event is fired, but not more than once every 5 minutes. + * var throttled = _.throttle(renewToken, 300000, { 'trailing': false }); + * jQuery(element).on('click', throttled); + * + * // Cancel the trailing throttled invocation. + * jQuery(window).on('popstate', throttled.cancel); + */ + function throttle(func, wait, options) { + var leading = true, + trailing = true; + + if (typeof func != 'function') { + throw new TypeError(FUNC_ERROR_TEXT); + } + if (isObject(options)) { + leading = 'leading' in options ? !!options.leading : leading; + trailing = 'trailing' in options ? !!options.trailing : trailing; + } + return debounce(func, wait, { + 'leading': leading, + 'maxWait': wait, + 'trailing': trailing + }); + } + + /** + * Creates a function that accepts up to one argument, ignoring any + * additional arguments. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Function + * @param {Function} func The function to cap arguments for. + * @returns {Function} Returns the new capped function. + * @example + * + * _.map(['6', '8', '10'], _.unary(parseInt)); + * // => [6, 8, 10] + */ + function unary(func) { + return ary(func, 1); + } + + /** + * Creates a function that provides `value` to `wrapper` as its first + * argument. Any additional arguments provided to the function are appended + * to those provided to the `wrapper`. The wrapper is invoked with the `this` + * binding of the created function. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Function + * @param {*} value The value to wrap. + * @param {Function} [wrapper=identity] The wrapper function. + * @returns {Function} Returns the new function. + * @example + * + * var p = _.wrap(_.escape, function(func, text) { + * return '

' + func(text) + '

'; + * }); + * + * p('fred, barney, & pebbles'); + * // => '

fred, barney, & pebbles

' + */ + function wrap(value, wrapper) { + return partial(castFunction(wrapper), value); + } + + /*------------------------------------------------------------------------*/ + + /** + * Casts `value` as an array if it's not one. + * + * @static + * @memberOf _ + * @since 4.4.0 + * @category Lang + * @param {*} value The value to inspect. + * @returns {Array} Returns the cast array. + * @example + * + * _.castArray(1); + * // => [1] + * + * _.castArray({ 'a': 1 }); + * // => [{ 'a': 1 }] + * + * _.castArray('abc'); + * // => ['abc'] + * + * _.castArray(null); + * // => [null] + * + * _.castArray(undefined); + * // => [undefined] + * + * _.castArray(); + * // => [] + * + * var array = [1, 2, 3]; + * console.log(_.castArray(array) === array); + * // => true + */ + function castArray() { + if (!arguments.length) { + return []; + } + var value = arguments[0]; + return isArray(value) ? value : [value]; + } + + /** + * Creates a shallow clone of `value`. + * + * **Note:** This method is loosely based on the + * [structured clone algorithm](https://mdn.io/Structured_clone_algorithm) + * and supports cloning arrays, array buffers, booleans, date objects, maps, + * numbers, `Object` objects, regexes, sets, strings, symbols, and typed + * arrays. The own enumerable properties of `arguments` objects are cloned + * as plain objects. An empty object is returned for uncloneable values such + * as error objects, functions, DOM nodes, and WeakMaps. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to clone. + * @returns {*} Returns the cloned value. + * @see _.cloneDeep + * @example + * + * var objects = [{ 'a': 1 }, { 'b': 2 }]; + * + * var shallow = _.clone(objects); + * console.log(shallow[0] === objects[0]); + * // => true + */ + function clone(value) { + return baseClone(value, CLONE_SYMBOLS_FLAG); + } + + /** + * This method is like `_.clone` except that it accepts `customizer` which + * is invoked to produce the cloned value. If `customizer` returns `undefined`, + * cloning is handled by the method instead. The `customizer` is invoked with + * up to four arguments; (value [, index|key, object, stack]). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to clone. + * @param {Function} [customizer] The function to customize cloning. + * @returns {*} Returns the cloned value. + * @see _.cloneDeepWith + * @example + * + * function customizer(value) { + * if (_.isElement(value)) { + * return value.cloneNode(false); + * } + * } + * + * var el = _.cloneWith(document.body, customizer); + * + * console.log(el === document.body); + * // => false + * console.log(el.nodeName); + * // => 'BODY' + * console.log(el.childNodes.length); + * // => 0 + */ + function cloneWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined$1; + return baseClone(value, CLONE_SYMBOLS_FLAG, customizer); + } + + /** + * This method is like `_.clone` except that it recursively clones `value`. + * + * @static + * @memberOf _ + * @since 1.0.0 + * @category Lang + * @param {*} value The value to recursively clone. + * @returns {*} Returns the deep cloned value. + * @see _.clone + * @example + * + * var objects = [{ 'a': 1 }, { 'b': 2 }]; + * + * var deep = _.cloneDeep(objects); + * console.log(deep[0] === objects[0]); + * // => false + */ + function cloneDeep(value) { + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG); + } + + /** + * This method is like `_.cloneWith` except that it recursively clones `value`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to recursively clone. + * @param {Function} [customizer] The function to customize cloning. + * @returns {*} Returns the deep cloned value. + * @see _.cloneWith + * @example + * + * function customizer(value) { + * if (_.isElement(value)) { + * return value.cloneNode(true); + * } + * } + * + * var el = _.cloneDeepWith(document.body, customizer); + * + * console.log(el === document.body); + * // => false + * console.log(el.nodeName); + * // => 'BODY' + * console.log(el.childNodes.length); + * // => 20 + */ + function cloneDeepWith(value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined$1; + return baseClone(value, CLONE_DEEP_FLAG | CLONE_SYMBOLS_FLAG, customizer); + } + + /** + * Checks if `object` conforms to `source` by invoking the predicate + * properties of `source` with the corresponding property values of `object`. + * + * **Note:** This method is equivalent to `_.conforms` when `source` is + * partially applied. + * + * @static + * @memberOf _ + * @since 4.14.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property predicates to conform to. + * @returns {boolean} Returns `true` if `object` conforms, else `false`. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * + * _.conformsTo(object, { 'b': function(n) { return n > 1; } }); + * // => true + * + * _.conformsTo(object, { 'b': function(n) { return n > 2; } }); + * // => false + */ + function conformsTo(object, source) { + return source == null || baseConformsTo(object, source, keys(source)); + } + + /** + * Performs a + * [`SameValueZero`](http://ecma-international.org/ecma-262/7.0/#sec-samevaluezero) + * comparison between two values to determine if they are equivalent. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; + * + * _.eq(object, object); + * // => true + * + * _.eq(object, other); + * // => false + * + * _.eq('a', 'a'); + * // => true + * + * _.eq('a', Object('a')); + * // => false + * + * _.eq(NaN, NaN); + * // => true + */ + function eq(value, other) { + return value === other || (value !== value && other !== other); + } + + /** + * Checks if `value` is greater than `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than `other`, + * else `false`. + * @see _.lt + * @example + * + * _.gt(3, 1); + * // => true + * + * _.gt(3, 3); + * // => false + * + * _.gt(1, 3); + * // => false + */ + var gt = createRelationalOperation(baseGt); + + /** + * Checks if `value` is greater than or equal to `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is greater than or equal to + * `other`, else `false`. + * @see _.lte + * @example + * + * _.gte(3, 1); + * // => true + * + * _.gte(3, 3); + * // => true + * + * _.gte(1, 3); + * // => false + */ + var gte = createRelationalOperation(function(value, other) { + return value >= other; + }); + + /** + * Checks if `value` is likely an `arguments` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an `arguments` object, + * else `false`. + * @example + * + * _.isArguments(function() { return arguments; }()); + * // => true + * + * _.isArguments([1, 2, 3]); + * // => false + */ + var isArguments = baseIsArguments(function() { return arguments; }()) ? baseIsArguments : function(value) { + return isObjectLike(value) && hasOwnProperty.call(value, 'callee') && + !propertyIsEnumerable.call(value, 'callee'); + }; + + /** + * Checks if `value` is classified as an `Array` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array, else `false`. + * @example + * + * _.isArray([1, 2, 3]); + * // => true + * + * _.isArray(document.body.children); + * // => false + * + * _.isArray('abc'); + * // => false + * + * _.isArray(_.noop); + * // => false + */ + var isArray = Array.isArray; + + /** + * Checks if `value` is classified as an `ArrayBuffer` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array buffer, else `false`. + * @example + * + * _.isArrayBuffer(new ArrayBuffer(2)); + * // => true + * + * _.isArrayBuffer(new Array(2)); + * // => false + */ + var isArrayBuffer = nodeIsArrayBuffer ? baseUnary(nodeIsArrayBuffer) : baseIsArrayBuffer; + + /** + * Checks if `value` is array-like. A value is considered array-like if it's + * not a function and has a `value.length` that's an integer greater than or + * equal to `0` and less than or equal to `Number.MAX_SAFE_INTEGER`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is array-like, else `false`. + * @example + * + * _.isArrayLike([1, 2, 3]); + * // => true + * + * _.isArrayLike(document.body.children); + * // => true + * + * _.isArrayLike('abc'); + * // => true + * + * _.isArrayLike(_.noop); + * // => false + */ + function isArrayLike(value) { + return value != null && isLength(value.length) && !isFunction(value); + } + + /** + * This method is like `_.isArrayLike` except that it also checks if `value` + * is an object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an array-like object, + * else `false`. + * @example + * + * _.isArrayLikeObject([1, 2, 3]); + * // => true + * + * _.isArrayLikeObject(document.body.children); + * // => true + * + * _.isArrayLikeObject('abc'); + * // => false + * + * _.isArrayLikeObject(_.noop); + * // => false + */ + function isArrayLikeObject(value) { + return isObjectLike(value) && isArrayLike(value); + } + + /** + * Checks if `value` is classified as a boolean primitive or object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a boolean, else `false`. + * @example + * + * _.isBoolean(false); + * // => true + * + * _.isBoolean(null); + * // => false + */ + function isBoolean(value) { + return value === true || value === false || + (isObjectLike(value) && baseGetTag(value) == boolTag); + } + + /** + * Checks if `value` is a buffer. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a buffer, else `false`. + * @example + * + * _.isBuffer(new Buffer(2)); + * // => true + * + * _.isBuffer(new Uint8Array(2)); + * // => false + */ + var isBuffer = nativeIsBuffer || stubFalse; + + /** + * Checks if `value` is classified as a `Date` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a date object, else `false`. + * @example + * + * _.isDate(new Date); + * // => true + * + * _.isDate('Mon April 23 2012'); + * // => false + */ + var isDate = nodeIsDate ? baseUnary(nodeIsDate) : baseIsDate; + + /** + * Checks if `value` is likely a DOM element. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a DOM element, else `false`. + * @example + * + * _.isElement(document.body); + * // => true + * + * _.isElement(''); + * // => false + */ + function isElement(value) { + return isObjectLike(value) && value.nodeType === 1 && !isPlainObject(value); + } + + /** + * Checks if `value` is an empty object, collection, map, or set. + * + * Objects are considered empty if they have no own enumerable string keyed + * properties. + * + * Array-like values such as `arguments` objects, arrays, buffers, strings, or + * jQuery-like collections are considered empty if they have a `length` of `0`. + * Similarly, maps and sets are considered empty if they have a `size` of `0`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is empty, else `false`. + * @example + * + * _.isEmpty(null); + * // => true + * + * _.isEmpty(true); + * // => true + * + * _.isEmpty(1); + * // => true + * + * _.isEmpty([1, 2, 3]); + * // => false + * + * _.isEmpty({ 'a': 1 }); + * // => false + */ + function isEmpty(value) { + if (value == null) { + return true; + } + if (isArrayLike(value) && + (isArray(value) || typeof value == 'string' || typeof value.splice == 'function' || + isBuffer(value) || isTypedArray(value) || isArguments(value))) { + return !value.length; + } + var tag = getTag(value); + if (tag == mapTag || tag == setTag) { + return !value.size; + } + if (isPrototype(value)) { + return !baseKeys(value).length; + } + for (var key in value) { + if (hasOwnProperty.call(value, key)) { + return false; + } + } + return true; + } + + /** + * Performs a deep comparison between two values to determine if they are + * equivalent. + * + * **Note:** This method supports comparing arrays, array buffers, booleans, + * date objects, error objects, maps, numbers, `Object` objects, regexes, + * sets, strings, symbols, and typed arrays. `Object` objects are compared + * by their own, not inherited, enumerable properties. Functions and DOM + * nodes are compared by strict equality, i.e. `===`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * var object = { 'a': 1 }; + * var other = { 'a': 1 }; + * + * _.isEqual(object, other); + * // => true + * + * object === other; + * // => false + */ + function isEqual(value, other) { + return baseIsEqual(value, other); + } + + /** + * This method is like `_.isEqual` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined`, comparisons + * are handled by the method instead. The `customizer` is invoked with up to + * six arguments: (objValue, othValue [, index|key, object, other, stack]). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if the values are equivalent, else `false`. + * @example + * + * function isGreeting(value) { + * return /^h(?:i|ello)$/.test(value); + * } + * + * function customizer(objValue, othValue) { + * if (isGreeting(objValue) && isGreeting(othValue)) { + * return true; + * } + * } + * + * var array = ['hello', 'goodbye']; + * var other = ['hi', 'goodbye']; + * + * _.isEqualWith(array, other, customizer); + * // => true + */ + function isEqualWith(value, other, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined$1; + var result = customizer ? customizer(value, other) : undefined$1; + return result === undefined$1 ? baseIsEqual(value, other, undefined$1, customizer) : !!result; + } + + /** + * Checks if `value` is an `Error`, `EvalError`, `RangeError`, `ReferenceError`, + * `SyntaxError`, `TypeError`, or `URIError` object. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an error object, else `false`. + * @example + * + * _.isError(new Error); + * // => true + * + * _.isError(Error); + * // => false + */ + function isError(value) { + if (!isObjectLike(value)) { + return false; + } + var tag = baseGetTag(value); + return tag == errorTag || tag == domExcTag || + (typeof value.message == 'string' && typeof value.name == 'string' && !isPlainObject(value)); + } + + /** + * Checks if `value` is a finite primitive number. + * + * **Note:** This method is based on + * [`Number.isFinite`](https://mdn.io/Number/isFinite). + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a finite number, else `false`. + * @example + * + * _.isFinite(3); + * // => true + * + * _.isFinite(Number.MIN_VALUE); + * // => true + * + * _.isFinite(Infinity); + * // => false + * + * _.isFinite('3'); + * // => false + */ + function isFinite(value) { + return typeof value == 'number' && nativeIsFinite(value); + } + + /** + * Checks if `value` is classified as a `Function` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a function, else `false`. + * @example + * + * _.isFunction(_); + * // => true + * + * _.isFunction(/abc/); + * // => false + */ + function isFunction(value) { + if (!isObject(value)) { + return false; + } + // The use of `Object#toString` avoids issues with the `typeof` operator + // in Safari 9 which returns 'object' for typed arrays and other constructors. + var tag = baseGetTag(value); + return tag == funcTag || tag == genTag || tag == asyncTag || tag == proxyTag; + } + + /** + * Checks if `value` is an integer. + * + * **Note:** This method is based on + * [`Number.isInteger`](https://mdn.io/Number/isInteger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an integer, else `false`. + * @example + * + * _.isInteger(3); + * // => true + * + * _.isInteger(Number.MIN_VALUE); + * // => false + * + * _.isInteger(Infinity); + * // => false + * + * _.isInteger('3'); + * // => false + */ + function isInteger(value) { + return typeof value == 'number' && value == toInteger(value); + } + + /** + * Checks if `value` is a valid array-like length. + * + * **Note:** This method is loosely based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a valid length, else `false`. + * @example + * + * _.isLength(3); + * // => true + * + * _.isLength(Number.MIN_VALUE); + * // => false + * + * _.isLength(Infinity); + * // => false + * + * _.isLength('3'); + * // => false + */ + function isLength(value) { + return typeof value == 'number' && + value > -1 && value % 1 == 0 && value <= MAX_SAFE_INTEGER; + } + + /** + * Checks if `value` is the + * [language type](http://www.ecma-international.org/ecma-262/7.0/#sec-ecmascript-language-types) + * of `Object`. (e.g. arrays, functions, objects, regexes, `new Number(0)`, and `new String('')`) + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is an object, else `false`. + * @example + * + * _.isObject({}); + * // => true + * + * _.isObject([1, 2, 3]); + * // => true + * + * _.isObject(_.noop); + * // => true + * + * _.isObject(null); + * // => false + */ + function isObject(value) { + var type = typeof value; + return value != null && (type == 'object' || type == 'function'); + } + + /** + * Checks if `value` is object-like. A value is object-like if it's not `null` + * and has a `typeof` result of "object". + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is object-like, else `false`. + * @example + * + * _.isObjectLike({}); + * // => true + * + * _.isObjectLike([1, 2, 3]); + * // => true + * + * _.isObjectLike(_.noop); + * // => false + * + * _.isObjectLike(null); + * // => false + */ + function isObjectLike(value) { + return value != null && typeof value == 'object'; + } + + /** + * Checks if `value` is classified as a `Map` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a map, else `false`. + * @example + * + * _.isMap(new Map); + * // => true + * + * _.isMap(new WeakMap); + * // => false + */ + var isMap = nodeIsMap ? baseUnary(nodeIsMap) : baseIsMap; + + /** + * Performs a partial deep comparison between `object` and `source` to + * determine if `object` contains equivalent property values. + * + * **Note:** This method is equivalent to `_.matches` when `source` is + * partially applied. + * + * Partial comparisons will match empty array and empty object `source` + * values against any array or object value, respectively. See `_.isEqual` + * for a list of supported value comparisons. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + * @example + * + * var object = { 'a': 1, 'b': 2 }; + * + * _.isMatch(object, { 'b': 2 }); + * // => true + * + * _.isMatch(object, { 'b': 1 }); + * // => false + */ + function isMatch(object, source) { + return object === source || baseIsMatch(object, source, getMatchData(source)); + } + + /** + * This method is like `_.isMatch` except that it accepts `customizer` which + * is invoked to compare values. If `customizer` returns `undefined`, comparisons + * are handled by the method instead. The `customizer` is invoked with five + * arguments: (objValue, srcValue, index|key, object, source). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {Object} object The object to inspect. + * @param {Object} source The object of property values to match. + * @param {Function} [customizer] The function to customize comparisons. + * @returns {boolean} Returns `true` if `object` is a match, else `false`. + * @example + * + * function isGreeting(value) { + * return /^h(?:i|ello)$/.test(value); + * } + * + * function customizer(objValue, srcValue) { + * if (isGreeting(objValue) && isGreeting(srcValue)) { + * return true; + * } + * } + * + * var object = { 'greeting': 'hello' }; + * var source = { 'greeting': 'hi' }; + * + * _.isMatchWith(object, source, customizer); + * // => true + */ + function isMatchWith(object, source, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined$1; + return baseIsMatch(object, source, getMatchData(source), customizer); + } + + /** + * Checks if `value` is `NaN`. + * + * **Note:** This method is based on + * [`Number.isNaN`](https://mdn.io/Number/isNaN) and is not the same as + * global [`isNaN`](https://mdn.io/isNaN) which returns `true` for + * `undefined` and other non-number values. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `NaN`, else `false`. + * @example + * + * _.isNaN(NaN); + * // => true + * + * _.isNaN(new Number(NaN)); + * // => true + * + * isNaN(undefined); + * // => true + * + * _.isNaN(undefined); + * // => false + */ + function isNaN(value) { + // An `NaN` primitive is the only value that is not equal to itself. + // Perform the `toStringTag` check first to avoid errors with some + // ActiveX objects in IE. + return isNumber(value) && value != +value; + } + + /** + * Checks if `value` is a pristine native function. + * + * **Note:** This method can't reliably detect native functions in the presence + * of the core-js package because core-js circumvents this kind of detection. + * Despite multiple requests, the core-js maintainer has made it clear: any + * attempt to fix the detection will be obstructed. As a result, we're left + * with little choice but to throw an error. Unfortunately, this also affects + * packages, like [babel-polyfill](https://www.npmjs.com/package/babel-polyfill), + * which rely on core-js. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a native function, + * else `false`. + * @example + * + * _.isNative(Array.prototype.push); + * // => true + * + * _.isNative(_); + * // => false + */ + function isNative(value) { + if (isMaskable(value)) { + throw new Error(CORE_ERROR_TEXT); + } + return baseIsNative(value); + } + + /** + * Checks if `value` is `null`. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `null`, else `false`. + * @example + * + * _.isNull(null); + * // => true + * + * _.isNull(void 0); + * // => false + */ + function isNull(value) { + return value === null; + } + + /** + * Checks if `value` is `null` or `undefined`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is nullish, else `false`. + * @example + * + * _.isNil(null); + * // => true + * + * _.isNil(void 0); + * // => true + * + * _.isNil(NaN); + * // => false + */ + function isNil(value) { + return value == null; + } + + /** + * Checks if `value` is classified as a `Number` primitive or object. + * + * **Note:** To exclude `Infinity`, `-Infinity`, and `NaN`, which are + * classified as numbers, use the `_.isFinite` method. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a number, else `false`. + * @example + * + * _.isNumber(3); + * // => true + * + * _.isNumber(Number.MIN_VALUE); + * // => true + * + * _.isNumber(Infinity); + * // => true + * + * _.isNumber('3'); + * // => false + */ + function isNumber(value) { + return typeof value == 'number' || + (isObjectLike(value) && baseGetTag(value) == numberTag); + } + + /** + * Checks if `value` is a plain object, that is, an object created by the + * `Object` constructor or one with a `[[Prototype]]` of `null`. + * + * @static + * @memberOf _ + * @since 0.8.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a plain object, else `false`. + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * _.isPlainObject(new Foo); + * // => false + * + * _.isPlainObject([1, 2, 3]); + * // => false + * + * _.isPlainObject({ 'x': 0, 'y': 0 }); + * // => true + * + * _.isPlainObject(Object.create(null)); + * // => true + */ + function isPlainObject(value) { + if (!isObjectLike(value) || baseGetTag(value) != objectTag) { + return false; + } + var proto = getPrototype(value); + if (proto === null) { + return true; + } + var Ctor = hasOwnProperty.call(proto, 'constructor') && proto.constructor; + return typeof Ctor == 'function' && Ctor instanceof Ctor && + funcToString.call(Ctor) == objectCtorString; + } + + /** + * Checks if `value` is classified as a `RegExp` object. + * + * @static + * @memberOf _ + * @since 0.1.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a regexp, else `false`. + * @example + * + * _.isRegExp(/abc/); + * // => true + * + * _.isRegExp('/abc/'); + * // => false + */ + var isRegExp = nodeIsRegExp ? baseUnary(nodeIsRegExp) : baseIsRegExp; + + /** + * Checks if `value` is a safe integer. An integer is safe if it's an IEEE-754 + * double precision number which isn't the result of a rounded unsafe integer. + * + * **Note:** This method is based on + * [`Number.isSafeInteger`](https://mdn.io/Number/isSafeInteger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a safe integer, else `false`. + * @example + * + * _.isSafeInteger(3); + * // => true + * + * _.isSafeInteger(Number.MIN_VALUE); + * // => false + * + * _.isSafeInteger(Infinity); + * // => false + * + * _.isSafeInteger('3'); + * // => false + */ + function isSafeInteger(value) { + return isInteger(value) && value >= -MAX_SAFE_INTEGER && value <= MAX_SAFE_INTEGER; + } + + /** + * Checks if `value` is classified as a `Set` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a set, else `false`. + * @example + * + * _.isSet(new Set); + * // => true + * + * _.isSet(new WeakSet); + * // => false + */ + var isSet = nodeIsSet ? baseUnary(nodeIsSet) : baseIsSet; + + /** + * Checks if `value` is classified as a `String` primitive or object. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a string, else `false`. + * @example + * + * _.isString('abc'); + * // => true + * + * _.isString(1); + * // => false + */ + function isString(value) { + return typeof value == 'string' || + (!isArray(value) && isObjectLike(value) && baseGetTag(value) == stringTag); + } + + /** + * Checks if `value` is classified as a `Symbol` primitive or object. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a symbol, else `false`. + * @example + * + * _.isSymbol(Symbol.iterator); + * // => true + * + * _.isSymbol('abc'); + * // => false + */ + function isSymbol(value) { + return typeof value == 'symbol' || + (isObjectLike(value) && baseGetTag(value) == symbolTag); + } + + /** + * Checks if `value` is classified as a typed array. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a typed array, else `false`. + * @example + * + * _.isTypedArray(new Uint8Array); + * // => true + * + * _.isTypedArray([]); + * // => false + */ + var isTypedArray = nodeIsTypedArray ? baseUnary(nodeIsTypedArray) : baseIsTypedArray; + + /** + * Checks if `value` is `undefined`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is `undefined`, else `false`. + * @example + * + * _.isUndefined(void 0); + * // => true + * + * _.isUndefined(null); + * // => false + */ + function isUndefined(value) { + return value === undefined$1; + } + + /** + * Checks if `value` is classified as a `WeakMap` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a weak map, else `false`. + * @example + * + * _.isWeakMap(new WeakMap); + * // => true + * + * _.isWeakMap(new Map); + * // => false + */ + function isWeakMap(value) { + return isObjectLike(value) && getTag(value) == weakMapTag; + } + + /** + * Checks if `value` is classified as a `WeakSet` object. + * + * @static + * @memberOf _ + * @since 4.3.0 + * @category Lang + * @param {*} value The value to check. + * @returns {boolean} Returns `true` if `value` is a weak set, else `false`. + * @example + * + * _.isWeakSet(new WeakSet); + * // => true + * + * _.isWeakSet(new Set); + * // => false + */ + function isWeakSet(value) { + return isObjectLike(value) && baseGetTag(value) == weakSetTag; + } + + /** + * Checks if `value` is less than `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than `other`, + * else `false`. + * @see _.gt + * @example + * + * _.lt(1, 3); + * // => true + * + * _.lt(3, 3); + * // => false + * + * _.lt(3, 1); + * // => false + */ + var lt = createRelationalOperation(baseLt); + + /** + * Checks if `value` is less than or equal to `other`. + * + * @static + * @memberOf _ + * @since 3.9.0 + * @category Lang + * @param {*} value The value to compare. + * @param {*} other The other value to compare. + * @returns {boolean} Returns `true` if `value` is less than or equal to + * `other`, else `false`. + * @see _.gte + * @example + * + * _.lte(1, 3); + * // => true + * + * _.lte(3, 3); + * // => true + * + * _.lte(3, 1); + * // => false + */ + var lte = createRelationalOperation(function(value, other) { + return value <= other; + }); + + /** + * Converts `value` to an array. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Lang + * @param {*} value The value to convert. + * @returns {Array} Returns the converted array. + * @example + * + * _.toArray({ 'a': 1, 'b': 2 }); + * // => [1, 2] + * + * _.toArray('abc'); + * // => ['a', 'b', 'c'] + * + * _.toArray(1); + * // => [] + * + * _.toArray(null); + * // => [] + */ + function toArray(value) { + if (!value) { + return []; + } + if (isArrayLike(value)) { + return isString(value) ? stringToArray(value) : copyArray(value); + } + if (symIterator && value[symIterator]) { + return iteratorToArray(value[symIterator]()); + } + var tag = getTag(value), + func = tag == mapTag ? mapToArray : (tag == setTag ? setToArray : values); + + return func(value); + } + + /** + * Converts `value` to a finite number. + * + * @static + * @memberOf _ + * @since 4.12.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted number. + * @example + * + * _.toFinite(3.2); + * // => 3.2 + * + * _.toFinite(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toFinite(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toFinite('3.2'); + * // => 3.2 + */ + function toFinite(value) { + if (!value) { + return value === 0 ? value : 0; + } + value = toNumber(value); + if (value === INFINITY || value === -INFINITY) { + var sign = (value < 0 ? -1 : 1); + return sign * MAX_INTEGER; + } + return value === value ? value : 0; + } + + /** + * Converts `value` to an integer. + * + * **Note:** This method is loosely based on + * [`ToInteger`](http://www.ecma-international.org/ecma-262/7.0/#sec-tointeger). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toInteger(3.2); + * // => 3 + * + * _.toInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toInteger(Infinity); + * // => 1.7976931348623157e+308 + * + * _.toInteger('3.2'); + * // => 3 + */ + function toInteger(value) { + var result = toFinite(value), + remainder = result % 1; + + return result === result ? (remainder ? result - remainder : result) : 0; + } + + /** + * Converts `value` to an integer suitable for use as the length of an + * array-like object. + * + * **Note:** This method is based on + * [`ToLength`](http://ecma-international.org/ecma-262/7.0/#sec-tolength). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toLength(3.2); + * // => 3 + * + * _.toLength(Number.MIN_VALUE); + * // => 0 + * + * _.toLength(Infinity); + * // => 4294967295 + * + * _.toLength('3.2'); + * // => 3 + */ + function toLength(value) { + return value ? baseClamp(toInteger(value), 0, MAX_ARRAY_LENGTH) : 0; + } + + /** + * Converts `value` to a number. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to process. + * @returns {number} Returns the number. + * @example + * + * _.toNumber(3.2); + * // => 3.2 + * + * _.toNumber(Number.MIN_VALUE); + * // => 5e-324 + * + * _.toNumber(Infinity); + * // => Infinity + * + * _.toNumber('3.2'); + * // => 3.2 + */ + function toNumber(value) { + if (typeof value == 'number') { + return value; + } + if (isSymbol(value)) { + return NAN; + } + if (isObject(value)) { + var other = typeof value.valueOf == 'function' ? value.valueOf() : value; + value = isObject(other) ? (other + '') : other; + } + if (typeof value != 'string') { + return value === 0 ? value : +value; + } + value = value.replace(reTrim, ''); + var isBinary = reIsBinary.test(value); + return (isBinary || reIsOctal.test(value)) + ? freeParseInt(value.slice(2), isBinary ? 2 : 8) + : (reIsBadHex.test(value) ? NAN : +value); + } + + /** + * Converts `value` to a plain object flattening inherited enumerable string + * keyed properties of `value` to own properties of the plain object. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {Object} Returns the converted plain object. + * @example + * + * function Foo() { + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.assign({ 'a': 1 }, new Foo); + * // => { 'a': 1, 'b': 2 } + * + * _.assign({ 'a': 1 }, _.toPlainObject(new Foo)); + * // => { 'a': 1, 'b': 2, 'c': 3 } + */ + function toPlainObject(value) { + return copyObject(value, keysIn(value)); + } + + /** + * Converts `value` to a safe integer. A safe integer can be compared and + * represented correctly. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {number} Returns the converted integer. + * @example + * + * _.toSafeInteger(3.2); + * // => 3 + * + * _.toSafeInteger(Number.MIN_VALUE); + * // => 0 + * + * _.toSafeInteger(Infinity); + * // => 9007199254740991 + * + * _.toSafeInteger('3.2'); + * // => 3 + */ + function toSafeInteger(value) { + return value + ? baseClamp(toInteger(value), -MAX_SAFE_INTEGER, MAX_SAFE_INTEGER) + : (value === 0 ? value : 0); + } + + /** + * Converts `value` to a string. An empty string is returned for `null` + * and `undefined` values. The sign of `-0` is preserved. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Lang + * @param {*} value The value to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.toString(null); + * // => '' + * + * _.toString(-0); + * // => '-0' + * + * _.toString([1, 2, 3]); + * // => '1,2,3' + */ + function toString(value) { + return value == null ? '' : baseToString(value); + } + + /*------------------------------------------------------------------------*/ + + /** + * Assigns own enumerable string keyed properties of source objects to the + * destination object. Source objects are applied from left to right. + * Subsequent sources overwrite property assignments of previous sources. + * + * **Note:** This method mutates `object` and is loosely based on + * [`Object.assign`](https://mdn.io/Object/assign). + * + * @static + * @memberOf _ + * @since 0.10.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.assignIn + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * function Bar() { + * this.c = 3; + * } + * + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; + * + * _.assign({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'c': 3 } + */ + var assign = createAssigner(function(object, source) { + if (isPrototype(source) || isArrayLike(source)) { + copyObject(source, keys(source), object); + return; + } + for (var key in source) { + if (hasOwnProperty.call(source, key)) { + assignValue(object, key, source[key]); + } + } + }); + + /** + * This method is like `_.assign` except that it iterates over own and + * inherited source properties. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias extend + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.assign + * @example + * + * function Foo() { + * this.a = 1; + * } + * + * function Bar() { + * this.c = 3; + * } + * + * Foo.prototype.b = 2; + * Bar.prototype.d = 4; + * + * _.assignIn({ 'a': 0 }, new Foo, new Bar); + * // => { 'a': 1, 'b': 2, 'c': 3, 'd': 4 } + */ + var assignIn = createAssigner(function(object, source) { + copyObject(source, keysIn(source), object); + }); + + /** + * This method is like `_.assignIn` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined`, assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias extendWith + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @see _.assignWith + * @example + * + * function customizer(objValue, srcValue) { + * return _.isUndefined(objValue) ? srcValue : objValue; + * } + * + * var defaults = _.partialRight(_.assignInWith, customizer); + * + * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } + */ + var assignInWith = createAssigner(function(object, source, srcIndex, customizer) { + copyObject(source, keysIn(source), object, customizer); + }); + + /** + * This method is like `_.assign` except that it accepts `customizer` + * which is invoked to produce the assigned values. If `customizer` returns + * `undefined`, assignment is handled by the method instead. The `customizer` + * is invoked with five arguments: (objValue, srcValue, key, object, source). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @see _.assignInWith + * @example + * + * function customizer(objValue, srcValue) { + * return _.isUndefined(objValue) ? srcValue : objValue; + * } + * + * var defaults = _.partialRight(_.assignWith, customizer); + * + * defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } + */ + var assignWith = createAssigner(function(object, source, srcIndex, customizer) { + copyObject(source, keys(source), object, customizer); + }); + + /** + * Creates an array of values corresponding to `paths` of `object`. + * + * @static + * @memberOf _ + * @since 1.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Array} Returns the picked values. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }, 4] }; + * + * _.at(object, ['a[0].b.c', 'a[1]']); + * // => [3, 4] + */ + var at = flatRest(baseAt); + + /** + * Creates an object that inherits from the `prototype` object. If a + * `properties` object is given, its own enumerable string keyed properties + * are assigned to the created object. + * + * @static + * @memberOf _ + * @since 2.3.0 + * @category Object + * @param {Object} prototype The object to inherit from. + * @param {Object} [properties] The properties to assign to the object. + * @returns {Object} Returns the new object. + * @example + * + * function Shape() { + * this.x = 0; + * this.y = 0; + * } + * + * function Circle() { + * Shape.call(this); + * } + * + * Circle.prototype = _.create(Shape.prototype, { + * 'constructor': Circle + * }); + * + * var circle = new Circle; + * circle instanceof Circle; + * // => true + * + * circle instanceof Shape; + * // => true + */ + function create(prototype, properties) { + var result = baseCreate(prototype); + return properties == null ? result : baseAssign(result, properties); + } + + /** + * Assigns own and inherited enumerable string keyed properties of source + * objects to the destination object for all destination properties that + * resolve to `undefined`. Source objects are applied from left to right. + * Once a property is set, additional values of the same property are ignored. + * + * **Note:** This method mutates `object`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.defaultsDeep + * @example + * + * _.defaults({ 'a': 1 }, { 'b': 2 }, { 'a': 3 }); + * // => { 'a': 1, 'b': 2 } + */ + var defaults = baseRest(function(object, sources) { + object = Object(object); + + var index = -1; + var length = sources.length; + var guard = length > 2 ? sources[2] : undefined$1; + + if (guard && isIterateeCall(sources[0], sources[1], guard)) { + length = 1; + } + + while (++index < length) { + var source = sources[index]; + var props = keysIn(source); + var propsIndex = -1; + var propsLength = props.length; + + while (++propsIndex < propsLength) { + var key = props[propsIndex]; + var value = object[key]; + + if (value === undefined$1 || + (eq(value, objectProto[key]) && !hasOwnProperty.call(object, key))) { + object[key] = source[key]; + } + } + } + + return object; + }); + + /** + * This method is like `_.defaults` except that it recursively assigns + * default properties. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 3.10.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @see _.defaults + * @example + * + * _.defaultsDeep({ 'a': { 'b': 2 } }, { 'a': { 'b': 1, 'c': 3 } }); + * // => { 'a': { 'b': 2, 'c': 3 } } + */ + var defaultsDeep = baseRest(function(args) { + args.push(undefined$1, customDefaultsMerge); + return apply(mergeWith, undefined$1, args); + }); + + /** + * This method is like `_.find` except that it returns the key of the first + * element `predicate` returns truthy for instead of the element itself. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category Object + * @param {Object} object The object to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. + * @example + * + * var users = { + * 'barney': { 'age': 36, 'active': true }, + * 'fred': { 'age': 40, 'active': false }, + * 'pebbles': { 'age': 1, 'active': true } + * }; + * + * _.findKey(users, function(o) { return o.age < 40; }); + * // => 'barney' (iteration order is not guaranteed) + * + * // The `_.matches` iteratee shorthand. + * _.findKey(users, { 'age': 1, 'active': true }); + * // => 'pebbles' + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findKey(users, ['active', false]); + * // => 'fred' + * + * // The `_.property` iteratee shorthand. + * _.findKey(users, 'active'); + * // => 'barney' + */ + function findKey(object, predicate) { + return baseFindKey(object, getIteratee(predicate, 3), baseForOwn); + } + + /** + * This method is like `_.findKey` except that it iterates over elements of + * a collection in the opposite order. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Object + * @param {Object} object The object to inspect. + * @param {Function} [predicate=_.identity] The function invoked per iteration. + * @returns {string|undefined} Returns the key of the matched element, + * else `undefined`. + * @example + * + * var users = { + * 'barney': { 'age': 36, 'active': true }, + * 'fred': { 'age': 40, 'active': false }, + * 'pebbles': { 'age': 1, 'active': true } + * }; + * + * _.findLastKey(users, function(o) { return o.age < 40; }); + * // => returns 'pebbles' assuming `_.findKey` returns 'barney' + * + * // The `_.matches` iteratee shorthand. + * _.findLastKey(users, { 'age': 36, 'active': true }); + * // => 'barney' + * + * // The `_.matchesProperty` iteratee shorthand. + * _.findLastKey(users, ['active', false]); + * // => 'fred' + * + * // The `_.property` iteratee shorthand. + * _.findLastKey(users, 'active'); + * // => 'pebbles' + */ + function findLastKey(object, predicate) { + return baseFindKey(object, getIteratee(predicate, 3), baseForOwnRight); + } + + /** + * Iterates over own and inherited enumerable string keyed properties of an + * object and invokes `iteratee` for each property. The iteratee is invoked + * with three arguments: (value, key, object). Iteratee functions may exit + * iteration early by explicitly returning `false`. + * + * @static + * @memberOf _ + * @since 0.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forInRight + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forIn(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'a', 'b', then 'c' (iteration order is not guaranteed). + */ + function forIn(object, iteratee) { + return object == null + ? object + : baseFor(object, getIteratee(iteratee, 3), keysIn); + } + + /** + * This method is like `_.forIn` except that it iterates over properties of + * `object` in the opposite order. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forIn + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forInRight(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'c', 'b', then 'a' assuming `_.forIn` logs 'a', 'b', then 'c'. + */ + function forInRight(object, iteratee) { + return object == null + ? object + : baseForRight(object, getIteratee(iteratee, 3), keysIn); + } + + /** + * Iterates over own enumerable string keyed properties of an object and + * invokes `iteratee` for each property. The iteratee is invoked with three + * arguments: (value, key, object). Iteratee functions may exit iteration + * early by explicitly returning `false`. + * + * @static + * @memberOf _ + * @since 0.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forOwnRight + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwn(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'a' then 'b' (iteration order is not guaranteed). + */ + function forOwn(object, iteratee) { + return object && baseForOwn(object, getIteratee(iteratee, 3)); + } + + /** + * This method is like `_.forOwn` except that it iterates over properties of + * `object` in the opposite order. + * + * @static + * @memberOf _ + * @since 2.0.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns `object`. + * @see _.forOwn + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.forOwnRight(new Foo, function(value, key) { + * console.log(key); + * }); + * // => Logs 'b' then 'a' assuming `_.forOwn` logs 'a' then 'b'. + */ + function forOwnRight(object, iteratee) { + return object && baseForOwnRight(object, getIteratee(iteratee, 3)); + } + + /** + * Creates an array of function property names from own enumerable properties + * of `object`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to inspect. + * @returns {Array} Returns the function names. + * @see _.functionsIn + * @example + * + * function Foo() { + * this.a = _.constant('a'); + * this.b = _.constant('b'); + * } + * + * Foo.prototype.c = _.constant('c'); + * + * _.functions(new Foo); + * // => ['a', 'b'] + */ + function functions(object) { + return object == null ? [] : baseFunctions(object, keys(object)); + } + + /** + * Creates an array of function property names from own and inherited + * enumerable properties of `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to inspect. + * @returns {Array} Returns the function names. + * @see _.functions + * @example + * + * function Foo() { + * this.a = _.constant('a'); + * this.b = _.constant('b'); + * } + * + * Foo.prototype.c = _.constant('c'); + * + * _.functionsIn(new Foo); + * // => ['a', 'b', 'c'] + */ + function functionsIn(object) { + return object == null ? [] : baseFunctions(object, keysIn(object)); + } + + /** + * Gets the value at `path` of `object`. If the resolved value is + * `undefined`, the `defaultValue` is returned in its place. + * + * @static + * @memberOf _ + * @since 3.7.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to get. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.get(object, 'a[0].b.c'); + * // => 3 + * + * _.get(object, ['a', '0', 'b', 'c']); + * // => 3 + * + * _.get(object, 'a.b.c', 'default'); + * // => 'default' + */ + function get(object, path, defaultValue) { + var result = object == null ? undefined$1 : baseGet(object, path); + return result === undefined$1 ? defaultValue : result; + } + + /** + * Checks if `path` is a direct property of `object`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @example + * + * var object = { 'a': { 'b': 2 } }; + * var other = _.create({ 'a': _.create({ 'b': 2 }) }); + * + * _.has(object, 'a'); + * // => true + * + * _.has(object, 'a.b'); + * // => true + * + * _.has(object, ['a', 'b']); + * // => true + * + * _.has(other, 'a'); + * // => false + */ + function has(object, path) { + return object != null && hasPath(object, path, baseHas); + } + + /** + * Checks if `path` is a direct or inherited property of `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path to check. + * @returns {boolean} Returns `true` if `path` exists, else `false`. + * @example + * + * var object = _.create({ 'a': _.create({ 'b': 2 }) }); + * + * _.hasIn(object, 'a'); + * // => true + * + * _.hasIn(object, 'a.b'); + * // => true + * + * _.hasIn(object, ['a', 'b']); + * // => true + * + * _.hasIn(object, 'b'); + * // => false + */ + function hasIn(object, path) { + return object != null && hasPath(object, path, baseHasIn); + } + + /** + * Creates an object composed of the inverted keys and values of `object`. + * If `object` contains duplicate values, subsequent values overwrite + * property assignments of previous values. + * + * @static + * @memberOf _ + * @since 0.7.0 + * @category Object + * @param {Object} object The object to invert. + * @returns {Object} Returns the new inverted object. + * @example + * + * var object = { 'a': 1, 'b': 2, 'c': 1 }; + * + * _.invert(object); + * // => { '1': 'c', '2': 'b' } + */ + var invert = createInverter(function(result, value, key) { + if (value != null && + typeof value.toString != 'function') { + value = nativeObjectToString.call(value); + } + + result[value] = key; + }, constant(identity)); + + /** + * This method is like `_.invert` except that the inverted object is generated + * from the results of running each element of `object` thru `iteratee`. The + * corresponding inverted value of each inverted key is an array of keys + * responsible for generating the inverted value. The iteratee is invoked + * with one argument: (value). + * + * @static + * @memberOf _ + * @since 4.1.0 + * @category Object + * @param {Object} object The object to invert. + * @param {Function} [iteratee=_.identity] The iteratee invoked per element. + * @returns {Object} Returns the new inverted object. + * @example + * + * var object = { 'a': 1, 'b': 2, 'c': 1 }; + * + * _.invertBy(object); + * // => { '1': ['a', 'c'], '2': ['b'] } + * + * _.invertBy(object, function(value) { + * return 'group' + value; + * }); + * // => { 'group1': ['a', 'c'], 'group2': ['b'] } + */ + var invertBy = createInverter(function(result, value, key) { + if (value != null && + typeof value.toString != 'function') { + value = nativeObjectToString.call(value); + } + + if (hasOwnProperty.call(result, value)) { + result[value].push(key); + } else { + result[value] = [key]; + } + }, getIteratee); + + /** + * Invokes the method at `path` of `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the method to invoke. + * @param {...*} [args] The arguments to invoke the method with. + * @returns {*} Returns the result of the invoked method. + * @example + * + * var object = { 'a': [{ 'b': { 'c': [1, 2, 3, 4] } }] }; + * + * _.invoke(object, 'a[0].b.c.slice', 1, 3); + * // => [2, 3] + */ + var invoke = baseRest(baseInvoke); + + /** + * Creates an array of the own enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. See the + * [ES spec](http://ecma-international.org/ecma-262/7.0/#sec-object.keys) + * for more details. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keys(new Foo); + * // => ['a', 'b'] (iteration order is not guaranteed) + * + * _.keys('hi'); + * // => ['0', '1'] + */ + function keys(object) { + return isArrayLike(object) ? arrayLikeKeys(object) : baseKeys(object); + } + + /** + * Creates an array of the own and inherited enumerable property names of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property names. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.keysIn(new Foo); + * // => ['a', 'b', 'c'] (iteration order is not guaranteed) + */ + function keysIn(object) { + return isArrayLike(object) ? arrayLikeKeys(object, true) : baseKeysIn(object); + } + + /** + * The opposite of `_.mapValues`; this method creates an object with the + * same values as `object` and keys generated by running each own enumerable + * string keyed property of `object` thru `iteratee`. The iteratee is invoked + * with three arguments: (value, key, object). + * + * @static + * @memberOf _ + * @since 3.8.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns the new mapped object. + * @see _.mapValues + * @example + * + * _.mapKeys({ 'a': 1, 'b': 2 }, function(value, key) { + * return key + value; + * }); + * // => { 'a1': 1, 'b2': 2 } + */ + function mapKeys(object, iteratee) { + var result = {}; + iteratee = getIteratee(iteratee, 3); + + baseForOwn(object, function(value, key, object) { + baseAssignValue(result, iteratee(value, key, object), value); + }); + return result; + } + + /** + * Creates an object with the same keys as `object` and values generated + * by running each own enumerable string keyed property of `object` thru + * `iteratee`. The iteratee is invoked with three arguments: + * (value, key, object). + * + * @static + * @memberOf _ + * @since 2.4.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @returns {Object} Returns the new mapped object. + * @see _.mapKeys + * @example + * + * var users = { + * 'fred': { 'user': 'fred', 'age': 40 }, + * 'pebbles': { 'user': 'pebbles', 'age': 1 } + * }; + * + * _.mapValues(users, function(o) { return o.age; }); + * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) + * + * // The `_.property` iteratee shorthand. + * _.mapValues(users, 'age'); + * // => { 'fred': 40, 'pebbles': 1 } (iteration order is not guaranteed) + */ + function mapValues(object, iteratee) { + var result = {}; + iteratee = getIteratee(iteratee, 3); + + baseForOwn(object, function(value, key, object) { + baseAssignValue(result, key, iteratee(value, key, object)); + }); + return result; + } + + /** + * This method is like `_.assign` except that it recursively merges own and + * inherited enumerable string keyed properties of source objects into the + * destination object. Source properties that resolve to `undefined` are + * skipped if a destination value exists. Array and plain object properties + * are merged recursively. Other objects and value types are overridden by + * assignment. Source objects are applied from left to right. Subsequent + * sources overwrite property assignments of previous sources. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 0.5.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} [sources] The source objects. + * @returns {Object} Returns `object`. + * @example + * + * var object = { + * 'a': [{ 'b': 2 }, { 'd': 4 }] + * }; + * + * var other = { + * 'a': [{ 'c': 3 }, { 'e': 5 }] + * }; + * + * _.merge(object, other); + * // => { 'a': [{ 'b': 2, 'c': 3 }, { 'd': 4, 'e': 5 }] } + */ + var merge = createAssigner(function(object, source, srcIndex) { + baseMerge(object, source, srcIndex); + }); + + /** + * This method is like `_.merge` except that it accepts `customizer` which + * is invoked to produce the merged values of the destination and source + * properties. If `customizer` returns `undefined`, merging is handled by the + * method instead. The `customizer` is invoked with six arguments: + * (objValue, srcValue, key, object, source, stack). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The destination object. + * @param {...Object} sources The source objects. + * @param {Function} customizer The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * function customizer(objValue, srcValue) { + * if (_.isArray(objValue)) { + * return objValue.concat(srcValue); + * } + * } + * + * var object = { 'a': [1], 'b': [2] }; + * var other = { 'a': [3], 'b': [4] }; + * + * _.mergeWith(object, other, customizer); + * // => { 'a': [1, 3], 'b': [2, 4] } + */ + var mergeWith = createAssigner(function(object, source, srcIndex, customizer) { + baseMerge(object, source, srcIndex, customizer); + }); + + /** + * The opposite of `_.pick`; this method creates an object composed of the + * own and inherited enumerable property paths of `object` that are not omitted. + * + * **Note:** This method is considerably slower than `_.pick`. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [paths] The property paths to omit. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.omit(object, ['a', 'c']); + * // => { 'b': '2' } + */ + var omit = flatRest(function(object, paths) { + var result = {}; + if (object == null) { + return result; + } + var isDeep = false; + paths = arrayMap(paths, function(path) { + path = castPath(path, object); + isDeep || (isDeep = path.length > 1); + return path; + }); + copyObject(object, getAllKeysIn(object), result); + if (isDeep) { + result = baseClone(result, CLONE_DEEP_FLAG | CLONE_FLAT_FLAG | CLONE_SYMBOLS_FLAG, customOmitClone); + } + var length = paths.length; + while (length--) { + baseUnset(result, paths[length]); + } + return result; + }); + + /** + * The opposite of `_.pickBy`; this method creates an object composed of + * the own and inherited enumerable string keyed properties of `object` that + * `predicate` doesn't return truthy for. The predicate is invoked with two + * arguments: (value, key). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The source object. + * @param {Function} [predicate=_.identity] The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.omitBy(object, _.isNumber); + * // => { 'b': '2' } + */ + function omitBy(object, predicate) { + return pickBy(object, negate(getIteratee(predicate))); + } + + /** + * Creates an object composed of the picked `object` properties. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The source object. + * @param {...(string|string[])} [paths] The property paths to pick. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.pick(object, ['a', 'c']); + * // => { 'a': 1, 'c': 3 } + */ + var pick = flatRest(function(object, paths) { + return object == null ? {} : basePick(object, paths); + }); + + /** + * Creates an object composed of the `object` properties `predicate` returns + * truthy for. The predicate is invoked with two arguments: (value, key). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The source object. + * @param {Function} [predicate=_.identity] The function invoked per property. + * @returns {Object} Returns the new object. + * @example + * + * var object = { 'a': 1, 'b': '2', 'c': 3 }; + * + * _.pickBy(object, _.isNumber); + * // => { 'a': 1, 'c': 3 } + */ + function pickBy(object, predicate) { + if (object == null) { + return {}; + } + var props = arrayMap(getAllKeysIn(object), function(prop) { + return [prop]; + }); + predicate = getIteratee(predicate); + return basePickBy(object, props, function(value, path) { + return predicate(value, path[0]); + }); + } + + /** + * This method is like `_.get` except that if the resolved value is a + * function it's invoked with the `this` binding of its parent object and + * its result is returned. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @param {Array|string} path The path of the property to resolve. + * @param {*} [defaultValue] The value returned for `undefined` resolved values. + * @returns {*} Returns the resolved value. + * @example + * + * var object = { 'a': [{ 'b': { 'c1': 3, 'c2': _.constant(4) } }] }; + * + * _.result(object, 'a[0].b.c1'); + * // => 3 + * + * _.result(object, 'a[0].b.c2'); + * // => 4 + * + * _.result(object, 'a[0].b.c3', 'default'); + * // => 'default' + * + * _.result(object, 'a[0].b.c3', _.constant('default')); + * // => 'default' + */ + function result(object, path, defaultValue) { + path = castPath(path, object); + + var index = -1, + length = path.length; + + // Ensure the loop is entered when path is empty. + if (!length) { + length = 1; + object = undefined$1; + } + while (++index < length) { + var value = object == null ? undefined$1 : object[toKey(path[index])]; + if (value === undefined$1) { + index = length; + value = defaultValue; + } + object = isFunction(value) ? value.call(object) : value; + } + return object; + } + + /** + * Sets the value at `path` of `object`. If a portion of `path` doesn't exist, + * it's created. Arrays are created for missing index properties while objects + * are created for all other missing properties. Use `_.setWith` to customize + * `path` creation. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 3.7.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @returns {Object} Returns `object`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.set(object, 'a[0].b.c', 4); + * console.log(object.a[0].b.c); + * // => 4 + * + * _.set(object, ['x', '0', 'y', 'z'], 5); + * console.log(object.x[0].y.z); + * // => 5 + */ + function set(object, path, value) { + return object == null ? object : baseSet(object, path, value); + } + + /** + * This method is like `_.set` except that it accepts `customizer` which is + * invoked to produce the objects of `path`. If `customizer` returns `undefined` + * path creation is handled by the method instead. The `customizer` is invoked + * with three arguments: (nsValue, key, nsObject). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {*} value The value to set. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * var object = {}; + * + * _.setWith(object, '[0][1]', 'a', Object); + * // => { '0': { '1': 'a' } } + */ + function setWith(object, path, value, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined$1; + return object == null ? object : baseSet(object, path, value, customizer); + } + + /** + * Creates an array of own enumerable string keyed-value pairs for `object` + * which can be consumed by `_.fromPairs`. If `object` is a map or set, its + * entries are returned. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias entries + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the key-value pairs. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.toPairs(new Foo); + * // => [['a', 1], ['b', 2]] (iteration order is not guaranteed) + */ + var toPairs = createToPairs(keys); + + /** + * Creates an array of own and inherited enumerable string keyed-value pairs + * for `object` which can be consumed by `_.fromPairs`. If `object` is a map + * or set, its entries are returned. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @alias entriesIn + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the key-value pairs. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.toPairsIn(new Foo); + * // => [['a', 1], ['b', 2], ['c', 3]] (iteration order is not guaranteed) + */ + var toPairsIn = createToPairs(keysIn); + + /** + * An alternative to `_.reduce`; this method transforms `object` to a new + * `accumulator` object which is the result of running each of its own + * enumerable string keyed properties thru `iteratee`, with each invocation + * potentially mutating the `accumulator` object. If `accumulator` is not + * provided, a new object with the same `[[Prototype]]` will be used. The + * iteratee is invoked with four arguments: (accumulator, value, key, object). + * Iteratee functions may exit iteration early by explicitly returning `false`. + * + * @static + * @memberOf _ + * @since 1.3.0 + * @category Object + * @param {Object} object The object to iterate over. + * @param {Function} [iteratee=_.identity] The function invoked per iteration. + * @param {*} [accumulator] The custom accumulator value. + * @returns {*} Returns the accumulated value. + * @example + * + * _.transform([2, 3, 4], function(result, n) { + * result.push(n *= n); + * return n % 2 == 0; + * }, []); + * // => [4, 9] + * + * _.transform({ 'a': 1, 'b': 2, 'c': 1 }, function(result, value, key) { + * (result[value] || (result[value] = [])).push(key); + * }, {}); + * // => { '1': ['a', 'c'], '2': ['b'] } + */ + function transform(object, iteratee, accumulator) { + var isArr = isArray(object), + isArrLike = isArr || isBuffer(object) || isTypedArray(object); + + iteratee = getIteratee(iteratee, 4); + if (accumulator == null) { + var Ctor = object && object.constructor; + if (isArrLike) { + accumulator = isArr ? new Ctor : []; + } + else if (isObject(object)) { + accumulator = isFunction(Ctor) ? baseCreate(getPrototype(object)) : {}; + } + else { + accumulator = {}; + } + } + (isArrLike ? arrayEach : baseForOwn)(object, function(value, index, object) { + return iteratee(accumulator, value, index, object); + }); + return accumulator; + } + + /** + * Removes the property at `path` of `object`. + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to unset. + * @returns {boolean} Returns `true` if the property is deleted, else `false`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 7 } }] }; + * _.unset(object, 'a[0].b.c'); + * // => true + * + * console.log(object); + * // => { 'a': [{ 'b': {} }] }; + * + * _.unset(object, ['a', '0', 'b', 'c']); + * // => true + * + * console.log(object); + * // => { 'a': [{ 'b': {} }] }; + */ + function unset(object, path) { + return object == null ? true : baseUnset(object, path); + } + + /** + * This method is like `_.set` except that accepts `updater` to produce the + * value to set. Use `_.updateWith` to customize `path` creation. The `updater` + * is invoked with one argument: (value). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.6.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {Function} updater The function to produce the updated value. + * @returns {Object} Returns `object`. + * @example + * + * var object = { 'a': [{ 'b': { 'c': 3 } }] }; + * + * _.update(object, 'a[0].b.c', function(n) { return n * n; }); + * console.log(object.a[0].b.c); + * // => 9 + * + * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; }); + * console.log(object.x[0].y.z); + * // => 0 + */ + function update(object, path, updater) { + return object == null ? object : baseUpdate(object, path, castFunction(updater)); + } + + /** + * This method is like `_.update` except that it accepts `customizer` which is + * invoked to produce the objects of `path`. If `customizer` returns `undefined` + * path creation is handled by the method instead. The `customizer` is invoked + * with three arguments: (nsValue, key, nsObject). + * + * **Note:** This method mutates `object`. + * + * @static + * @memberOf _ + * @since 4.6.0 + * @category Object + * @param {Object} object The object to modify. + * @param {Array|string} path The path of the property to set. + * @param {Function} updater The function to produce the updated value. + * @param {Function} [customizer] The function to customize assigned values. + * @returns {Object} Returns `object`. + * @example + * + * var object = {}; + * + * _.updateWith(object, '[0][1]', _.constant('a'), Object); + * // => { '0': { '1': 'a' } } + */ + function updateWith(object, path, updater, customizer) { + customizer = typeof customizer == 'function' ? customizer : undefined$1; + return object == null ? object : baseUpdate(object, path, castFunction(updater), customizer); + } + + /** + * Creates an array of the own enumerable string keyed property values of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property values. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.values(new Foo); + * // => [1, 2] (iteration order is not guaranteed) + * + * _.values('hi'); + * // => ['h', 'i'] + */ + function values(object) { + return object == null ? [] : baseValues(object, keys(object)); + } + + /** + * Creates an array of the own and inherited enumerable string keyed property + * values of `object`. + * + * **Note:** Non-object values are coerced to objects. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category Object + * @param {Object} object The object to query. + * @returns {Array} Returns the array of property values. + * @example + * + * function Foo() { + * this.a = 1; + * this.b = 2; + * } + * + * Foo.prototype.c = 3; + * + * _.valuesIn(new Foo); + * // => [1, 2, 3] (iteration order is not guaranteed) + */ + function valuesIn(object) { + return object == null ? [] : baseValues(object, keysIn(object)); + } + + /*------------------------------------------------------------------------*/ + + /** + * Clamps `number` within the inclusive `lower` and `upper` bounds. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category Number + * @param {number} number The number to clamp. + * @param {number} [lower] The lower bound. + * @param {number} upper The upper bound. + * @returns {number} Returns the clamped number. + * @example + * + * _.clamp(-10, -5, 5); + * // => -5 + * + * _.clamp(10, -5, 5); + * // => 5 + */ + function clamp(number, lower, upper) { + if (upper === undefined$1) { + upper = lower; + lower = undefined$1; + } + if (upper !== undefined$1) { + upper = toNumber(upper); + upper = upper === upper ? upper : 0; + } + if (lower !== undefined$1) { + lower = toNumber(lower); + lower = lower === lower ? lower : 0; + } + return baseClamp(toNumber(number), lower, upper); + } + + /** + * Checks if `n` is between `start` and up to, but not including, `end`. If + * `end` is not specified, it's set to `start` with `start` then set to `0`. + * If `start` is greater than `end` the params are swapped to support + * negative ranges. + * + * @static + * @memberOf _ + * @since 3.3.0 + * @category Number + * @param {number} number The number to check. + * @param {number} [start=0] The start of the range. + * @param {number} end The end of the range. + * @returns {boolean} Returns `true` if `number` is in the range, else `false`. + * @see _.range, _.rangeRight + * @example + * + * _.inRange(3, 2, 4); + * // => true + * + * _.inRange(4, 8); + * // => true + * + * _.inRange(4, 2); + * // => false + * + * _.inRange(2, 2); + * // => false + * + * _.inRange(1.2, 2); + * // => true + * + * _.inRange(5.2, 4); + * // => false + * + * _.inRange(-3, -2, -6); + * // => true + */ + function inRange(number, start, end) { + start = toFinite(start); + if (end === undefined$1) { + end = start; + start = 0; + } else { + end = toFinite(end); + } + number = toNumber(number); + return baseInRange(number, start, end); + } + + /** + * Produces a random number between the inclusive `lower` and `upper` bounds. + * If only one argument is provided a number between `0` and the given number + * is returned. If `floating` is `true`, or either `lower` or `upper` are + * floats, a floating-point number is returned instead of an integer. + * + * **Note:** JavaScript follows the IEEE-754 standard for resolving + * floating-point values which can produce unexpected results. + * + * @static + * @memberOf _ + * @since 0.7.0 + * @category Number + * @param {number} [lower=0] The lower bound. + * @param {number} [upper=1] The upper bound. + * @param {boolean} [floating] Specify returning a floating-point number. + * @returns {number} Returns the random number. + * @example + * + * _.random(0, 5); + * // => an integer between 0 and 5 + * + * _.random(5); + * // => also an integer between 0 and 5 + * + * _.random(5, true); + * // => a floating-point number between 0 and 5 + * + * _.random(1.2, 5.2); + * // => a floating-point number between 1.2 and 5.2 + */ + function random(lower, upper, floating) { + if (floating && typeof floating != 'boolean' && isIterateeCall(lower, upper, floating)) { + upper = floating = undefined$1; + } + if (floating === undefined$1) { + if (typeof upper == 'boolean') { + floating = upper; + upper = undefined$1; + } + else if (typeof lower == 'boolean') { + floating = lower; + lower = undefined$1; + } + } + if (lower === undefined$1 && upper === undefined$1) { + lower = 0; + upper = 1; + } + else { + lower = toFinite(lower); + if (upper === undefined$1) { + upper = lower; + lower = 0; + } else { + upper = toFinite(upper); + } + } + if (lower > upper) { + var temp = lower; + lower = upper; + upper = temp; + } + if (floating || lower % 1 || upper % 1) { + var rand = nativeRandom(); + return nativeMin(lower + (rand * (upper - lower + freeParseFloat('1e-' + ((rand + '').length - 1)))), upper); + } + return baseRandom(lower, upper); + } + + /*------------------------------------------------------------------------*/ + + /** + * Converts `string` to [camel case](https://en.wikipedia.org/wiki/CamelCase). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the camel cased string. + * @example + * + * _.camelCase('Foo Bar'); + * // => 'fooBar' + * + * _.camelCase('--foo-bar--'); + * // => 'fooBar' + * + * _.camelCase('__FOO_BAR__'); + * // => 'fooBar' + */ + var camelCase = createCompounder(function(result, word, index) { + word = word.toLowerCase(); + return result + (index ? capitalize(word) : word); + }); + + /** + * Converts the first character of `string` to upper case and the remaining + * to lower case. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to capitalize. + * @returns {string} Returns the capitalized string. + * @example + * + * _.capitalize('FRED'); + * // => 'Fred' + */ + function capitalize(string) { + return upperFirst(toString(string).toLowerCase()); + } + + /** + * Deburrs `string` by converting + * [Latin-1 Supplement](https://en.wikipedia.org/wiki/Latin-1_Supplement_(Unicode_block)#Character_table) + * and [Latin Extended-A](https://en.wikipedia.org/wiki/Latin_Extended-A) + * letters to basic Latin letters and removing + * [combining diacritical marks](https://en.wikipedia.org/wiki/Combining_Diacritical_Marks). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to deburr. + * @returns {string} Returns the deburred string. + * @example + * + * _.deburr('déjà vu'); + * // => 'deja vu' + */ + function deburr(string) { + string = toString(string); + return string && string.replace(reLatin, deburrLetter).replace(reComboMark, ''); + } + + /** + * Checks if `string` ends with the given target string. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {string} [target] The string to search for. + * @param {number} [position=string.length] The position to search up to. + * @returns {boolean} Returns `true` if `string` ends with `target`, + * else `false`. + * @example + * + * _.endsWith('abc', 'c'); + * // => true + * + * _.endsWith('abc', 'b'); + * // => false + * + * _.endsWith('abc', 'b', 2); + * // => true + */ + function endsWith(string, target, position) { + string = toString(string); + target = baseToString(target); + + var length = string.length; + position = position === undefined$1 + ? length + : baseClamp(toInteger(position), 0, length); + + var end = position; + position -= target.length; + return position >= 0 && string.slice(position, end) == target; + } + + /** + * Converts the characters "&", "<", ">", '"', and "'" in `string` to their + * corresponding HTML entities. + * + * **Note:** No other characters are escaped. To escape additional + * characters use a third-party library like [_he_](https://mths.be/he). + * + * Though the ">" character is escaped for symmetry, characters like + * ">" and "/" don't need escaping in HTML and have no special meaning + * unless they're part of a tag or unquoted attribute value. See + * [Mathias Bynens's article](https://mathiasbynens.be/notes/ambiguous-ampersands) + * (under "semi-related fun fact") for more details. + * + * When working with HTML you should always + * [quote attribute values](http://wonko.com/post/html-escaping) to reduce + * XSS vectors. + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @example + * + * _.escape('fred, barney, & pebbles'); + * // => 'fred, barney, & pebbles' + */ + function escape(string) { + string = toString(string); + return (string && reHasUnescapedHtml.test(string)) + ? string.replace(reUnescapedHtml, escapeHtmlChar) + : string; + } + + /** + * Escapes the `RegExp` special characters "^", "$", "\", ".", "*", "+", + * "?", "(", ")", "[", "]", "{", "}", and "|" in `string`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to escape. + * @returns {string} Returns the escaped string. + * @example + * + * _.escapeRegExp('[lodash](https://lodash.com/)'); + * // => '\[lodash\]\(https://lodash\.com/\)' + */ + function escapeRegExp(string) { + string = toString(string); + return (string && reHasRegExpChar.test(string)) + ? string.replace(reRegExpChar, '\\$&') + : string; + } + + /** + * Converts `string` to + * [kebab case](https://en.wikipedia.org/wiki/Letter_case#Special_case_styles). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the kebab cased string. + * @example + * + * _.kebabCase('Foo Bar'); + * // => 'foo-bar' + * + * _.kebabCase('fooBar'); + * // => 'foo-bar' + * + * _.kebabCase('__FOO_BAR__'); + * // => 'foo-bar' + */ + var kebabCase = createCompounder(function(result, word, index) { + return result + (index ? '-' : '') + word.toLowerCase(); + }); + + /** + * Converts `string`, as space separated words, to lower case. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the lower cased string. + * @example + * + * _.lowerCase('--Foo-Bar--'); + * // => 'foo bar' + * + * _.lowerCase('fooBar'); + * // => 'foo bar' + * + * _.lowerCase('__FOO_BAR__'); + * // => 'foo bar' + */ + var lowerCase = createCompounder(function(result, word, index) { + return result + (index ? ' ' : '') + word.toLowerCase(); + }); + + /** + * Converts the first character of `string` to lower case. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the converted string. + * @example + * + * _.lowerFirst('Fred'); + * // => 'fred' + * + * _.lowerFirst('FRED'); + * // => 'fRED' + */ + var lowerFirst = createCaseFirst('toLowerCase'); + + /** + * Pads `string` on the left and right sides if it's shorter than `length`. + * Padding characters are truncated if they can't be evenly divided by `length`. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * _.pad('abc', 8); + * // => ' abc ' + * + * _.pad('abc', 8, '_-'); + * // => '_-abc_-_' + * + * _.pad('abc', 3); + * // => 'abc' + */ + function pad(string, length, chars) { + string = toString(string); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + if (!length || strLength >= length) { + return string; + } + var mid = (length - strLength) / 2; + return ( + createPadding(nativeFloor(mid), chars) + + string + + createPadding(nativeCeil(mid), chars) + ); + } + + /** + * Pads `string` on the right side if it's shorter than `length`. Padding + * characters are truncated if they exceed `length`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * _.padEnd('abc', 6); + * // => 'abc ' + * + * _.padEnd('abc', 6, '_-'); + * // => 'abc_-_' + * + * _.padEnd('abc', 3); + * // => 'abc' + */ + function padEnd(string, length, chars) { + string = toString(string); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (string + createPadding(length - strLength, chars)) + : string; + } + + /** + * Pads `string` on the left side if it's shorter than `length`. Padding + * characters are truncated if they exceed `length`. + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to pad. + * @param {number} [length=0] The padding length. + * @param {string} [chars=' '] The string used as padding. + * @returns {string} Returns the padded string. + * @example + * + * _.padStart('abc', 6); + * // => ' abc' + * + * _.padStart('abc', 6, '_-'); + * // => '_-_abc' + * + * _.padStart('abc', 3); + * // => 'abc' + */ + function padStart(string, length, chars) { + string = toString(string); + length = toInteger(length); + + var strLength = length ? stringSize(string) : 0; + return (length && strLength < length) + ? (createPadding(length - strLength, chars) + string) + : string; + } + + /** + * Converts `string` to an integer of the specified radix. If `radix` is + * `undefined` or `0`, a `radix` of `10` is used unless `value` is a + * hexadecimal, in which case a `radix` of `16` is used. + * + * **Note:** This method aligns with the + * [ES5 implementation](https://es5.github.io/#x15.1.2.2) of `parseInt`. + * + * @static + * @memberOf _ + * @since 1.1.0 + * @category String + * @param {string} string The string to convert. + * @param {number} [radix=10] The radix to interpret `value` by. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {number} Returns the converted integer. + * @example + * + * _.parseInt('08'); + * // => 8 + * + * _.map(['6', '08', '10'], _.parseInt); + * // => [6, 8, 10] + */ + function parseInt(string, radix, guard) { + if (guard || radix == null) { + radix = 0; + } else if (radix) { + radix = +radix; + } + return nativeParseInt(toString(string).replace(reTrimStart, ''), radix || 0); + } + + /** + * Repeats the given string `n` times. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to repeat. + * @param {number} [n=1] The number of times to repeat the string. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {string} Returns the repeated string. + * @example + * + * _.repeat('*', 3); + * // => '***' + * + * _.repeat('abc', 2); + * // => 'abcabc' + * + * _.repeat('abc', 0); + * // => '' + */ + function repeat(string, n, guard) { + if ((guard ? isIterateeCall(string, n, guard) : n === undefined$1)) { + n = 1; + } else { + n = toInteger(n); + } + return baseRepeat(toString(string), n); + } + + /** + * Replaces matches for `pattern` in `string` with `replacement`. + * + * **Note:** This method is based on + * [`String#replace`](https://mdn.io/String/replace). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to modify. + * @param {RegExp|string} pattern The pattern to replace. + * @param {Function|string} replacement The match replacement. + * @returns {string} Returns the modified string. + * @example + * + * _.replace('Hi Fred', 'Fred', 'Barney'); + * // => 'Hi Barney' + */ + function replace() { + var args = arguments, + string = toString(args[0]); + + return args.length < 3 ? string : string.replace(args[1], args[2]); + } + + /** + * Converts `string` to + * [snake case](https://en.wikipedia.org/wiki/Snake_case). + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the snake cased string. + * @example + * + * _.snakeCase('Foo Bar'); + * // => 'foo_bar' + * + * _.snakeCase('fooBar'); + * // => 'foo_bar' + * + * _.snakeCase('--FOO-BAR--'); + * // => 'foo_bar' + */ + var snakeCase = createCompounder(function(result, word, index) { + return result + (index ? '_' : '') + word.toLowerCase(); + }); + + /** + * Splits `string` by `separator`. + * + * **Note:** This method is based on + * [`String#split`](https://mdn.io/String/split). + * + * @static + * @memberOf _ + * @since 4.0.0 + * @category String + * @param {string} [string=''] The string to split. + * @param {RegExp|string} separator The separator pattern to split by. + * @param {number} [limit] The length to truncate results to. + * @returns {Array} Returns the string segments. + * @example + * + * _.split('a-b-c', '-', 2); + * // => ['a', 'b'] + */ + function split(string, separator, limit) { + if (limit && typeof limit != 'number' && isIterateeCall(string, separator, limit)) { + separator = limit = undefined$1; + } + limit = limit === undefined$1 ? MAX_ARRAY_LENGTH : limit >>> 0; + if (!limit) { + return []; + } + string = toString(string); + if (string && ( + typeof separator == 'string' || + (separator != null && !isRegExp(separator)) + )) { + separator = baseToString(separator); + if (!separator && hasUnicode(string)) { + return castSlice(stringToArray(string), 0, limit); + } + } + return string.split(separator, limit); + } + + /** + * Converts `string` to + * [start case](https://en.wikipedia.org/wiki/Letter_case#Stylistic_or_specialised_usage). + * + * @static + * @memberOf _ + * @since 3.1.0 + * @category String + * @param {string} [string=''] The string to convert. + * @returns {string} Returns the start cased string. + * @example + * + * _.startCase('--foo-bar--'); + * // => 'Foo Bar' + * + * _.startCase('fooBar'); + * // => 'Foo Bar' + * + * _.startCase('__FOO_BAR__'); + * // => 'FOO BAR' + */ + var startCase = createCompounder(function(result, word, index) { + return result + (index ? ' ' : '') + upperFirst(word); + }); + + /** + * Checks if `string` starts with the given target string. + * + * @static + * @memberOf _ + * @since 3.0.0 + * @category String + * @param {string} [string=''] The string to inspect. + * @param {string} [target] The string to search for. + * @param {number} [position=0] The position to search from. + * @returns {boolean} Returns `true` if `string` starts with `target`, + * else `false`. + * @example + * + * _.startsWith('abc', 'a'); + * // => true + * + * _.startsWith('abc', 'b'); + * // => false + * + * _.startsWith('abc', 'b', 1); + * // => true + */ + function startsWith(string, target, position) { + string = toString(string); + position = position == null + ? 0 + : baseClamp(toInteger(position), 0, string.length); + + target = baseToString(target); + return string.slice(position, position + target.length) == target; + } + + /** + * Creates a compiled template function that can interpolate data properties + * in "interpolate" delimiters, HTML-escape interpolated data properties in + * "escape" delimiters, and execute JavaScript in "evaluate" delimiters. Data + * properties may be accessed as free variables in the template. If a setting + * object is given, it takes precedence over `_.templateSettings` values. + * + * **Note:** In the development build `_.template` utilizes + * [sourceURLs](http://www.html5rocks.com/en/tutorials/developertools/sourcemaps/#toc-sourceurl) + * for easier debugging. + * + * For more information on precompiling templates see + * [lodash's custom builds documentation](https://lodash.com/custom-builds). + * + * For more information on Chrome extension sandboxes see + * [Chrome's extensions documentation](https://developer.chrome.com/extensions/sandboxingEval). + * + * @static + * @since 0.1.0 + * @memberOf _ + * @category String + * @param {string} [string=''] The template string. + * @param {Object} [options={}] The options object. + * @param {RegExp} [options.escape=_.templateSettings.escape] + * The HTML "escape" delimiter. + * @param {RegExp} [options.evaluate=_.templateSettings.evaluate] + * The "evaluate" delimiter. + * @param {Object} [options.imports=_.templateSettings.imports] + * An object to import into the template as free variables. + * @param {RegExp} [options.interpolate=_.templateSettings.interpolate] + * The "interpolate" delimiter. + * @param {string} [options.sourceURL='lodash.templateSources[n]'] + * The sourceURL of the compiled template. + * @param {string} [options.variable='obj'] + * The data object variable name. + * @param- {Object} [guard] Enables use as an iteratee for methods like `_.map`. + * @returns {Function} Returns the compiled template function. + * @example + * + * // Use the "interpolate" delimiter to create a compiled template. + * var compiled = _.template('hello <%= user %>!'); + * compiled({ 'user': 'fred' }); + * // => 'hello fred!' + * + * // Use the HTML "escape" delimiter to escape data property values. + * var compiled = _.template('<%- value %>'); + * compiled({ 'value': '