自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(45)
  • 收藏
  • 关注

原创 3. 560 和为K的子数组(mid)

二、 思路先理解明白题,那意思是要找出来所有的和等于k的个数。先弄个preSum,然后两个for循环挨个的遍历,找到了就ans++。三、标准答案总结无。

2022-06-14 23:16:32 108 1

原创 2. 304 二维区域和检索(mid)

二、 思路和上一题思路相似,在构建一个二维数组preSum(为了方便比给的matrix多一行一列),preSum[i,j]里面放从[0,0]到[i,j]这个矩形的和。然后求两个点的和就直接preSum[row2+1,col2+1] - preSum[row2+1,col1] - preSum[row1,col2+1]+preSum[row1,col1]三、标准答案总结仔细读题宝,看好变量表示啥意思,不能理所当然。...

2022-06-13 23:41:35 175

原创 1. 303区域和检索(easy)

二、 思路其实就是再建个数组,存前n项和,然后到时候求区间和的时候,直接数组内对应两个下标一减就ok了。三、标准答案总结其实就是直接在读取数组的时候,顺便一个for循环求出来前n个数字的和,放到一个新数组里,用的时候直接两个一减就完事儿了。.........

2022-06-07 23:25:34 120

原创 4. 3 无重复字符的最长子串(mid)

