Leetcode
西工大苗苗
这个作者很懒,什么都没留下…
展开
-
leetcode - 67 二进制求和
这道题遇到的最大的问题就是关于int隐式转换为char时报错这一道题主要使用Stringbuffer来减少字符串上复制的开销关键之一就是两个二进制求和的结果长度最多比较长的数字长1思路:首先将a字符串设置为较长的那一个开辟两个Stringbuffer,较长的那一个数字头部多加一个0另一个较短的前部补0到两者长度相同,方便计算计算,进位,循环设置最高位class Solut...原创 2019-08-02 15:24:19 · 98 阅读 · 0 评论 -
leetcode - 772 加一
https://leetcode-cn.com/explore/learn/card/array-and-string/198/introduction-to-array/772/class Solution { public int[] plusOne(int[] digits) { for(int i=digits.length-1;i>=0;i--) ...原创 2019-07-17 17:55:22 · 381 阅读 · 0 评论 -
leetcode - 747 至少是其他数字两倍的最大数
class Solution { public int dominantIndex(int[] nums) { if(nums.length <= 1) return nums.length == 0 ? -1 : 0; int first = nums[0]>nums[1] ? nums[0] : nums[1]; ...原创 2019-07-17 17:14:50 · 111 阅读 · 0 评论 -
leetcode - 724 寻找数组的中心索引
class Solution { public int pivotIndex(int[] nums) { //[-1,-1,-1,0,1,1] if(nums.length == 0) return -1; if( nums.length == 1 || nums.length == 2 && nums...原创 2019-07-17 14:25:22 · 77 阅读 · 0 评论 -
leetcode - 118 杨辉三角
class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> result = new ArrayList<List<Integer>>(); for(int i=1;i&l...原创 2019-07-18 19:35:36 · 119 阅读 · 0 评论 -
leetcode - 54 螺旋矩阵
用时40min物理上x,y坐标和二维数组中第一维第二维的关系易错注意边界条件class Solution { public List<Integer> spiralOrder(int[][] matrix) { List<Integer> result = new ArrayList<Integer>(); if...原创 2019-07-18 17:35:17 · 106 阅读 · 0 评论 -
leetcode - 498 对角线遍历
用时62minclass Solution { public int[] findDiagonalOrder(int[][] matrix) { if(matrix.length == 0) return new int[0]; int row = 0,col = 0,n = matrix.length , m = matrix[0...原创 2019-07-18 15:21:23 · 154 阅读 · 0 评论 -
*leetcode - 28 实现Strstr()
两个字符串,需要判断第二个字符串是否为第一个字符串的子字符串,如果是的话返回子字符串所在位置第一个元素的索引推荐解法:KMP算法,现在还没有搞懂,已标星当前解法:当前为逐个比对以及回溯的方法,效率比较低,复杂度为平方class Solution { public int strStr(String haystack, String needle) { if(nee...原创 2019-08-12 15:50:00 · 113 阅读 · 0 评论