本文主要是介绍[RATS]week-6,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
[RATS]week-6
- Algorithm
- Question
- Answer
- Result
- Review
- Spring Cloud - Spring Cloud Netflix
- Tips - Spring AOP增强生效的三种方法
- Share - Python && Kotlin from infoQ
- google 搜索频次
- 平均薪资
Algorithm
Question
请你来实现一个 atoi 函数,使其能将字符串转换成整数。
首先,该函数会根据需要丢弃无用的开头空格字符,直到寻找到第一个非空格的字符为止。
当我们寻找到的第一个非空字符为正或者负号时,则将该符号与之后面尽可能多的连续数字组合起来,作为该整数的正负号;假如第一个非空字符是数字,则直接将其与之后连续的数字字符组合起来,形成整数。
该字符串除了有效的整数部分之后也可能会存在多余的字符,这些字符可以被忽略,它们对于函数不应该造成影响。
注意:假如该字符串中的第一个非空格字符不是一个有效整数字符、字符串为空或字符串仅包含空白字符时,则你的函数不需要进行转换。
在任何情况下,若函数不能进行有效的转换时,请返回 0。
说明:
假设我们的环境只能存储 32 位大小的有符号整数,那么其数值范围为 [−231, 231 − 1]。如果数值超过这个范围,请返回 INT_MAX (231 − 1) 或 INT_MIN (−231) 。
示例 1:
输入: “42”
输出: 42
示例 2:
输入: " -42"
输出: -42
解释: 第一个非空白字符为 ‘-’, 它是一个负号。
我们尽可能将负号与后面所有连续出现的数字组合起来,最后得到 -42 。
示例 3:
输入: “4193 with words”
输出: 4193
解释: 转换截止于数字 ‘3’ ,因为它的下一个字符不为数字。
示例 4:
输入: “words and 987”
输出: 0
解释: 第一个非空字符是 ‘w’, 但它不是数字或正、负号。
因此无法执行有效的转换。
示例 5:
输入: “-91283472332”
输出: -2147483648
解释: 数字 “-91283472332” 超过 32 位有符号整数范围。
因此返回 INT_MIN (−231) 。
来源:力扣(LeetCode)
链接:https://leetcode-cn.com/problems/string-to-integer-atoi
著作权归领扣网络所有。商业转载请联系官方授权,非商业转载请注明出处。
Answer
public int myAtoi(String str) {char[] charArray = str.toCharArray();char space1 = 160;char space2 = 32;char minus = 45,plus = 43;char minDigitalChar = 48;char maxDigitalChar = 57;StringBuilder sb = new StringBuilder();for (char c : charArray) {if (sb.length() == 0 && (c == space1 || c == space2)) {continue;}if (sb.length() == 0 && (c < minDigitalChar || c > maxDigitalChar) && minus != c && plus != c) {return 0;}if (sb.length() > 0 && (c < minDigitalChar || c > maxDigitalChar)) {break;}sb.append(c);if("-".compareTo(sb.toString()) == 0 || "+".compareTo(sb.toString()) == 0) continue;Long l = Long.valueOf(sb.toString());if (l > Integer.MAX_VALUE) {return Integer.MAX_VALUE;}if (l < Integer.MIN_VALUE) {return Integer.MIN_VALUE;}}if(sb.length() == 0) return 0;if("-".compareTo(sb.toString()) == 0 || "+".compareTo(sb.toString()) == 0) return 0;Long l = Long.valueOf(sb.toString());if (l > Integer.MAX_VALUE) {return Integer.MAX_VALUE;}if (l < Integer.MIN_VALUE) {return Integer.MIN_VALUE;}return l.intValue();}
Result
Review
Spring Cloud - Spring Cloud Netflix
Spring Cloud Stream is a framework for building highly scalable event-driven microservices connected with shared messaging systems.
The framework provides a flexible programming model built on already established and familiar Spring idioms and best practices, including support for persistent pub/sub semantics, consumer groups, and stateful partitions.
Spring Cloud Stream 是一套构建高扩展的事件驱动的链接共享消息系统的微服务架构。这套框架提供了*灵活的构建在一部书的稳定的和类似Spring习惯和最佳时间的编程模型,包括了支持发布发布/订阅模型,消费者组和状态分区
Binder Implementations
Spring Cloud Stream supports a variety of binder implementations and the following table includes the link to the GitHub projects.
· RabbitMQ
· Apache Kafka
· Kafka Streams
· Amazon Kinesis
· Google PubSub (partner maintained)
· Solace PubSub+ (partner maintained)
· Azure Event Hubs (partner maintained)
· Apache RocketMQ (partner maintained)
The core building blocks of Spring Cloud Stream are:
·Destination Binders: Components responsible to provide integration with the external messaging systems.
·Destination Bindings: Bridge between the external messaging systems and application provided Producers and Consumers of messages (created by the Destination Binders).
·Message: The canonical data structure used by producers and consumers to communicate with Destination Binders (and thus other applications via external messaging systems).
**Binder Implementations
Spring CLoud Stream 支持多种类型的binder implementations和下面表格中包括的GitHub上的项目链接
· RabbitMQ
· Apache Kafka
· Kafka Streams
· Amazon Kinesis
· Google PubSub (partner maintained)
· Solace PubSub+ (partner maintained)
· Azure Event Hubs (partner maintained)
· Apache RocketMQ (partner maintained)
这个核心构建Spring Cloud Stream 组成部分是:
· Destination Binders:组件负责集成提供外部消息传送系统
· Destination Bindings:外部消息传送系统和应用程序之间的桥提供了生产者与消费者的消息(Destination Binders创建)
· 信息:生产者和消费者使用的典型数据结构在Destination Binders之间传递消息。
**
Tips - Spring AOP增强生效的三种方法
1.把Service自己作为Bean注入到Service中,
2.使用ApplicationContext
3.使用AopContext
Demo 如下
public DemoService{@Autowiredprivate DemoService demoService;@Autowiredprivate ApplicationContext appContext;@Transactionalpublic void method1(){}@Transactionalpublic void method2(){}public void invokeWithSelf(){demoService.method1();demoService.method2();}public void invokeWithAppContext(){DemoService service = (DemoService)appContext.getBean(DemoService.class);service.method1();service.method2();}public void invokeWithAopContext(){Demoservice service = (DemoService)AopContext.currentProxy();service.method1();service.method2();}
}
注意要使用AopContext.currentProxy()时,需要在程序main入口的类添加@EnableAspectJAutoProxy(exposeProxy = true)
@EnableAspectJAutoProxy(exposeProxy = true)
public class DemoApplication{public static void main(String[] args){SpringApplication.run(DemoApplication.class, args);}
}
以上自极客时间-《MySQL实战45讲》学习笔记
Share - Python && Kotlin from infoQ
google 搜索频次
平均薪资
Python 正在蚕食编程语言的世界。今年 4 月,外媒 ZDNet援引 SlashData 的数据表示,目前全球范围有 820 万开发者使用 Python 进行编码,其数量已超过拥有 760 万使用者的 Java。去年 9 月,它们的用户数还分别为 700 万(Python)和 710 万(Java)。有分析称,机器学习的兴起是 Python 崛起的重要推动因素。现在,高达 69%的机器学习开发人员和数据科学家都在使用 Python。通过下表,你还可以看到,尽管 Python 的平均薪资较去年有所回落,但与其他语言相比仍具竞争力。
与之相应地,一些科技巨头都在使用 Python。例如,Google 从人工智能算法到云应用引擎等领域都使用 Python;Dropbox 99.9% 的代码是用 Python 编写的,包括服务器后端、桌面客户端、网站控制器逻辑、API 后端和分析工具等。
目前,Kotlin 主要用来构建 Android 应用程序。根据 JetBrains 最近的一项调查,大约 62% 的开发人员正在使用 Kotlin 构建移动应用程序,41% 的开发人员用它完成 Web 后端项目,库占 29%,工具占 22%,9% 的受访者将其用于桌面应用程序,7% 的受访者将其用于构建物联网。Kotlin 的势头很可能在未来几年才会爆发,当前,它距离完全超越 Java 还有很长一段路要走。
Java 与 Kotlin 之间的关系同 Objective-C 与 Swift 有些类似。但不同的是,后者间的“对决”显然更加白热化,Objective-C 与 Swift 分别位列排行榜第八、九位,份额仅差 0.17%,而 Objective-C 的搜索趋势较 Swift 低 0.4 个百分点。
此外,榜单中,上升幅度同比增长较多的还有 Go,Rust,JavaScript,Julia;与之相对地,Ruby,Scala,Perl,Visual Basic,Lua,Delphi 则有所下降。
这篇关于[RATS]week-6的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!