自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 【java】43. Multiply Strings

问题原文https://leetcode-cn.com/problems/multiply-strings/description/ //任意一个整数和长度为1的整数相乘 public String helpFun(String x,String y){ StringBuilder res = new StringBuilder(); int ...

2018-08-28 18:06:35 203

原创 【java】100. Same Tree

问题原文https://leetcode-cn.com/problems/same-tree/description/ public boolean isSameTree(TreeNode p, TreeNode q) { if(p == null && q == null) return true; if(p == null || q == ...

2018-08-27 19:08:46 173

原创 【java】645. Set Mismatch

问题原文https://leetcode-cn.com/problems/set-mismatch/description/找出重复的元素,利用TABLE数组记录那个数没有在输入中出现,那么这个数就是我们要找的那个被覆盖的数。public int[] findErrorNums(int[] nums) { int max = nums.length; int[] ...

2018-08-22 16:36:19 237

原创 【java】290. Word Pattern

问题原文https://leetcode-cn.com/problems/word-pattern/description/public boolean wordPattern(String pattern, String str) { if(pattern == null && str == null) return true; if(pattern == null |...

2018-08-22 15:33:50 131

原创 【java】274. H-Index

问题原文https://leetcode.com/problems/h-index/description/public int hIndex(int[] citations) { Arrays.sort(citations); int len = citations.length; int res = 0; for(int i...

2018-08-09 16:35:11 226

原创 【java】114. Flatten Binary Tree to Linked List

问题原文https://leetcode-cn.com/problems/flatten-binary-tree-to-linked-list/description/方法:递归public void flatten(TreeNode root) { if(root == null) return; TreeNode left = root.left; ...

2018-08-09 15:25:43 235

原创 【java】592. Fraction Addition and Subtraction

问题原文https://leetcode-cn.com/problems/fraction-addition-and-subtraction/description/代码主要分为三个部分一、最简分数比需要用到辗转相除法,求出最大公因数。所以第一个函数用来获取两者之间的最大公因数二、获取一个字符串里面的第一个分数三、递归进行计算 public int division(int ...

2018-08-08 15:21:03 229

原创 【java】518. Coin Change 2

问题原文https://leetcode-cn.com/problems/coin-change-2/description/动态规划:)到达目前金额数的方式只与前面的金额数到达方式有关。dp[i]为到达该目标金额数的方式个数假设目前所要到达的金额数目标为1,coins选择有1,2,5。那么dp[1]+=dp[1-coins[0]]=dp[1-1]=dp[0],也就是说我们可以在c...

2018-08-07 17:00:19 342

原创 【java】498. Diagonal Traverse

问题原文https://leetcode-cn.com/problems/diagonal-traverse/description/ public int[] findDiagonalOrder(int[][] matrix) { int r = matrix.length; if(r == 0) return new int[0]; int...

2018-08-04 15:25:07 199

原创 【java】457. Circular Array Loop

问题原文https://leetcode-cn.com/problems/circular-array-loop/description/public boolean circularArrayLoop(int[] nums) { if(nums.length<2) return false; int size = nums.length; ...

2018-08-04 14:28:44 317

原创 【java】485. Max Consecutive Ones

问题原文https://leetcode-cn.com/problems/max-consecutive-ones/description/这道题很简单,不多说。public int findMaxConsecutiveOnes(int[] nums) { if(nums.length == 1) { if(nums[0] == 0) return 0 ; e...

2018-08-01 20:52:38 167

原创 【java】872. Leaf-Similar Trees

问题原文https://leetcode-cn.com/problems/leaf-similar-trees/description/这道题的思路很简单,就是进行后序遍历。public boolean leafSimilar(TreeNode root1, TreeNode root2) { List<Integer> l1 = new LinkedList...

2018-07-31 20:10:47 441

原创 【java】319. Bulb Switcher

问题原文https://leetcode-cn.com/problems/bulb-switcher/description/不动脑子的做法就是for双层循环,显而易见会超时。于是寻求新的想法。举个例子,第八个位置的灯泡,在第一、二、四、八轮会被转换开关,最后是暗的。第九个位置的灯泡,在第一、三、九轮会被转换开关,最后是亮的。所以总结来看,完全平方数位置的灯泡在操作结束之后会是亮的...

2018-07-28 22:16:16 158

原创 【java】77. Combinations

原文链接https://leetcode-cn.com/problems/combinations/description/class Solution { List<List<Integer>> res = new LinkedList<>(); public List<List<Integer>> combine(in...

