ARTS是什么?

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

Algorithm

  1. package leetcode;
  2. /**
  3. * @className: LeetCode10
  4. * @description:
  5. * 未知 整数数组 arr 由 n 个非负整数组成。
  6. * 经编码后变为长度为 n - 1 的另一个整数数组 encoded ,其中 encoded[i] = arr[i] XOR arr[i + 1] 。
  7. * 例如,arr = [1,0,2,1] 经编码后得到 encoded = [1,2,3] 。
  8. * 给你编码后的数组 encoded 和原数组 arr 的第一个元素 first(arr[0])。
  9. * 请解码返回原数组 arr 。可以证明答案存在并且是唯一的。
  10. * 示例 1:
  11. * 输入:encoded = [1,2,3], first = 1
  12. * 输出:[1,0,2,1]
  13. * 解释:若 arr = [1,0,2,1] ,那么 first = 1 且 encoded = [1 XOR 0, 0 XOR 2, 2 XOR 1] = [1,2,3]
  14. *
  15. * 示例 2:
  16. * 输入:encoded = [6,2,7,3], first = 4
  17. * 输出:[4,2,0,7,4]
  18. * @author: Miluo
  19. * @date: 2021/5/6
  20. **/
  21. public class LeetCode10 {
  22. public int[] decode(int[] encoded, int first) {
  23. int[] code = new int[encoded.length + 1];
  24. code[0] = first;
  25. for (int i = 0; i < encoded.length; i++) {
  26. code[i + 1] = encoded[i]^code[i];
  27. }
  28. return code;
  29. }
  30. }

Review

Two Software Engineering Lessons Learnt the Hard Way

  1. 知识需要再实践中学习,只是阅读和聊天无法内化知识,而且只有在犯错的情况下,才能获得重要得见识,犯错才是最好得老师。
  2. 开发的产品,最重要的是满足用户的需求。一个没人用的产品后续发展是没有方向的,在需求的驱动下,产品才能有明确的目标,才会有更好的发展。

Tip

当在Spring中使用@Autowired的接口有多个实现时,可能出的问题:required a single bean, but 2 were found

  1. @Repository
  2. pulic class OneDataService implements DataService{
  3. ...
  4. }
  5. @Repository
  6. pulic class TwoDataService implements DataService{
  7. ...
  8. }
  9. @Autowired
  10. DataService dataservice;

解决方法:

  1. 用@Qualifier注解表示具体要使用的实现服务

    1. @Autowired()
    2. @Qualifier("oneDataService")
    3. DataService dataService;
  2. 在自动注入时,名称显式指为所要使用的实现服务

    1. @Autowired()
    2. DataService twoDataService;

    Share

    “残酷” 的事实