- 博客(13)
- 收藏
- 关注
原创 #121(122). 买卖股票的最佳时机(Ⅰ,Ⅱ)
第一版 class Solution { public int maxProfit(int[] prices) { if(prices.length<2) return 0; int max_num=0; int min_num=Integer.MAX_VALUE; int max = 0; int in...
2019-02-01 18:40:04 136
原创 #21. 合并两个有序链表
https://leetcode-cn.com/problems/merge-two-sorted-lists/ class Solution { public ListNode mergeTwoLists(ListNode l1, ListNode l2) { if(l1==null) return l2; if(l2==null) return l1; ...
2019-01-15 14:34:51 149
原创 #78. 子集
https://leetcode-cn.com/problems/subsets/ class Solution { public List<List<Integer>> subsets(int[] nums) { List<List<Integer>> subsets = new ArrayList&a
2019-01-13 18:11:42 101
原创 #236.二叉树的最近公共祖先
https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-tree/description/ 初始代码 class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { St...
2018-12-07 18:43:17 134
原创 #235. 二叉搜索树的最近公共祖先
https://leetcode-cn.com/problems/lowest-common-ancestor-of-a-binary-search-tree/description/ 初步代码(没有考虑到二叉搜索树左小右大的性质)(10ms72%) class Solution { public TreeNode lowestCommonAncestor(TreeNode root, T...
2018-12-05 11:10:43 155
原创 #9. 回文数
https://leetcode-cn.com/problems/palindrome-number/description/ 原始代码(普通写法) class Solution { public boolean isPalindrome(int x) { if(x<0) return false; String s= "&
2018-12-03 13:27:11 95
原创 #155. 最小栈
https://leetcode-cn.com/problems/min-stack/description/ 原始代码 class MinStack { ArrayList<Integer> stack; int pointer; int min; /** initialize your data structure here. */ pub...
2018-12-01 20:28:42 112
原创 #169. 求众数
https://leetcode-cn.com/problems/majority-element/description/ (学到了带标签的continue和break) class Solution { public int majorityElement(int[] nums) { int[] num = new int[nums.length]; i...
2018-11-29 22:12:55 134
原创 #100. 相同的树
https://leetcode-cn.com/problems/same-tree/description/ ①迭代 class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p==null||q==null) { if(p==null&&...
2018-11-27 23:33:07 115
原创 #637. 二叉树的层平均值
https://leetcode-cn.com/problems/average-of-levels-in-binary-tree/description/ ①迭代版本 class Solution { public List&lt;Double&gt; averageOfLevels(TreeNode root) { List&lt;Double&gt; re=new A...
2018-11-21 19:32:38 171
原创 LeetCode 682
#682. 棒球比赛 https://leetcode-cn.com/problems/baseball-game/description/ 用IDEA和用网站编译答案不一样???(IDEA正确答案) class Solution { public int calPoints(String[] ops) { int last = 0; int sum = 0...
2018-11-18 21:25:40 172
原创 leetcode 349
#349. 两个数组的交集 https://leetcode-cn.com/problems/intersection-of-two-arrays/description/ class Solution { public int[] intersection(int[] nums1, int[] nums2) { int count=0; int flag ...
2018-11-14 18:35:45 167
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人