2018-07-28 21:23:18 210

原创 【java】496. Next Greater Element I

问题链接https://leetcode-cn.com/problems/next-greater-element-i/description/public int[] nextGreaterElement(int[] nums1, int[] nums2) { int[] res = new int[nums1.length]; Map<Intege...

2018-07-25 11:56:45 294

原创 【java】622. Design Circular Queue

原文链接https://leetcode-cn.com/problems/design-circular-queue/description/这个就是基础的循环队列的相关问题。问题难点主要是判断空和满的情况。class MyCircularQueue { int[] queue; int front; int rear; int size; /*...

2018-07-23 18:03:34 1106

原创 【java】704. Binary Search

问题原文https://leetcode-cn.com/problems/binary-search/description/public int search(int[] nums, int target) { int i = 0; int j = nums.length-1; if(target<nums[i] || target&g...

2018-07-23 15:40:02 225

原创 【java】703. Kth Largest Element in a Stream

问题原文https://leetcode-cn.com/problems/kth-largest-element-in-a-stream/description/这道题的技巧是在队列里面维护k个元素。class KthLargest { int k; PriorityQueue<Integer> queue; public KthLargest(int...

2018-07-20 18:31:13 828 2

原创 【java】在无序数组中寻找Kth大元素

public int portition(int[] nums,int left,int right) { int key = nums[left]; int i = left; int j = right; while(i<j) { if(nums[j]>key) { if(nums[i]<key) { int tmp = nums[...

2018-07-20 16:27:28 467

原创 【java】快速排序

public void quickSort(int[] nums,int left,int right) { if(left>=right) return; int key = nums[left]; int i = left; int j = right; while(i<j) { if(nums[j]<key) { if(nums[i]&g...

2018-07-20 15:57:32 96

原创 【java】700. Search in a Binary Search Tree

问题原文https://leetcode-cn.com/problems/search-in-a-binary-search-tree/description/public TreeNode searchBST(TreeNode root, int val) { if(root == null) return null; if(root.val == val)...

2018-07-20 15:12:14 537

原创 【java】633. Sum of Square Numbers

问题原文https://leetcode-cn.com/problems/sum-of-square-numbers/description/解决这道题的过程中,了解到完全平方数的一个性质,在这里记录一下有关问题代码如下,时间复杂度为lgn public boolean judgeSquareSum(int c) { int i = 0; int j = (int)Mat...

2018-07-20 14:26:14 214

原创 【java】429. N-ary Tree Level Order Traversal

问题原文https://leetcode-cn.com/problems/n-ary-tree-level-order-traversal/description/public List<List<Integer>> levelOrder(Node root) { List<List<Integer>> res = new Li...

2018-07-20 13:12:26 447 1

原创 【java】589. N-ary Tree Preorder Traversal

问题原文如下https://leetcode-cn.com/problems/n-ary-tree-preorder-traversal/description/递归法public List<Integer> preorder(Node root) { List<Integer> res = new LinkedList<>(); ...

2018-07-19 19:32:10 586

原创 【java】559. Maximum Depth of N-ary Tree

原文链接https://leetcode-cn.com/problems/maximum-depth-of-n-ary-tree/description/这道题的方法对很多二叉树的问题都十分试用,逻辑很简单,就是一层一层遍历。public int maxDepth(Node root) { if(root == null) return 0 ; int r...

2018-07-19 16:56:15 1288 1

原创 【java】836. Rectangle Overlap

问题原文https://leetcode-cn.com/problems/rectangle-overlap/description/这道题我刚开始在想枚举重叠的可能情况,后来发现太多了,于是我想着枚举不可能的情况,果然思路更简单了。public boolean isRectangleOverlap(int[] rec1, int[] rec2) { i...

2018-07-17 08:55:56 307

原创 【java】849. Maximize Distance to Closest Person

问题原文点击打开链接今天心情不好,不多说,上代码。 public int maxDistToClosest(int[] seats) { Stack<Integer> stack = new Stack<>(); for (int i = 0;i<seats.length;i++){ if (seats[i] =...

2018-07-13 17:24:13 290

原创 【java】594. Longest Harmonious Subsequence

问题原文点击打开链接注意问题中的序列,并不要求连续,所以只需要统计在数组中,符合差为1的数对出现的次数就可以了。 public int findLHS(int[] nums) { if (nums.length == 0 || nums.length == 1) return 0; Map<Integer,Integer> map = new Ha...

2018-07-09 11:27:24 173

原创 【java】521. Longest Uncommon Subsequence I

问题原文点击打开链接换个思路想一想,独特的子序列,那么两者中最长的字符串肯定不会有人和它重复。真的是横看成岭侧成峰呀public int findLUSlength(String a, String b) { if (a.equals(b)) return -1; return Math.max(a.length(),b.length()); }...

2018-07-09 10:38:21 134

原创 【java】628. Maximum Product of Three Numbers

问题原文点击打开链接先对这道题进行排序,然后排序前三的整数相乘。但是要考虑两种特殊情况,第一是数组里面包含负整数的情况,第二种是前三里面包含0的情况。分开讨论问题就很简单了。public void intiHeap(int[] nums,int length,int parent){ int val = nums[parent]; int child = 2*par...

2018-07-09 10:09:19 166

原创 【java】784. Letter Case Permutation

问题原文点击打开链接对于这道题的思考,我是把字符串想象成树的结构去理解的。如果遇到字母字符,就意味着该节点有两个儿子。否则一个儿子。要保留前面的结果,其实也就是回溯法的思想。 List<String> res = new LinkedList<>();//设置一个全局变量作为返回值 public List<String> letterCasePer...

2018-07-07 18:27:33 208

原创 【java】747. Largest Number At Least Twice of Others

问题原文点击打开链接这道题简单的不用思考..... public int dominantIndex(int[] nums) { int maxVal = Integer.MIN_VALUE; int pos = 0; for (int i = 0;i<nums.length;i++){ if (nums[i] &...

2018-07-07 17:07:50 166

原创 【java】598. Range Addition II

问题原文点击打开链接这道题需要动点小脑筋,全部操作里面,重复最多次的肯定是范围最小的,所以我们只要找出涉及到的最小行和列就行啦 public int maxCount(int m, int n, int[][] ops) { if (ops.length == 0 || ops[0].length==0) return m*n; int length = op...

2018-07-06 18:31:10 117

原创 【java】234. Palindrome Linked List

问题原文点击打开链接问题一开始的思路就是反转链表,但是如果直接对原始链表进行反转,而且不使用额外储存空间,是无法比较的。但是使用了额外的存储空间不符合题目要求的。所以最后的想法是,对链表后半段进行反转,将反转后的半段链表和前半段链表进行比较。代码如下 //反转链表 public ListNode reverse(ListNode head){ if (head == nu...

2018-07-06 10:05:29 318

原创 【java】812. Largest Triangle Area

问题原文点击打开链接问题难度easy,代码如下 public double area(int[] x,int[] y,int[] z){ return 0.5*(x[0]*y[1]+y[0]*z[1]+z[0]*x[1]-x[0]*z[1]-y[0]*x[1]-z[0]*y[1]); } public double largestTriangleArea(i...

2018-07-06 09:10:03 308

原创 405. Convert a Number to Hexadecimal

问题原文点击打开链接这道题难度为easy,但是十分的繁琐。由于没有用到库函数,所以代码非常冗长。做好这道题的前提要了解原码、补码的概念,还有清楚解决INT型负整数的临界值。代码如下 //反转字符串 public String reverse(String code){ char[] tmp = code.toCharArray(); for (int ...

2018-07-05 14:24:51 85

原创 162. Find Peak Element【java】

问题原文地址点击打开链接代码如下 public int findPeakElement(int[] nums) { if (nums.length == 0 || nums == null) return 0 ; if (nums.length == 1) return 0; int[] left = new int[nums.length];...

2018-07-04 11:18:04 250

原创 203. Remove Linked List Elements【java】

问题原文地址点击打开链接对链表最基础的处理。代码已写注释。代码如下 public ListNode removeElements(ListNode head, int val) { if (head == null) return head; ListNode current = head;//移动的指针 ListNode pre = null...

2018-07-04 10:43:15 298

原创 674. Longest Continuous Increasing Subsequence

问题原文地址点击打开链接这道题难度easy,时间复杂度O(N)。代码如下 public int findLengthOfLCIS(int[] nums) { if (nums.length == 0 || nums == null) return 0 ; if (nums.length == 1) return 1; int maxlength...

2018-07-04 10:26:09 81

原创 Lemonade Change

柠檬水找零原题如下点击打开链接这道题难度easy。没啥难点可言。代码如下 public boolean lemonadeChange(int[] bills) { int[] money = new int[11];//两种美元的数量 for (int i = 0;i<bills.length;i++){ if (bills[i]...

2018-07-04 10:12:43 193

空空如也

空空如也

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

TA关注的人

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