![](https://img-blog.csdnimg.cn/20201014180756738.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
leetcode
小杰011
这个作者很懒,什么都没留下…
展开
-
LeetCode_15. 三数之和
三数之和先对传过来的数组排序定格1个元素,其余两个元素用左右两个指针控制相加为0则赋值,大于0则右边指针左移,小于左指针右移(因为排过序,大了左移,小了右移动),这样可以查出某个定格元素对应其他元素的值外层定格元素变值循环代码class Solution { public List<List<Integer>> threeSum(int[] nums) { List<List<Integer>> list = new A原创 2021-04-12 20:26:17 · 70 阅读 · 0 评论 -
LeetCode_12. 整数转罗马数字
整数转罗马数字1 . 定义两数组对应关系,把题目的4,9,10,90,400,900也加上去2 . 创建循环判断输入数据对应能用哪个符号3 . while里面把当前符合能用的都拼接掉,跳出网小符号继续执行class Solution { public String intToRoman(int num) { if(num<=0){ return null; } int[] number = {1,4,5,9,1原创 2021-04-11 15:28:47 · 97 阅读 · 0 评论 -
LeetCode_11. 盛最多水的容器
盛最多水的容器class Solution { public int maxArea(int[] height) { int l = 0; int r = height.length - 1; int maxArea = 0; while(l<r){ int area = Math.min(height[l],height[r])*(r-l); maxArea = Math.max原创 2021-04-11 15:00:36 · 57 阅读 · 0 评论 -
LeetCode_9. 回文数
回文数class Solution { public boolean isPalindrome(int x) { if(x<0){ return false; } int y = x; int b = 0; while(y!=0){ int a = y%10; y /= 10; b = b*10 +a; }原创 2021-04-11 14:44:17 · 69 阅读 · 0 评论 -
LeetCode_184. 部门工资最高的员工
184. 部门工资最高的员工1 . 联表查询2 . 判断工资和部门是否相同3 . 根据部门id分组查询每个部门的最大工资select d.name as 'Department',e.name as 'Employee',e.salary as 'Salary' from Department d,Employee ewhere e.DepartmentId = d.id and (e.Salary,e.DepartmentId) in ( SELECT原创 2021-04-10 20:37:55 · 75 阅读 · 0 评论 -
LeetCode_7整数反转
注意超出int的问题,返回结果最好定义为long然后强转代码class Solution { public int reverse(int x) { long r = 0; while(x != 0){ int a = x%10; x /=10; r = r*10 + a; } if(r> -(1<<31) && r<.原创 2021-04-10 19:59:33 · 60 阅读 · 0 评论 -
LeetCode06_Z字形变换
LeetCode06_Z字形变换先定义StringBuilder的List集合,第一个字母存在第一个StringBuilder中,依次第二行存第二个字母,然后当在最终行数反转存储,实现z形存储,最后把三个StringBuilder合在一起便是答案,下面上代码class Solution { public String convert(String s, int numRows) { if(numRows == 1) return s; List<Strin原创 2021-03-16 20:05:13 · 76 阅读 · 0 评论