首页 文章 精选 留言 我的

精选列表

搜索[Java],共10000篇文章
优秀的个人博客,低调大师

leetcode算法题解(Java版)-5-简单模拟,字符串处理

一、简单贪心 题目描述 Given n non-negative integers a1 , a2 , ..., an , where each represents a point at coordinate (i, ai ). n vertical lines are drawn such that the two endpoints of line i is at (i, ai ) and (i, 0). Find two lines, which together with x-axis forms a container, such that the container contains the most water. Note: You may not slant the container. 思路 这题在一分钟内就想了个笨方法,迅速敲完,KO! 因为题目还是很简单,不考虑将装水的容器倾斜,所以只要考虑梯形中最短的边和底边的乘积就行了:正反两遍循环数组,第一遍从0~len,先固定最左边的边,从右往左遍历数组,如果碰到大于等于最左边边长的边,那就判断是否大于当前的最大盛水体积并跟新,然后就停止这次循环,将最左边的边向右移动一格,重复操作;第二遍从len~0,和第一遍一样。 代码 public class Solution { public int maxArea(int[] height) { int len=height.length; if(len==0){ return 0; } int maxW=0; for(int i=0;i<len;i++){ for(int j=len-1;j>i;j--){ if(height[j]>=height[i]){ if(height[i]*(j-i)>maxW){ maxW=height[i]*(j-i); } break; } } } for(int i=len-1;i>0;i--){ for(int j=0;j<i;j++){ if(height[j]>=height[i]){ if(height[i]*(i-j)>maxW){ maxW=height[i]*(i-j); } break; } } } return maxW; } } 思路2 好吧,虚心学习,看了一下其他人的代码。发现一个好方法: 从两边往中间走,每次舍弃较短的边,因为宽度减小,要通过高度的增加来弥补 代码 public class Solution { public int maxArea(int[] height) { int len=height.length; if(len==0){ return 0; } int l=0; int r=len-1; int maxW=0; while(l<r){ maxW=Math.max(maxW,Math.min(height[l],height[r])*(r-l)); if(height[l]<height[r]){ l++; } else{ r--; } } return maxW; } } 二、简单回文数字 题目描述 Determine whether an integer is a palindrome. Do this without extra space. click to show spoilers.Some hints: Could negative integers be palindromes? (ie, -1) If you are thinking of converting the integer to string, note the restriction of using extra space. You could also try reversing an integer. However, if you have solved the problem "Reverse Integer", you know that the reversed integer might overflow. How would you handle such case? There is a more generic way of solving this problem. 思路 题目有个限制,就是不能开辟新的空间。 那就和一般的回文串做法不同了,可以这么来搞:干脆求出它翻转过来的整型,最后比较是否值相等。 想到这个思路,是因为int型的特殊基本数据类型,特别对待,哈哈哈 代码 public class Solution { public boolean isPalindrome(int x) { if(x<0){ return false; } int reverse=0; int x_rel=x; while(x!=0){ reverse=reverse*10+x%10; x/=10; } return reverse==x_rel; } } 三、字符串,模拟 题目描述Implement atoi to convert a string to an integer. Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input cases. Notes: It is intended for this problem to be specified vaguely (ie, no given input specs). You are responsible to gather all the input requirements up front. spoilers alert... click to show requirements for atoi.Requirements for atoi: The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this character, takes an optional initial plus or minus sign followed by as many numerical digits as possible, and interprets them as a numerical value. The string can contain additional characters after those that form the integral number, which are ignored and have no effect on the behavior of this function. If the first sequence of non-whitespace characters in str is not a valid integral number, or if no such sequence exists because either str is empty or it contains only whitespace characters, no conversion is performed. If no valid conversion could be performed, a zero value is returned. If the correct value is out of the range of representable values, INT_MAX (2147483647) or INT_MIN (-2147483648) is returned. 思路 细节要求比较多,正负号,非法字符,溢出等都要考虑。 代码 public class Solution { public int atoi(String str) { if(str==null||str.length()==0){ return 0; } int pos=0; while(str.charAt(pos)==' '){ pos++; } int flag=1; if(str.charAt(pos)=='-'){ flag=-1; pos++; } if(str.charAt(pos)=='+'){ flag=1; pos++; } int len=str.length(); int res=0; for(int i=pos;i<len;i++){ char c=str.charAt(i); if(c<'0'||c>'9'){ break; } if(res>Integer.MAX_VALUE/10||(res==Integer.MAX_VALUE/10&&c>'7')){ if(flag>0){ return Integer.MAX_VALUE; } else{ return Integer.MIN_VALUE; } } res=res*10+(c-'0'); } return res*flag; } }

优秀的个人博客,低调大师

springboot配置Cors跨域、java最简单配置跨域解决方案

