![](https://img-blog.csdnimg.cn/20201014180756916.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode
Master_Reid
这个作者很懒,什么都没留下…
展开
-
LeetCode 136. Single Number
public class Solution { public int singleNumber(int[] nums) { int ans = 0; for (int i = 0; i < nums.length; i++) { ans ^= nums[i]; } return ans; }}原创 2015-06-24 20:46:19 · 368 阅读 · 0 评论 -
LeetCode 235. Lowest Common Ancestor of a Binary Search Tree
找最小公共祖先递归:只有两个点在根的两侧,他们的公共祖先必为当前根节点。若同侧,则定义最新的根节点。递归直到两节点分开左右,或者其一节点为根节点/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNo原创 2015-07-11 16:09:20 · 399 阅读 · 0 评论 -
LeetCode 83. Remove Duplicates from Sorted List
简单链表操作判断重复用hash/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */public class Solution { p原创 2015-07-11 16:13:50 · 373 阅读 · 0 评论 -
LeetCode 153. Find Minimum in Rotated Sorted Array
特殊序列找最小值利用二分public class Solution { public int findMin(int[] nums) { return min(nums, 0, nums.length - 1); } private static int min(int[] a, int begin, int end) {原创 2015-07-11 16:51:37 · 417 阅读 · 0 评论 -
LeetCode 191. Number of 1 Bits
public class Solution { // you need to treat n as an unsigned value public int hammingWeight(int n) { int hw = 0, shiftCount = 0; while (shiftCount++ < 32) { hw +=原创 2015-06-24 20:49:00 · 377 阅读 · 0 评论 -
LeetCode 169. Majority Element
public class Solution { public int majorityElement(int[] nums) { int len = nums.length; int counter = 0, candidate = nums[0]; for (int i : nums) { if (counter =原创 2015-06-24 21:27:03 · 346 阅读 · 0 评论 -
LeetCode 35. Search Insert Position
public class Solution { public int searchInsert(int[] nums, int target) { int len = nums.length; for (int i = len - 1; i >= 0; i--) { if (nums[i] == target) return i;原创 2015-06-24 21:02:46 · 371 阅读 · 0 评论 -
LeetCode 100. Same Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {原创 2015-06-24 20:47:37 · 357 阅读 · 0 评论 -
LeetCode 104. Maximum Depth of Binary Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {原创 2015-06-24 20:45:03 · 357 阅读 · 0 评论 -
LeetCode 226. Invert Binary Tree
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {原创 2015-06-24 21:04:19 · 298 阅读 · 0 评论 -
LeetCode 171. Excel Sheet Column Number
public class Solution { public int titleToNumber(String s) { int title = 0, time = 1; int len = s.length(); for (int i = len - 1; i >= 0; i--) { title += ((s.ch原创 2015-06-24 20:50:18 · 310 阅读 · 0 评论 -
LeetCode 217. Contains Duplicate
public class Solution { public boolean containsDuplicate(int[] nums) { Set dupli = new HashSet(); for (int i = 0; i < nums.length; i++) { if (!dupli.contains(nums[i]))原创 2015-06-24 21:01:03 · 378 阅读 · 0 评论 -
LeetCode 94. Binary Tree Inorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {原创 2015-06-24 20:59:50 · 330 阅读 · 0 评论 -
LeetCode 144. Binary Tree Preorder Traversal
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {原创 2015-06-24 20:56:05 · 365 阅读 · 0 评论 -
LeetCode 141. Linked List Cycle
/** * Definition for singly-linked list. * class ListNode { * int val; * ListNode next; * ListNode(int x) { * val = x; * next = null; * } * } */public class原创 2015-06-24 20:52:41 · 317 阅读 · 0 评论 -
LeetCode 116. Populating Next Right Pointers in Each Node
/** * Definition for binary tree with next pointer. * public class TreeLinkNode { * int val; * TreeLinkNode left, right, next; * TreeLinkNode(int x) { val = x; } * } */public class原创 2015-06-24 20:58:25 · 376 阅读 · 0 评论 -
LeetCode 108. Convert Sorted Array to Binary Search Tree
已排序数组建二叉搜索树根据性质建树即可/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */pu原创 2015-07-11 16:15:39 · 430 阅读 · 0 评论