自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

翻译 3. 无重复字符的最长子串

class Solution { public int lengthOfLongestSubstring(String s) { int n = s.length(); int res = 0; int end=0,start=0; Set<Character> set=new HashSet<>();...

2019-08-20 16:18:13 109

翻译 1.两数之和

1.两数之和class Solution { public int[] twoSum(int[] nums, int target) { int[] res = new int[2]; if(nums == null || nums.length <=1) return res; HashMap<Integer, Integer...

2019-08-20 15:18:49 109

翻译 557. 反转字符串中的单词 III

class Solution { public String reverseWords(String s) { String [] words=s.split(" "); StringBuilder res=new StringBuilder(); for(String word:words){ res.append(...

2019-06-29 10:32:27 115

翻译 344. 反转字符串

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

2019-06-26 15:04:20 159

翻译 292. Nim 游戏

class Solution { public boolean canWinNim(int n) { int val = n%4; if(val >= 1 && val <= 3) return true; return false; }}...

2019-06-26 14:37:24 129

翻译 237. 删除链表中的节点

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

2019-06-23 16:49:27 112

翻译 236. 二叉树的最近公共祖先

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

2019-06-20 22:30:30 269

翻译 235. 二叉搜索树的最近公共祖先

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

2019-06-20 21:46:09 196

翻译 231. 2的幂

class Solution { public boolean isPowerOfTwo(int n) { if(n==1) return true; if(n>=2 && n%2==0) return isPowerOfTwo(n/2); return false; ...

2019-06-19 12:54:31 85

翻译 230. 二叉搜索树中第K小的元素

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

2019-06-19 12:41:22 115

翻译 217. 存在重复元素

class Solution { public boolean containsDuplicate(int[] nums) { int length = nums.length; HashSet<Integer> set = new HashSet<>(); for(int i = 0;i<length;i++)...

2019-06-17 21:35:01 90

翻译 215. 数组中的第K个最大元素

class Solution { public int findKthLargest(int[] nums, int k) { Arrays.sort(nums); return nums[nums.length-k]; }}

2019-06-17 21:22:34 155

翻译 169. 求众数

class Solution { public int majorityElement(int[] nums) { Map<Integer,Integer> map = new HashMap<Integer,Integer>(); int n = nums.length; for(int num : nums){...

2019-06-16 19:10:14 140

翻译 160. 相交链表

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

2019-06-13 22:27:05 87

翻译 155. 最小栈

class MinStack { private Stack<Integer> stack; private Stack<Integer> minStack; /** initialize your data structure here. */ public MinStack() { stack = new Stack&...

2019-06-13 22:00:26 85

翻译 146. LRU缓存机制

class LRULinkedHashMap<K,V> extends LinkedHashMap<K,V> { //定义缓存的容量 private int capacity; private static final long serialVersionUID = 1L; //带参数的构造器 LRULinkedHashMap(int...

2019-06-13 21:46:02 100

翻译 148. 排序链表

/*** Definition for singly-linked list.* public class ListNode {* int val;* ListNode next;* ListNode(int x) { val = x; }* }*/class Solution { public ListNode sortList(Li...

2019-06-10 22:56:33 81

翻译 142. 环形链表 II

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

2019-06-09 20:01:50 81

翻译 141. 环形链表

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

2019-06-08 22:19:52 79

翻译 136. 只出现一次的数字

class Solution { public int singleNumber(int[] nums) { int result = 0; for(int i : nums) { result ^= i; } return result; }}思路:异或运算...

2019-06-07 13:47:23 74

翻译 124. 二叉树中的最大路径和

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

2019-06-06 20:36:21 87

翻译 122. 买卖股票的最佳时机 II

class Solution { public int maxProfit(int[] prices) { if(prices == null) return 0; if(prices.length < 2) return 0; int ret = 0; for(int i = 1;i<prices.length;...

2019-06-06 20:00:52 120

翻译 121. 买卖股票的最佳时机

class Solution { public int maxProfit(int[] prices) { int minprice = Integer.MAX_VALUE; int maxprofit = 0; for (int i = 0; i < prices.length; i++) { if (pric...

2019-06-05 19:33:46 77

翻译 104. 二叉树的最大深度

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

2019-06-05 19:20:15 87

翻译 89. 格雷编码

class Solution { public List<Integer> grayCode(int n) { int size = 1 << n; List<Integer> res = new ArrayList<>(); for(int i=0;i<size;i++){...

2019-06-04 22:49:27 85

翻译 88. 合并两个有序数组

class Solution { public void merge(int[] nums1, int m, int[] nums2, int n) { int []res = new int[m+n]; int i=0,j=0,cnt=0; //遍历两个数组,将较小的值依次赋给res数组 while(i<m&&...

2019-06-03 15:05:22 177

翻译 78. 子集

class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> res = new ArrayList<List<Integer>>(); List<Integer> ...

2019-06-02 14:59:46 82

翻译 70. 爬楼梯

class Solution { public int climbStairs(int n) { if(n==1) return 1; int step=0; int step1=1,step2=1; for(int i=1;i<n;i++) { step=...

2019-06-01 20:29:33 69

翻译 62. 不同路径

class Solution { public int uniquePaths(int m, int n) { if (m <= 0 || n <= 0) return 0; int[][] a = new int[m][n]; for (int i = 0; i < m; i++) a[i][0] = 1;...

2019-05-31 20:24:53 84

翻译 61. 旋转链表

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

2019-05-30 16:48:48 89

翻译 59. 螺旋矩阵 II

class Solution { public int[][] generateMatrix(int n) { int [][]res = new int [n][n]; int left = 0; int right = n-1; int top = 0; int bottom = n-1; ...

2019-05-29 12:17:46 92

翻译 54. 螺旋矩阵

class Solution { public List<Integer> spiralOrder(int[][] matrix) { if (matrix == null || matrix.length == 0) return new ArrayList<>(); int left = 0, right = matrix[0]....

2019-05-28 22:18:07 113

翻译 53. 最大子序和

class Solution { public int maxSubArray(int[] nums) { if(nums == null || nums.length == 0){ return 0; } int local = nums[0]; int global = nums[0];...

2019-05-27 20:17:38 84

翻译 46. 全排列

class Solution { public List<List<Integer>> permute(int[] nums) { if (nums == null || nums.length == 0) return new ArrayList<List<Integer>>(); List<List&l...

2019-05-26 17:39:28 128

翻译 43. 字符串相乘

class Solution { public String multiply(String num1, String num2) { int[] res = new int[num1.length() + num2.length()]; int temp = 0; for (int i = num1.length() - 1; i >...

2019-05-25 19:58:01 90

翻译 33. 搜索旋转排序数组

class Solution { public int search(int[] nums, int target) { if(nums==null||nums.length<1) return -1; int left = 0; int right = nums.length - 1; while (left <...

2019-05-24 17:11:49 88

翻译 26. 删除排序数组中的重复项

if(nums==null||nums.length==0){ return 0; } int cur=0; for(int pre=0;pre<nums.length;pre++){ if(nums[cur]!=nums[pre]){ cur++;...

2019-05-23 19:33:54 97

翻译 23. 合并K个排序链表

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

2019-05-22 22:42:51 86

翻译 21. 合并两个有序链表

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

2019-05-21 20:01:08 92

翻译 20. 有效的括号

class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<>(); char[] chs = s.toCharArray(); int len = chs.length; if((len&...

2019-05-20 19:26:13 121

空空如也

空空如也

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

TA关注的人

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