自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 2020-12-31(367. 有效的完全平方数)

class Solution { public boolean isPerfectSquare(int num) { int i; for(i=1;i*i<num;i++){ } if(i*i==num){ return true; }else{ return false; } } }超时了。二分法可以,牛顿迭代法更可class Sol

2020-12-31 11:27:52 55

原创 2020-12-30(350. 两个数组的交集 II)

class Solution { public int[] intersect(int[] nums1, int[] nums2) { if(nums1.length>nums2.length){ return intersect(nums2,nums1); } Map<Integer,Integer> a=new HashMap<Integer,Integer>(); for(in

2020-12-30 11:20:44 44

原创 2020-12-29(349. 两个数组的交集)

class Solution { public int[] intersection(int[] nums1, int[] nums2) { Set<Integer> a=new HashSet<Integer>(); Set<Integer> c=new HashSet<Integer>(); for(int i:nums1){ a.add(i); }

2020-12-29 10:24:32 69

原创 2020-12-28(345. 反转字符串中的元音字母)

class Solution { public String reverseVowels(String s) { char[] chars = s.toCharArray(); int start=0,finish=s.length()-1; while(start<finish){ if(isyuanyin(s.charAt(start))&&isyuanyin(s.charAt(finish))){

2020-12-28 18:16:30 100

原创 2020-12-27(344. 反转字符串)

class Solution { public void reverseString(char[] s) { char temp; for(int i=0;i<s.length/2;i++){ temp=s[i]; s[i]=s[s.length-1-i]; s[s.length-1-i]=temp; } }}就这???

2020-12-27 15:18:56 181 1

原创 2020-12-26(342. 4的幂)

class Solution { public boolean isPowerOfFour(int n) { return Math.log10(n)/Math.log10(4)%1==0; }}昨天学,今天用。不错不错~

2020-12-26 11:25:36 65

原创 2020-12-25(326. 3的幂)

class Solution { public boolean isPowerOfThree(int n) { Set<Integer> a=new HashSet<Integer>(); int s=1; a.add(1); for(int i=0;i<20;i++){ s=s*3; a.add(s); } return !a

2020-12-25 12:25:13 58

原创 2020-12-24(303. 区域和检索 - 数组不可变)

class NumArray { int[] nums=new int[10010]; public NumArray(int[] nums) { this.nums=nums; } public int sumRange(int i, int j) { int sum=0; for(int k=i;k<=j;k++){ sum+=nums[k]; } re

2020-12-24 10:32:34 76 1

原创 2020-12-23(292. Nim 游戏)

class Solution { public boolean canWinNim(int n) { return n%4!=0; }}这怕这类题目,隐隐的觉得是贪心之类的算法,或者就是数学思维。然后看了结果,这就是推理。。。可恶,笑死自己。

2020-12-23 10:36:12 60

原创 2020-12-22(290. 单词规律)

class Solution { public boolean wordPattern(String pattern, String s) { Map<Character,String> a=new HashMap<>(); String [] arr = s.split("\\s+"); // for(int i=0;i<arr.length;i++){ // System.out.println

2020-12-22 10:14:09 96

原创 2020-12-21(283. 移动零)

class Solution { public void moveZeroes(int[] nums) { if(nums.length==1){ return ; } for(int i=0;i<nums.length;i++){ for(int j=i;j<nums.length-1;j++){ if(nums[j]==0){

2020-12-21 15:35:52 60

原创 2020-12-20(278. 第一个错误的版本)

/* The isBadVersion API is defined in the parent class VersionControl. boolean isBadVersion(int version); */public class Solution extends VersionControl { public int firstBadVersion(int n) { int min=1; int max=n; int mid

2020-12-20 14:33:53 73

原创 2020-12-19(268. 丢失的数字)

class Solution { public int missingNumber(int[] nums) { int length=nums.length; int temp[]=new int[length+1]; for(int i=0;i<nums.length;i++){ temp[nums[i]]=1; } for(int i=0;i<temp.length;i++){

2020-12-19 14:54:00 89 1

原创 2020-12-18(263. 丑数)

class Solution { public boolean isUgly(int num) { if(num<=0){ return false; } if(num==1) return true; while(!(num==2||num==3||num==5)){ if(num%2==0){ num/=2;

2020-12-18 09:23:31 44

原创 2020-12-17(258. 各位相加)

class Solution { public int addDigits(int num) { int temp; while(num>=10){ int temp2=0; while(num!=0){ temp=num%10; num/=10; temp2+=temp; }

2020-12-17 10:35:24 54

原创 2020-12-16(257. 二叉树的所有路径)

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { List<String> a=new ArrayList<String>(); publ

2020-12-16 14:14:12 44

原创 2020-12-15(242. 有效的字母异位词)

class Solution { public boolean isAnagram(String s, String t) { int[] temp1=new int[30]; int[] temp2=new int[30]; if(s.length()!=t.length()){ return false; } for(int i=0;i<s.length();i++){

2020-12-15 08:34:34 59

原创 2020-12-14(237. 删除链表中的节点)

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public void deleteNode(ListNode node) { node.val=node.next.val; nod

2020-12-14 09:51:51 63

原创 2020-12-13(235. 二叉搜索树的最近公共祖先)

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNod

2020-12-13 14:58:46 47

原创 2020-12-12(234. 回文链表)

class Solution { public boolean isPalindrome(ListNode head) { List<Integer> vals = new ArrayList<Integer>(); // 将链表的值复制到数组中 ListNode currentNode = head; while (currentNode != null) {

2020-12-12 23:40:37 47

原创 2020-12-11(232. 用栈实现队列)

class MyQueue { Stack<Integer> a=new Stack<>(); //存放 Stack<Integer> b=new Stack<>(); //输出 int front; /** Initialize your data structure here. */ public MyQueue() { } /** Push element x to th

2020-12-11 10:51:26 42

原创 2020-12-10(231. 2的幂)

class Solution { public boolean isPowerOfTwo(int n) { Set<Integer> a=new HashSet<>(); a.add(1); for(int i=2;i<n+1;i*=2){ a.add(i); } if(a.add(n)){ return false; }els

2020-12-10 11:45:51 65

原创 2020-12-09(228. 汇总区间)

class Solution { public List<String> summaryRanges(int[] nums) { List<String> a=new ArrayList<>(); if(nums.length==0){ return a; } int start; String temp=String.valueOf(nums[0]

2020-12-09 10:29:37 60

原创 2020-12-08(226. 翻转二叉树)

/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */class Solution { public TreeNode invertTree(TreeNode root) { if(root=

2020-12-08 16:51:21 40

原创 2020-12-07(225. 用队列实现栈)

class MyStack { Queue<Integer> queue; /** Initialize your data structure here. */ public MyStack() { queue = new LinkedList<Integer>(); } /** Push element x onto stack. */ public void push(int x) { i

2020-12-07 15:18:39 63 1

原创 2020-12-06(219. 存在重复元素 II)

class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { Set<Integer> a=new HashSet<>(); for(int i=0;i<nums.length;i++){ if(i>k){ a.remove(nums[i-k-1]); }

2020-12-06 12:33:45 55

原创 2020-12-05(217. 存在重复元素)

class Solution { public boolean containsDuplicate(int[] nums) { Set<Integer> a=new HashSet<>(); for(int i=0;i<nums.length;i++){ if(!a.add(nums[i])){ return true; } }

2020-12-05 13:25:02 38

原创 2020-12-04(206. 反转链表)

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode reverseList(ListNode head) { ListNode result=null;

2020-12-04 14:46:16 37

原创 2020-12-03(205. 同构字符串)

class Solution { public boolean isIsomorphic(String s, String t) { int a1[]=new int[300]; List<Integer> b1=new ArrayList<>(); int temp1=1; if(s.length()!=t.length()){ return false; }

2020-12-03 17:49:44 93

原创 2020-12-02(204. 计数质数)

class Solution { public int countPrimes(int n) { int result=0; for(int i=2;i<n;i++){ if(isPrimes(i)){ result++; } } return result; } boolean isPrimes(int n){ for

2020-12-02 11:07:35 54

原创 2020-12-01(203. 移除链表元素)

/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */class Solution { public ListNode removeElements(ListNode head, int val) { ListNode head2=nul

2020-12-01 14:53:31 37

空空如也

空空如也

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

TA关注的人

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