题目:3 无重复字符的最长子串(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(滑动窗口)2.总结一、题目Given a string s, find the length of the longest substring without repeating characters. Example 1:Input: s = "abcabcbb"Output: 3Explanation: The answer is "abc", with the length of

2022-05-04 13:48:42 230

原创 3. 438 找到字符串中所有字母异位词(mid)

题目:438 找到字符串中所有字母异位词(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(滑动窗口)2.总结一、题目Given two strings s and p, return an array of all the start indices of p's anagrams in s. You may return the answer in any order.An Anagram is a word or phrase formed by rearranging t

2022-05-03 22:58:57 319

原创 2. 567 字符串的排列(mid)

题目:567 字符串的排列(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.滑动窗口2.总结一、题目Given two strings s1 and s2, return true if s2 contains a permutation of s1, or false otherwise.In other words, return true if one of s1's permutations is the substring of s2. Example 1:Inp

2022-04-25 23:16:55 131

原创 1. 76 最小覆盖子串(hard)

题目:76 最小覆盖子串(hard)一、题目二、 思路二、自己写的1.代码三、标准答案1.滑动窗口2.总结一、题目Given two strings s and t of lengths m and n respectively, return the minimum window substring of s such that every character in t (including duplicates) is included in the window. If there is no s

2022-04-25 22:57:19 531

原创 3. 977 有序数组的平方(easy)

题目:977 有序数组的平方(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.总结一、题目Given an integer array nums sorted in non-decreasing order, return an array of the squares of each number sorted in non-decreasing order. Example 1:Input: nums = [-4,-1,0,3,10]Output:

2022-04-19 16:49:13 58

原创 2. 344 反转字符串(easy)

题目:344 反转字符串(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.总结一、题目Write a function that reverses a string. The input string is given as an array of characters s.You must do this by modifying the input array in-place with O(1) extra memory. Example 1:

2022-04-19 15:51:32 46

原创 1. 167 两数之和II -输入有序数组(mid)

题目:167 两数之和II -输入有序数组(mid)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.总结一、题目Given a 1-indexed array of integers numbers that is already sorted in non-decreasing order, find two numbers such that they add up to a specific target number. Let these two numbers be

2022-04-19 15:33:52 149

原创 3. 283 移动零(easy)

题目:704 Binary Search(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(快慢指针)2.总结一、题目Given an integer array nums, move all 0's to the end of it while maintaining the relative order of the non-zero elements.Note that you must do this in-place without making a copy of

2022-04-18 14:49:51 130

原创 2. 26删除有序数组中的重复项(easy)

题目:26删除有序数组中的重复项(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(快慢指针)2.总结一、题目Given an integer array nums sorted in non-decreasing order, remove the duplicates in-place such that each unique element appears only once. The relative order of the elements should be kep

2022-04-18 14:16:57 53

原创 1. 27 移除元素(easy)

题目:27 移除元素(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(快慢指针)3.总结一、题目Given an integer array nums and an integer val, remove all occurrences of val in nums in-place. The relative order of the elements may be changed.Since it is impossible to change the length of

2022-04-18 14:08:22 211

原创 Test4:类的属性、变量

Test4:类的属性、变量/* 笔记: day5_4(类的属性、变量) * */public class Test4 { //语法格式:修饰符 类型 属性名 = 初始值 //修饰符(用来修饰变量,指明变量到底是公有的还是私有的):private该属性只能由该类的方法访问、使用,不能在类之外的方法访问、使用;public该属性可以被该类以外的方法访问 //类型:任何基本类型或者类 //变量的分类:成员变量和局部变量 //在方法体外,类体内声明的变量是成员变量 //在方法体

2022-04-14 23:46:12 83

原创 Test3:对象的创建和使用

Test3:对象的创建和使用/* 笔记: day5_3(对象的创建和使用) * * 使用new+构造器创建一个新的对象 */public class Test3 { public static void main(String[] args) { //实例化人类(Test2),创建person对象 Test2 person = new Test2(); //等号左边声明一个Test2类型的变量,变量名person;等号右边就是实例化 person.name = "张

2022-04-14 23:45:27 177

原创 Test2:类的写法

Test1:类的写法/* 笔记: day5_2(类的写法) * * 定义类(考虑修饰符、类名) * 编写类的属性(考虑修饰符、属性类型、属性名、初始化值) * 编写类的方法(考虑修饰符、返回值类型、方法名、形参等) * *///人的类public class Test2 { //属性(成员变量),类的成员变量可以先声明,不用初始化,类成员变量有默认值 String name; //String的默认值是null int age; //int的默认值是0

2022-04-14 23:44:08 290

原创 Test1:面向对象编程

Test1:面向对象编程/* 笔记: day5_1(面向对象编程) * 把万事万物抽象成一个一个的类,里面有属性和行为,以人举例来说就是属性-变量(高矮胖瘦)、行为-方法(吃饭、打球) */public class Test1 { public static void main(String[] args) { //用面向对象的思想去分析 //eg1:列车司机紧急刹车 //类:列车,司机 //列车的方法:刹车(){} //司机的方法:紧急刹车(){} //

2022-04-14 23:38:08 206

原创 5. 367 有效的完全平方数(easy)

题目:367 有效的完全平方数(easy)一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(完全平方数肯定是前n个连续奇数的和)3.方法三(牛顿迭代法)4.总结一、题目Given a positive integer num, write a function which returns True if num is a perfect square else False.Follow up: Do not use any built-in library func

2022-04-14 14:26:05 231

原创 4. 69 x的平方根(easy)

@[TOC](题目:69 Sqrt(x)(easy))一、题目Given a non-negative integer x, compute and return the square root of x.Since the return type is an integer, the decimal digits are truncated, and only the integer part of the result is returned.Note: You are not allowe

2022-04-13 16:40:56 68

原创 Test3:数组常见问题

Test3:数组常见问题/* 笔记: day4_8(数组常见问题) * */public class Test3 { public static void main(String[] args) { //java.lang.ArrayIndexOutOfBoundsException:数组越界,访问了数组中的不存在的脚标 int[] arr = new int[3]; System.out.println(arr[4]); //arr cannot be res

2022-04-12 23:43:28 90

原创 Test2:数组常见算法

Test2:数组常见算法/* 笔记: day4_7(数组常见算法) * */public class Test2 { public static void main(String[] args) { //求数组元素的最大值、最小值、总和、平均数 int[] arr = new int[] {1,2,38,96,4}; //最大值 int max = arr[0]; for (int i = 0; i < arr.length; i++) { if

2022-04-12 23:42:49 42

原创 Test1:多维数组

Test1:多维数组/* 笔记: day4_6(多维数组) * */public class Test1 { public static void main(String[] args) { //二维数组的动态初始化 int[][] j = new int[2][3]; int[][] k = new int[2][]; //只定义第一维的长度,第二维的不定义,第二维默认值为null //二维数组的静态初始化 int[][] i = new int[][]

2022-04-12 23:42:04 22

原创 3. 34 在排序数组中查找元素的第一个和最后一个位置(mid)

题目:XXX一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(左闭右开)3.总结题目:XXX一、题目二、 思路二、自己写的1.代码三、标准答案1.方法一(左闭右闭)2.方法二(左闭右开)3.总结Binary Search)一、题目Given an array of integers nums which is sorted in ascending order, and an integer target, write a function to search tar

2022-04-12 14:14:18 103

原创 Test2:一维数组

Test2:一维数组/* 笔记: day4_5(一维数组) * 数组是存放多个数据的集合 */public class Test2 { public static void main(String[] args) { //数组声明 int[] i; //声明了一个int的数组 //int j[]; //也行 //初始化 //1.动态初始化:声明变量且说明数组里面能放几个该数据类型的数据 int[] arr = new int[3]; //2.静态初始化

2022-04-08 23:50:19 45

原创 Test1:数据流程控制语句

Test1:数据流程控制语句/* 笔记: day4_4(特殊流程控制语句) * */public class Test1 { public static void main(String[] args) { //break结束当前所在循环 //eg1:switch中 int i = 2; switch (i) { case 1: //break终止case的 break; case 2: break; default: break;

2022-04-08 23:49:31 42

原创 Test2:嵌套循环练习

Test2:嵌套循环练习/* 笔记: 嵌套循环练习 * */public class Test2 { public static void main(String[] args) { // 九九乘法表 for (int i = 1; i <= 9; i++) { for (int j = 1; j <= i; j++) { System.out.print(i + "*" + j + "" + "=" + (i * j) + "\t"); }

2022-04-07 22:33:19 247

原创 Test1:嵌套循环

Test1:嵌套循环/* 笔记: day4_3(嵌套循环) * */public class Test1 { public static void main(String[] args) { for (int i = 0; i < 4; i++) { //每一次循环都会执行大括号里面的所有代码 System.out.println("大循环---" + i); for (int j = 0; j < 2; j++) { //大循环的次数乘以小循环的次数就

2022-04-07 22:32:37 27

原创 Test2:循环结构while do-while

Test2:循环结构while do-while/* 笔记: day4_2(循环结构 while do-while) * */public class Test2 { public static void main(String[] args) { //while int i = 0; while (i <= 100) {//获取变量i<=100的结果,是true还是false,是true执行while大括号里面的代码,是false不执行 System.

2022-04-07 22:30:48 141

原创 Test1:循环结构for

Test1:循环结构for/* 笔记: day4_1(循环结构 for) * */public class Test1 { public static void main(String[] args) { for (int i = 0; i < 5; i++) { System.out.println(i); System.out.println("hello world"); } //练习 for (int i = 1; i <= 1

2022-04-07 22:30:07 45

原创 Test5:分支结构switch

Test5:分支结构switch/* 笔记: day3_7(分支结构 switch) * switch比if-else效率高 */public class Test5 { public static void main(String[] args) { //如果数字是1输出星期一,是2输出星期二,不是1和2的时候输出不知道 int i = 1; switch (i) { case 1: //if (i == 1) System.out.println("星期一"

2022-04-07 22:28:07 38

原创 Test4:分支结构(if-else)

Test4:分支结构(if-else)/* 笔记: day3_6(分支结构 if-else) * if-else效率更高 */public class Test4 { public static void main(String[] args) { int i = 1; int k = 2; if (i == 1 && k ==2) { System.out.println(i); } //判断一个数字是奇数还是偶数,输出结果

2022-04-07 22:27:23 73

原创 Test3:顺序结构

Test3:顺序结构/* 笔记: day3_5(顺序结构) * */public class Test3 { public static void main(String[] args) { // java中定义成员变量时采用合法的前向引用 //错了,得先声明再引用// int k = i;// int i = 0; //对了 int i = 0; int k = i; }}...

2022-04-07 22:26:37 22

原创 Test2:运算符的优先级

Test2:运算符的优先级/* 笔记: day3_4(运算符的优先级) * 不经常用,直接加括号就完事儿了 */public class Test2 { public static void main(String[] args) { System.out.println(1 + 2 * 3); //7 不同级别运算符按不同级别算 System.out.println(2 * 3 % 2); //0 同一级别运算符从左到右运算 }}...

2022-04-07 22:25:56 38

原创 Test1:三元(三目运算符)

Test1:三元(三目运算符)/* 笔记: day3_3(三元(三目)运算符) * */public class Test1 { public static void main(String[] args) { int i = 1; int k = i > 0 ? 1 : 0; //最前面是个判别表达式,是true执行问号后面的,是flase执行冒号后面的 System.out.println(k); //1 //练习1 输出两数中较大的数 int m =

2022-04-07 22:25:03 52

原创 Test5:位运算符

Test5:位运算符/* 笔记: day3_2(位运算符) * 正数二进制->求反码->求补码(反码+1)->负数二进制 * 负数二进制->减1->求反码->正数二进制 */public class Test5{ public static void main(String[] args) { // 左移:<< 3 << 2 = 12 -> 3 * 2 * 2 = 12 m << n -&

2022-04-07 22:22:09 29

原创 Test4:逻辑运算符练习

Test4:逻辑运算符练习/* * 逻辑运算符练习 */public class Test4 { public static void main(String[] args) { // int x = 1;// int y = 1;// if (x++ == 2 & ++y ==2) // x = 7;// System.out.println("x=" + x + ",y=" + y); //2 2 // int x = 1;// int y

2022-04-06 23:05:46 90

原创 Test3:逻辑运算符

Test3:逻辑运算符/* 笔记: day3_1(逻辑运算符) * */public class Test3 { public static void main(String[] args) { // 逻辑运算符:& | ^ ! && || System.out.println(4 == 4 && 1 == 1); //true System.out.println(4 == 4 || 1 != 1); //true

2022-04-06 23:04:46 86

原创 Test2:比较运算符

Test2:比较运算符/* 笔记: day2_10(比较运算符) * */public class Test2 { public static void main(String[] args) { // == != < > <= >= 返回true flase System.out.println(4 == 5); //flase System.out.println(4 != 5); //true }}...

2022-04-06 23:03:42 30

原创 Test1:赋值运算符

Test1:赋值运算符/* 笔记: day2_9(赋值运算符) * */public class Test1 { public static void main(String[] args) { // 赋值运算 int i =1; short s = 2; //自动类型转换 i = s; //强制类型转换 s = (short)i; //连续赋值 int i0 = 0; int i1 = 0; int i2 = 0; i0 =

2022-04-06 23:02:51 32

原创 Test2:算术运算符练习

Test2:算术运算符练习/* * 算术运算符练习 */public class Test2 { public static void main(String[] args) { int i1 = 10, i2 = 20; int i = i1++; System.out.println(i); //10 //已经用完了i1了,所以自加 System.out.println("i1=" + i1); //11 i = ++i1; System.out

2022-04-06 22:57:54 61

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除