现在前后分离已经是很常见的一种开发方式了,所以难免会遇到跨域问题,之前用的比较多的是jsonp(本人表示没用过),之前我遇到这种问题一般都是用nginx做反向代理实现跨域请求。 不过springmvc4.2版本增加了对cors的支持,所以解决办法就更简单了,后端一个全局配置轻松解决跨域问题,比之前的都简单轻松。 cors协议不懂的可以百度哦,这里就不废话了。 由于现在大部分项目都是基于springboot做的,目前微服务的开发模式也很火,所以这块就用springboot做案例,用xml配置方式的自己看着改。 1、 全局配置 @Configuration public class WebAppConfigurer extends WebMvcConfigurerAdapter { @Override public void addCorsMappings(CorsRegistry registry) { registry.addMapping("/**") .allowedOrigins("*") //.allowedOrigins("http://192.168.89.89") //rest集中请求方式 .allowedMethods("GET", "POST","DELETE") .allowCredentials(false).maxAge(3600); } } 2、单个接口配置 @CrossOrigin(origins = "*", maxAge = 3600) //* 可以改成ip地址 @PostMapping("save") public ResponseEntity<Result> addNote(@RequestParam String noteName){ 3、 微服务相关帖子 微服务架构搭建:Consul+sleuth+zipkin+Feign/Ribbon+SpringConfig+Zuul+Hystrix Dash-Board-Turbine 码农笔录二维码

优秀的个人博客,低调大师

www.xttblog.com尚硅谷Java视频教程_SpringBoot视频教程

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/xmt1139057136/article/details/79831708 SpringBoot是企业级开发的整体整合解决方案,特别用于快速构建微服务应用,旨在用最简单的方式让开发人员适应各种开发场景; 本视频着重介绍SpringBoot的使用和内部原理;内容包含微服务概念、配置文件、日志框架的使用、web开发、Thymeleaf模板引擎、Docker容器技术、MyBatis、Spring Data JPA、自定义starter等; 学习本套视频最基本需要掌握Spring、SpringMVC、Maven;最好配合《Spring注解版》一起学习效果更好。 00、尚硅谷_SpringBoot_源码、课件 01、尚硅谷_SpringBoot_入门-课程简介 02、尚硅谷_SpringBoot_入门-Spring Boot简介 03、尚硅谷_SpringBoot_入门-微服务简介 04、尚硅谷_SpringBoot_入门-环境准备 05、尚硅谷_SpringBoot_入门-springboot-helloworld 06、尚硅谷_SpringBoot_入门-HelloWorld细节-场景启动器(starter) 07、尚硅谷_SpringBoot_入门-HelloWorld细节-自动配置 08、尚硅谷_SpringBoot_入门-使用向导快速创建Spring Boot应用 09、尚硅谷_SpringBoot_配置-yaml简介 10、尚硅谷_SpringBoot_配置-yaml语法 11、尚硅谷_SpringBoot_配置-yaml配置文件值获取 12、尚硅谷_SpringBoot_配置-properties配置文件编码问题 13、尚硅谷_SpringBoot_配置-@ConfigurationProperties与@Value区别 14、尚硅谷_SpringBoot_配置-@PropertySource、@ImportResource、@Bean 15、尚硅谷_SpringBoot_配置-配置文件占位符 16、尚硅谷_SpringBoot_配置-Profile多环境支持 17、尚硅谷_SpringBoot_配置-配置文件的加载位置 18、尚硅谷_SpringBoot_配置-外部配置加载顺序 19、尚硅谷_SpringBoot_配置-自动配置原理 20、尚硅谷_SpringBoot_配置-@Conditional&自动配置报告 21、尚硅谷_SpringBoot_日志-日志框架分类和选择 22、尚硅谷_SpringBoot_日志-slf4j使用原理 23、尚硅谷_SpringBoot_日志-其他日志框架统一转换为slf4j 24、尚硅谷_SpringBoot_日志-SpringBoot日志关系 25、尚硅谷_SpringBoot_日志-SpringBoot默认配置 26、尚硅谷_SpringBoot_日志-指定日志文件和日志Profile功能 27、尚硅谷_SpringBoot_日志-切换日志框架 28、尚硅谷_SpringBoot_web开发-简介 29、尚硅谷_SpringBoot_web开发-webjars&静态资源映射规则 30、尚硅谷_SpringBoot_web开发-引入thymeleaf 31、尚硅谷_SpringBoot_web开发-thymeleaf语法 32、尚硅谷_SpringBoot_web开发-SpringMVC自动配置原理 33、尚硅谷_SpringBoot_web开发-扩展与全面接管SpringMVC 34、尚硅谷_SpringBoot_web开发-【实验】-引入资源 35、尚硅谷_SpringBoot_web开发-【实验】-国际化 36、尚硅谷_SpringBoot_web开发-【实验】-登陆&拦截器 37、尚硅谷_SpringBoot_web开发-【实验】-Restful实验要求 38、尚硅谷_SpringBoot_web开发-【实验】-员工列表-公共页抽取 39、尚硅谷_SpringBoot_web开发-【实验】-员工列表-链接高亮&列表完成 40、尚硅谷_SpringBoot_web开发-【实验】-员工添加-来到添加页面 41、尚硅谷_SpringBoot_web开发-【实验】-员工添加-添加完成 42、尚硅谷_SpringBoot_web开发-【实验】-员工修改-重用页面&修改完成 43、尚硅谷_SpringBoot_web开发-【实验】-员工删除-删除完成 44、尚硅谷_SpringBoot_web开发-错误处理原理&定制错误页面 45、尚硅谷_SpringBoot_web开发-定制错误数据 46、尚硅谷_SpringBoot_web开发-嵌入式Servlet容器配置修改 47、尚硅谷_SpringBoot_web开发-注册servlet三大组件 48、尚硅谷_SpringBoot_web开发-切换其他嵌入式Servlet容器 49、尚硅谷_SpringBoot_web开发-嵌入式Servlet容器自动配置原理 50、尚硅谷_SpringBoot_web开发-嵌入式Servlet容器启动原理 51、尚硅谷_SpringBoot_web开发-使用外部Servlet容器&JSP支持 52、尚硅谷_SpringBoot_web开发-外部Servlet容器启动SpringBoot应用原理 53、尚硅谷_SpringBoot_Docker-简介 54、尚硅谷_SpringBoot_Docker-核心概念 55、尚硅谷_SpringBoot_Docker-linux环境准备 56、尚硅谷_SpringBoot_Docker-docker安装&启动&停止 57、尚硅谷_SpringBoot_Docker-docker镜像操作常用命令 58、尚硅谷_SpringBoot_Docker-docker容器操作常用命令 59、尚硅谷_SpringBoot_Docker-docker安装MySQL 60、尚硅谷_SpringBoot_数据访问-简介 61、尚硅谷_SpringBoot_数据访问-JDBC&自动配置原理 62、尚硅谷_SpringBoot_数据访问-整合Druid&配置数据源监控 63、尚硅谷_SpringBoot_数据访问-整合MyBatis(一)-基础环境搭建 64、尚硅谷_SpringBoot_数据访问-整合MyBatis(二)-注解版MyBatis 65、尚硅谷_SpringBoot_数据访问-整合MyBatis(二)-配置版MyBatis 66、尚硅谷_SpringBoot_数据访问-SpringData JPA简介 67、尚硅谷_SpringBoot_数据访问-整合JPA 68、尚硅谷_SpringBoot_原理-第一步:创建SpringApplication 69、尚硅谷_SpringBoot_原理-第二步:启动应用 70、尚硅谷_SpringBoot_原理-事件监听机制相关测试 71、尚硅谷_SpringBoot_原理-自定义starter 72、尚硅谷_SpringBoot_结束语

资源下载

更多资源
Mario

Mario

马里奥是站在游戏界顶峰的超人气多面角色。马里奥靠吃蘑菇成长,特征是大鼻子、头戴帽子、身穿背带裤,还留着胡子。与他的双胞胎兄弟路易基一起,长年担任任天堂的招牌角色。

Spring

Spring

Spring框架(Spring Framework)是由Rod Johnson于2002年提出的开源Java企业级应用框架,旨在通过使用JavaBean替代传统EJB实现方式降低企业级编程开发的复杂性。该框架基于简单性、可测试性和松耦合性设计理念,提供核心容器、应用上下文、数据访问集成等模块,支持整合Hibernate、Struts等第三方框架,其适用范围不仅限于服务器端开发,绝大多数Java应用均可从中受益。

Rocky Linux

Rocky Linux

Rocky Linux(中文名:洛基)是由Gregory Kurtzer于2020年12月发起的企业级Linux发行版,作为CentOS稳定版停止维护后与RHEL(Red Hat Enterprise Linux)完全兼容的开源替代方案,由社区拥有并管理,支持x86_64、aarch64等架构。其通过重新编译RHEL源代码提供长期稳定性,采用模块化包装和SELinux安全架构,默认包含GNOME桌面环境及XFS文件系统,支持十年生命周期更新。

WebStorm

WebStorm

WebStorm 是jetbrains公司旗下一款JavaScript 开发工具。目前已经被广大中国JS开发者誉为“Web前端开发神器”、“最强大的HTML5编辑器”、“最智能的JavaScript IDE”等。与IntelliJ IDEA同源,继承了IntelliJ IDEA强大的JS部分的功能。

用户登录
用户注册