leetcode
maozezhong0
这个作者很懒,什么都没留下…
展开
-
101. Symmetric Tree
题目:https://leetcode.com/problems/symmetric-tree/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int原创 2016-06-07 20:54:25 · 178 阅读 · 0 评论 -
66. Plus One
题目:https://leetcode.com/problems/plus-one/题意: 给定数组a[],从a[0]到a[length-1]是一个数的各位的数字,比如19,则a[0]=1,a[1]=0。让你求这个数字加一所得的各位数的数组.代码:public class Solution { public int[] plusOne(int[] digits) { int原创 2016-06-07 21:17:56 · 215 阅读 · 0 评论 -
26. Remove Duplicates from Sorted Array
题目:https://leetcode.com/problems/remove-duplicates-from-sorted-array/代码:public class Solution { public int removeDuplicates(int[] nums) { if(nums.length==0) return 0; in原创 2016-06-08 11:37:54 · 176 阅读 · 0 评论 -
118. Pascal's Triangle
题目:https://leetcode.com/problems/pascals-triangle/代码:public class Solution { public List<List<Integer>> generate(int numRows) { List<List<Integer>> res = new ArrayList<>(); ArrayLis原创 2016-06-08 11:38:40 · 191 阅读 · 0 评论 -
342. Power of Four
题目:https://leetcode.com/problems/power-of-four/代码:public class Solution { public boolean isPowerOfFour(int num) { if(num==1) return true; if(num<4) return fa原创 2016-06-08 11:39:27 · 175 阅读 · 0 评论 -
232. Implement Queue using Stacks
题目:https://leetcode.com/problems/implement-queue-using-stacks/代码:class MyQueue { Queue<Integer> stack = new LinkedList<>(); // Push element x to the back of queue. public void push(int x) {原创 2016-06-08 11:40:06 · 181 阅读 · 0 评论 -
257. Binary Tree Paths
题目:https://leetcode.com/problems/binary-tree-paths/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(i原创 2016-06-24 12:58:37 · 159 阅读 · 0 评论 -
234. Palindrome Linked List
题目:https://leetcode.com/problems/palindrome-linked-list/代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; }原创 2016-06-25 10:36:22 · 148 阅读 · 0 评论 -
14. Longest Common Prefix
题目:https://leetcode.com/problems/longest-common-prefix/代码:public class Solution { public String longestCommonPrefix(String[] strs) { int length = strs.length; if(length==0)原创 2016-06-25 10:55:52 · 177 阅读 · 0 评论 -
172. Factorial Trailing Zeroes
题目:https://leetcode.com/problems/factorial-trailing-zeroes/代码:public class Solution {public int trailingZeroes(int n) { int count = 0; while(n > 0) { n /= 5; count += n; }原创 2016-06-08 21:23:18 · 181 阅读 · 0 评论 -
102. Binary Tree Level Order Traversal
题目:https://leetcode.com/problems/binary-tree-level-order-traversal/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right;原创 2016-06-08 21:23:39 · 175 阅读 · 0 评论 -
9. Palindrome Number
题目:https://leetcode.com/problems/palindrome-number/代码:public class Solution { public boolean isPalindrome(int x) { if(x<0) return false; List<Integer> temp = new ArrayLi原创 2016-06-08 21:24:06 · 224 阅读 · 0 评论 -
119. Pascal's Triangle II
题目:https://leetcode.com/problems/pascals-triangle-ii/代码:public class Solution { public List<Integer> getRow(int rowIndex) { List<List<Integer>> temp = new ArrayList<>(); List<Intege原创 2016-06-08 21:24:36 · 148 阅读 · 0 评论 -
112. Path Sum
题目:https://leetcode.com/problems/path-sum/ 代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) {原创 2016-06-09 21:26:46 · 152 阅读 · 0 评论 -
36. Valid Sudoku
题目:https://leetcode.com/problems/valid-sudoku/代码:public class Solution { public boolean isValidSudoku(char[][] board) { int col = board.length; int cow = board[0].length; Ar原创 2016-06-09 21:27:10 · 223 阅读 · 0 评论 -
111. Minimum Depth of Binary Tree
题目:https://leetcode.com/problems/minimum-depth-of-binary-tree/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; *原创 2016-06-09 21:27:32 · 176 阅读 · 0 评论 -
225. Implement Stack using Queues
题目:https://leetcode.com/problems/implement-stack-using-queues/代码:class MyStack { // Push element x onto stack. Queue<Integer> q1 = new LinkedList<Integer>(); Queue<Integer> q2 = new LinkedL原创 2016-06-09 21:43:33 · 169 阅读 · 0 评论 -
344. Reverse String
题目:https://leetcode.com/problems/reverse-string/代码:public class Solution { public String reverseString(String s) { StringBuffer m = new StringBuffer(); for(int i=s.length()-1;i>=0;i原创 2016-06-04 21:29:16 · 170 阅读 · 0 评论 -
292. Nim Game
题目:https://leetcode.com/problems/nim-game/代码:public class Solution { public boolean canWinNim(int n) { if ( n%4 == 0 ) return false; else return true; }原创 2016-06-04 21:30:36 · 199 阅读 · 0 评论 -
258. Add Digits
题目:https://leetcode.com/problems/add-digits/代码:刚开始思考,感觉很麻烦,想到用循环来计算位数,计算和后来一想,最后的结构就在0到9之间,那么肯定是有一定的规律的,因此就有以下这种简单点方法public class Solution { public int addDigits(int num) { int m = (num-9原创 2016-06-04 21:31:20 · 161 阅读 · 0 评论 -
104. Maximum Depth of Binary Tree
题目:https://leetcode.com/problems/maximum-depth-of-binary-tree/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; *原创 2016-06-04 21:32:08 · 176 阅读 · 0 评论 -
226. Invert Binary Tree
题目:https://leetcode.com/problems/invert-binary-tree/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(原创 2016-06-04 21:33:54 · 140 阅读 · 0 评论 -
349. Intersection of Two Arrays
题目:https://leetcode.com/problems/intersection-of-two-arrays/代码:ArrayLIst <>尖括号内不能放基本类型,比如char,int,要想放int就在尖括号内放Integer:ArrayList<integer>public class Solution { public int[] intersection(int[] nu原创 2016-06-04 21:34:25 · 200 阅读 · 0 评论 -
283. Move Zeroes
题目:https://leetcode.com/problems/move-zeroes/代码:ArrayList只能用.get得到数据public class Solution { public void moveZeroes(int[] nums) { ArrayList<Integer> m = new ArrayList<Integer>(); fo原创 2016-06-04 21:34:54 · 147 阅读 · 0 评论 -
237. Delete Node in a Linked Lis
题目:https://leetcode.com/problems/delete-node-in-a-linked-list/代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val原创 2016-06-04 21:35:35 · 167 阅读 · 0 评论 -
100. Same Tree
题目:https://leetcode.com/problems/same-tree/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) {原创 2016-06-04 21:36:06 · 165 阅读 · 0 评论 -
242. Valid Anagram
题目:https://leetcode.com/problems/valid-anagram/代码:char也能用Arrays.sort()排序public class Solution { public boolean isAnagram(String s, String t) { if(s.length()!=t.length()) return原创 2016-06-04 21:36:38 · 186 阅读 · 0 评论 -
171. Excel Sheet Column Number
题目:https://leetcode.com/problems/excel-sheet-column-number/代码:public class Solution { public int titleToNumber(String s) { char[] m = s.toCharArray(); int count = m.length-1;原创 2016-06-04 21:37:17 · 144 阅读 · 0 评论 -
169. Majority Element
题目:https://leetcode.com/problems/majority-element/代码:public class Solution { public int majorityElement(int[] nums) { Arrays.sort(nums); int limit = (int)(nums.length/2.0);原创 2016-06-04 21:37:43 · 244 阅读 · 0 评论 -
217. Contains Duplicate
题目:https://leetcode.com/problems/contains-duplicate/代码:public class Solution { public boolean containsDuplicate(int[] nums) { Arrays.sort(nums); for(int i=0;i<nums.length-1;i++)原创 2016-06-04 21:38:15 · 180 阅读 · 0 评论 -
350. Intersection of Two Arrays II
题目:https://leetcode.com/problems/intersection-of-two-arrays-ii/代码:public class Solution { public int[] intersect(int[] nums1, int[] nums2) { int[] flag = new int[nums2.length]; Arra原创 2016-06-04 21:38:47 · 486 阅读 · 0 评论 -
206. Reverse Linked List
题目:https://leetcode.com/problems/reverse-linked-list/代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } *原创 2016-06-04 21:39:41 · 187 阅读 · 0 评论 -
235. Lowest Common Ancestor of a Binary Search Tree
题目:https://leetcode.com/problems/lowest-common-ancestor-of-a-binary-search-tree/代码:/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * Tre原创 2016-06-04 21:40:12 · 185 阅读 · 0 评论 -
191. Number of 1 Bits
题目:https://leetcode.com/problems/number-of-1-bits/代码:java中有三种移位运算符<< : 左移运算符,num << 1,相当于num乘以2>> : 右移运算符,num >> 1,相当于num除以2>>> : 无符号右移,忽略符号位,空位都以0补齐public class Solution {原创 2016-06-04 21:40:43 · 195 阅读 · 0 评论 -
231. Power of Two
题目:https://leetcode.com/problems/power-of-two/代码:public class Solution { public boolean isPowerOfTwo(int n) { return n>0 && Math.pow(2,(int)(Math.log(Integer.MAX_VALUE)/Math.log(2.0)))%n==0原创 2016-06-04 21:41:10 · 171 阅读 · 0 评论 -
326. Power of Three
题目:https://leetcode.com/problems/power-of-three/代码:public class Solution { public boolean isPowerOfThree(int n) { int count=0; double flag; do{ flag = Math.pow(3,原创 2016-06-04 21:41:37 · 185 阅读 · 0 评论 -
67. Add Binary
题目:https://leetcode.com/problems/add-binary/代码:public class Solution { public String addBinary(String a, String b) { int lengtha = a.length(); int lengthb = b.length(); int i原创 2016-06-26 13:14:05 · 261 阅读 · 0 评论 -
219. Contains Duplicate II
题目:https://leetcode.com/problems/contains-duplicate-ii/代码:public class Solution { public boolean containsNearbyDuplicate(int[] nums, int k) { Set<Integer> res = new HashSet<>(); for原创 2016-06-10 21:28:41 · 150 阅读 · 0 评论 -
160. Intersection of Two Linked Lists
题目:https://leetcode.com/problems/intersection-of-two-linked-lists/代码:/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) {原创 2016-06-10 21:29:07 · 161 阅读 · 0 评论 -
223. Rectangle Area
题目:https://leetcode.com/problems/rectangle-area/代码:public class Solution { public int computeArea(int A, int B, int C, int D, int E, int F, int G, int H) { int col,cow; col = Ma原创 2016-06-11 11:59:29 · 177 阅读 · 0 评论