![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
LeetCode OJ
cgfankai
这个作者很懒,什么都没留下…
展开
-
52. N-Queens II
public class Solution { private final static Set occupiedCols = new HashSet(); private final static Set occupiedDiag1s = new HashSet(); private final static Set occupiedDiag2s = new HashSet();原创 2016-03-01 14:17:23 · 206 阅读 · 0 评论 -
318. Maximum Product of Word Lengths
public class Solution { public int maxProduct(String[] words) { int max = 0 ; int[] masks = new int[words.length]; for (int i = 0; i < masks.length; i++) { for (char c :原创 2016-02-29 09:39:00 · 154 阅读 · 0 评论 -
268. Missing Number
public class Solution { public int missingNumber(int[] nums) { int[] copy = new int[nums.length+1]; copy[0] = 1; for (int i = 0; i < nums.length; i++) { copy[nums[i]] =原创 2016-02-26 14:47:01 · 148 阅读 · 0 评论 -
169. Majority Element
public class Solution { public int majorityElement(int[] nums) { HashMap elementNum = new HashMap(nums.length/2); for (int element : nums) { if (elementNum.containsKey(element原创 2016-02-25 19:03:29 · 148 阅读 · 0 评论 -
217. Contains Duplicate
解法一:public class Solution { public boolean containsDuplicate(int[] nums) { HashSet hasSet = new HashSet<>(); for (int i = 0; i < nums.length; i++) { if (hasSet.contains(nums[i原创 2016-02-25 10:00:13 · 125 阅读 · 0 评论 -
171. Excel Sheet Column Number
public class Solution { public int titleToNumber(String s) { String _27String = s.toLowerCase(); int res = 0; for (int i = 0; i < _27String.length(); i++) { res = (i原创 2016-02-25 09:24:16 · 134 阅读 · 0 评论 -
122. Best Time to Buy and Sell Stock II
解法一: public class Solution { public int maxProfit(int[] prices) { if (prices.length<2) return 0; int sumProfit = 0,startIndex = 0; for (int i = 1; i < prices.length; i++) {原创 2016-02-25 08:57:23 · 151 阅读 · 0 评论 -
238. Product of Array Except Self
解法一: public class Solution { public int[] productExceptSelf(int[] nums) { int product=1,zeroNum = 0; int res[] = new int[nums.length]; for (int i : nums) { if (i!=0) { product*=原创 2016-02-24 10:09:12 · 238 阅读 · 0 评论 -
100. Same Tree
解法一: public class solution { public boolean isSameTree(TreeNode p, TreeNode q) { if (p==null&&q==null) { return true; } if (p==null&&q!=null) { return f原创 2016-02-23 12:40:06 · 161 阅读 · 0 评论 -
260. Single Number III
解法一: public class Solution { public int[] singleNumber(int[] nums) { int[] copyNum = new int[nums.length]; LinkedList list = new LinkedList(); for (int i : nums) { if (list.cont原创 2016-02-24 08:53:15 · 176 阅读 · 0 评论 -
283. Move Zeroes
解法一:public void moveZeroes(int[] nums) { if (nums.length==1) { return; } int zeroNum=0; for (int i = 0; i < nums.length-zeroNum; i++) { if (nums[i]==0) { for (int j =原创 2016-02-23 10:53:39 · 135 阅读 · 0 评论 -
226. Invert Binary Tree
解法一: public TreeNode invertTree(TreeNode root) { ArrayDeque queue = new ArrayDeque(); queue.add(root); while (!queue.isEmpty()) { TreeNode temp1 = queue.pollFirst(); TreeNode temp2 = t原创 2016-02-23 11:00:11 · 177 阅读 · 0 评论 -
237. Delete Node in a Linked List
public void deleteNode(ListNode node) { node.val = node.next.val; node.next=node.next.next; }原创 2016-02-23 10:58:56 · 221 阅读 · 0 评论 -
206. Reverse Linked List
/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ public class Solution { public ListNode reve原创 2016-03-01 14:51:39 · 163 阅读 · 0 评论 -
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 {原创 2016-02-29 10:07:21 · 142 阅读 · 0 评论