ARTS是什么?

Algorithm:每周至少做一个LeetCode的算法题 Review:阅读并点评至少一篇英文文章 Tip:学习至少一个技术技巧 Share:分享一篇有观点和思考的技术文章

Algorithm

  1. /**
  2. * @className: LeetCode09
  3. * @description: 给定二叉搜索树的根结点 root,返回值位于范围 [low, high] 之间的所有结点的值的和。
  4. * @author: Miluo
  5. * @date: 2021/4/26
  6. **/
  7. class TreeNode1 {
  8. int val;
  9. TreeNode1 left;
  10. TreeNode1 right;
  11. TreeNode1() {}
  12. TreeNode1(int val) { this.val = val; }
  13. TreeNode1(int val, TreeNode1 left, TreeNode1 right) {
  14. this.val = val;
  15. this.left = left;
  16. this.right = right;
  17. }
  18. }
  19. public class LeetCode09 {
  20. public int rangeSumBST(TreeNode1 root, int low, int high) {
  21. if (root.val < low && root.right != null) {
  22. return rangeSumBST(root.right,low,high);
  23. }else if(root.val > high && root.left != null) {
  24. return rangeSumBST(root.left,low,high);
  25. }
  26. if(root.val >= low && root.val <= high){
  27. if (root.left != null && root.right == null){
  28. return root.val + rangeSumBST(root.left,low,high);
  29. }else if (root.left == null && root.right != null){
  30. return root.val + rangeSumBST(root.right,low,high);
  31. }else if (root.left != null){
  32. return root.val + rangeSumBST(root.left,low,high) + rangeSumBST(root.right,low,high);
  33. }
  34. return root.val;
  35. }
  36. return 0;
  37. }
  38. //官方题解:
  39. public int rangeSumBST1(TreeNode1 root, int low, int high) {
  40. if (root == null) {
  41. return 0;
  42. }
  43. if (root.val > high) {
  44. return rangeSumBST(root.left, low, high);
  45. }
  46. if (root.val < low) {
  47. return rangeSumBST(root.right, low, high);
  48. }
  49. return root.val + rangeSumBST(root.left, low, high) + rangeSumBST(root.right, low, high);
  50. }
  51. }

Review

Why the Serverless Revolution Has Stalled
有以下因素限制了发展:

  1. 有编程语言的限制,虽然无服务器公司都提供了包装器来运行不支持的语言,但是会影响性能
  2. 无服务器公司没有统一的标准,使得迁移成本高
  3. 性能难以衡量,公司会隐藏相关信息。且代码从未运行或一段时间未运行需要初始化,那么重要的代码需要在间隔时间运行,而用户就需要支付运行时间的费用
  4. 通常不建议运行完整的应用。可以运行完整的应用,但是不值得

Tip

Java8 Date Time API

在Java 8之前,所有关于时间和日期的API都存在各种使用方面的缺陷,主要有:

  1. Java的java.util.Date和java.util.Calendar类易用性差,不支持时区,而且他们都不是线程安全的;
  2. 用于格式化日期的类DateFormat被放在java.text包中,它是一个抽象类,所以我们需要实例化一个SimpleDateFormat对象来处理日期格式化,并且DateFormat也是非线程安全,这意味着如果你在多线程程序中调用同一个DateFormat对象,会得到意想不到的结果。
  3. 对日期的计算方式繁琐,而且容易出错,因为月份是从0开始的,从Calendar中获取的月份需要加一才能表示当前月份。
  1. import java.time.*;
  2. import java.time.format.DateTimeFormatter;
  3. /**
  4. * @author Miluo
  5. * @className LocalDate
  6. * @description 日期
  7. * @date 2021/4/25
  8. **/
  9. public class LocalDateTest {
  10. public static void main(String[] args) {
  11. //初始化
  12. LocalDate localDate = LocalDate.of(2021, 4, 25);//2021-04-25
  13. LocalDate localDate1 = LocalDate.now();//2021-04-25
  14. LocalDate parse = LocalDate.parse("2021-04-25");//2021-04-25
  15. //年
  16. int year = localDate.getYear();
  17. System.out.println(year);//2021
  18. int dayOfYear = localDate.getDayOfYear();
  19. System.out.println(dayOfYear);//115
  20. //月
  21. Month month = localDate.getMonth();
  22. System.out.println(month);//APRIL
  23. int dayOfMonth = localDate.getDayOfMonth();
  24. System.out.println(dayOfMonth);//25
  25. //星期
  26. DayOfWeek dayOfWeek = localDate.getDayOfWeek();
  27. System.out.println(dayOfWeek);//SUNDAY
  28. //格式
  29. String format = localDate.format(DateTimeFormatter.BASIC_ISO_DATE);
  30. System.out.println(format);//20210425
  31. }
  32. }
  1. import java.time.LocalTime;
  2. /**
  3. * @author Miluo
  4. * @className LocalTimeTest
  5. * @description 时间,与LocalDate相似
  6. * @date 2021/4/25
  7. **/
  8. public class LocalTimeTest {
  9. public static void main(String[] args) {
  10. //初始化
  11. LocalTime now = LocalTime.now();
  12. LocalTime parse = LocalTime.parse("16:46:32");
  13. LocalTime of = LocalTime.of(16, 46, 32);
  14. //时
  15. int hour = now.getHour();
  16. //分
  17. int minute = now.getMinute();
  18. //秒
  19. int second = now.getSecond();
  20. }
  21. }
  1. /**
  2. * @author Miluo
  3. * @className InstantTest
  4. * @description 时间戳:可精确到纳秒
  5. * @date 2021/4/25
  6. **/
  7. public class InstantTest {
  8. public static void main(String[] args) {
  9. Instant now = Instant.now();
  10. System.out.println(now);//2021-04-25T08:54:31.094Z
  11. }
  12. }
  13. /**
  14. * @author Miluo
  15. * @className Duration
  16. * @description 时间段
  17. * @date 2021/4/25
  18. **/
  19. public class DurationTest {
  20. public static void main(String[] args) {
  21. LocalDateTime from = LocalDateTime.of(2021, Month.JANUARY, 5, 10, 7, 0); // 2017-01-05 10:07:00
  22. LocalDateTime to = LocalDateTime.of(2021, Month.FEBRUARY, 5, 10, 7, 0); // 2017-02-05 10:07:00
  23. Duration duration = Duration.between(from, to); // 表示从 2017-01-05 10:07:00 到 2017-02-05 10:07:00 这段时间
  24. long days = duration.toDays(); // 这段时间的总天数
  25. long hours = duration.toHours(); // 这段时间的小时数
  26. long minutes = duration.toMinutes(); // 这段时间的分钟数
  27. long seconds = duration.getSeconds(); // 这段时间的秒数
  28. long milliSeconds = duration.toMillis(); // 这段时间的毫秒数
  29. long nanoSeconds = duration.toNanos(); // 这段时间的纳秒数
  30. }
  31. }
  32. /**
  33. * @author Miluo
  34. * @className PeriodTest
  35. * @description 时间段:用年月日表示,因此只接收LocalDate
  36. * @date 2021/4/25
  37. **/
  38. public class PeriodTest {
  39. public static void main(String[] args) {
  40. //初始化
  41. Period period = Period.of(2, 3, 6);
  42. Period period1 = Period.between(
  43. LocalDate.of(2021, 1, 5),
  44. LocalDate.of(2021, 4, 5)
  45. );
  46. }
  47. }

Share

怎样花两年时间去面试一个人