ARTS是什么?

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

Algorithm

  1. package leetcode;
  2. import java.util.HashMap;
  3. import java.util.Stack;
  4. /**
  5. * @className: LeetCode04
  6. * @description:
  7. * 给定一个只包括 '(',')','{','}','[',']' 的字符串 s ,判断字符串是否有效。
  8. * 有效字符串需满足:
  9. * 左括号必须用相同类型的右括号闭合。
  10. * 左括号必须以正确的顺序闭合。
  11. * 示例 1:
  12. * 输入:s = "()"
  13. * 输出:true
  14. *
  15. * 示例 2:
  16. * 输入:s = "()[]{}"
  17. * 输出:true
  18. *
  19. * 示例 3:
  20. * 输入:s = "(]"
  21. * 输出:false
  22. *
  23. * 示例 4:
  24. * 输入:s = "([)]"
  25. * 输出:false
  26. * @author: Miluo
  27. * @date: 2021/3/14
  28. **/
  29. public class LeetCode04 {
  30. public boolean isValid(String s) {
  31. //奇数为false
  32. if ((s.length() % 2) != 0){
  33. return false;
  34. }
  35. Stack<Character> stack = new Stack<>();
  36. HashMap<Character, Character> map = new HashMap<>();
  37. map.put(')','(');
  38. map.put('}','{');
  39. map.put(']','[');
  40. for (int i = 0; i < s.length(); i++) {
  41. if (map.containsKey(s.charAt(i))){
  42. if (stack.isEmpty()){
  43. return false;
  44. }
  45. if (map.get(s.charAt(i)) == stack.peek()){
  46. stack.pop();
  47. }else {
  48. return false;
  49. };
  50. }else {
  51. stack.push(s.charAt(i));
  52. }
  53. }
  54. return stack.isEmpty();
  55. }
  56. }

Review

Tools are not skills
从长远来看,知道why远比知道how更重要。像技术、框架、工具等会被淘汰,但是其核心思想、原理会延续。当有新事物出现时,有可能只是新瓶装旧酒,懂得其中根本,就能在短时间内上手。

Tip

Spring Cloud Stream

Spring Cloud Stream 在 Spring Cloud 体系内用于构建高度可扩展的基于事件驱动的微服务。

RocketMQ

  1. //1.Maven依赖
  2. <dependency>
  3. <groupId>com.alibaba.cloud</groupId>
  4. <artifactId>spring-cloud-starter-stream-rocketmq</artifactId>
  5. </dependency>
  6. //2.配置文件参考官方文档.Spring Cloud Stream 中的两个概念: Binder and Binding
  7. // Binder :用于与外部消息中间件集成的组件,用于创建绑定
  8. // Binding:充当消息中间件与应用程序的提供者和使用者之间的桥梁。开发人员只需要使用提供者或使
  9. // 用者来产生或使用数据,而不必担心与消息中间件的交互。
  10. //3.MessageChannel
  11. public interface DemoOutput(){
  12. //生产管道
  13. @Output(" *channel name* ")
  14. MessageChannel output();
  15. }
  16. public interface DemoInput(){
  17. //消费管道
  18. @Input(" *channel name* ")
  19. MessageChannel input();
  20. }
  21. //4.producer
  22. @Component
  23. @EnableBinding(DemoOutput.class)
  24. public class DemoProducer(){
  25. @Resuource
  26. private DemoOutput demoOutput
  27. public void send(String message){
  28. Message<String> msg = MessageBuilder.WithPayload(message).build();
  29. //发送消息
  30. demoOutput.output().send(msg)
  31. }
  32. }
  33. //5.consumer
  34. @Component
  35. @EnableBinding(DemoInput.class)
  36. public class DemoProducer(){
  37. @StreamListener(" *channel name* ")
  38. public void consume(String message){
  39. ...
  40. }
  41. }

Share

关于字符编码,你所需要知道的(ASCII,Unicode,Utf-8,GB2312…)