- 博客(59)
- 资源 (3)
- 收藏
- 关注
原创 leetcode 415. Add Strings
/** * 415. Add Strings * @param num1 * @param num2 * @return * 2017年3月16日下午9:22:21 */public String addString(String num1, String num2) { int idx1 = num1.length()-1; int idx2 = num2.length()-1
2017-03-16 21:51:52
398
原创 leetcode 268. Missing Number
/** * 268. Missing Number * @param nums * @return * 2017年3月16日下午9:10:15 */public int missingNumber(int[] nums) { int res = 0; for (int i = 0; i<nums.length; i++) res ^= i^nums[i]; return re
2017-03-16 21:16:39
304
原创 leetcode 217. Contains Duplicate
/** * 217. Contains Duplicate * @param nums * @return * 2017年3月15日上午10:29:39 */public boolean containsDuplicate(int[] nums) { if (nums == null || nums.length<2) return false; HashSet set = n
2017-03-15 10:48:49
321
原创 leetcode 409. Longest Palindrome
/** * 409. Longest Palindrome * @param s * @return * 2017年3月14日下午2:08:28 */public int longestPalindrome(String s) { int[] alpha = new int[52];// A-Za-z for (int i = 0; i < s.length(); i++) {
2017-03-14 14:33:42
327
原创 leetcode 242. Valid Anagram
/** * 242. Valid Anagram * @param s * @param t * @return * 2017年3月14日下午1:48:13 */public boolean isAnagram(String s, String t) { if (s.length() != t.length()) return false; int[] alpha = new
2017-03-14 13:55:27
297
原创 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 {
2017-03-13 14:49:00
209
原创 leetcode 122 Best Time to Buy and Sell Stock II
public class Solution { public int maxProfit(int[] prices) { int total = 0; for (int i = 0; i < prices.length-1; i++) if (prices[i+1] > prices[i]) total
2017-03-13 14:16:30
238
原创 leetcode 495. Teemo Attacking
/** * 495. Teemo Attacking * @param timeseries * @param duration * @return * 2017年3月12日下午9:16:40 */public int findPoisonedDuration(int[] timeSeries, int duration) { if (timeSeries.length == 0)
2017-03-12 21:30:19
278
原创 leetcode 442. Find All Duplicates in an Array
/** * 442. Find All Duplicates in an Array * @param nums * @return * 2017年3月11日下午3:13:04 */public List findDuplicates(int[] nums) { List lst = new ArrayList(); int[] cnt = new int[nums.length+
2017-03-11 15:23:44
274
原创 leetcode 338. Counting Bits
/** * 338. Counting Bits * 因为是二进制,采用移位分析,可知f[i] = f[i/2]+(i&1); * (i&1) 是代表奇偶差别, 注:+优先级比&高 * @param num * @return * 2017年3月11日下午2:43:15 */ public int[] countBits
2017-03-11 14:56:32
218
原创 leetcode 122. Best Time to Buy and Sell Stock II
/** * 122. Best Time to Buy and Sell Stock II * 一次遍历,记录最小价格(买入),计算最大利润(卖出-买入) * @param prices * @return * 2017年3月10日下午12:56:43 */ public int maxProfit(int[] prices) {
2017-03-11 14:23:54
213
原创 leetcode 387. First Unique Character in a String
public class Solution { public int firstUniqChar(String s) { int[] alphabet = new int[26]; for(char c: s.toCharArray()) alphabet[c-'a'] ++; for (int i=0;i<s.length(); i++)
2017-03-10 11:32:57
291
原创 leetcode 168. Excel Sheet Column Title
public class Solution { public String convertToTitle(int n) { int temp = n; StringBuilder sbdr = new StringBuilder(); while (temp != 0) { sbdr.append((char)('A'+(temp-1)%26
2017-03-09 18:29:27
229
原创 leetcode 171. Excel Sheet Column Number
public class Solution { public int titleToNumber(String s) { int num = 0; for (int i = s.length()-1; i>=0; i--) num += (s.charAt(i) - 'A'+1)*Math.pow(26, s.length()-i-1);
2017-03-09 16:42:23
207
原创 leetcode 349. Intersection of Two Arrays
public class Solution { public int[] intersection(int[] nums1, int[] nums2) { Set s1 = new HashSet(); Set s2 = new HashSet(); for (int i: nums1) s1.add(Integer.valueOf(i));
2017-03-09 16:15:53
249
原创 leetcode 504. Base 7
public class Solution { public String convertToBase7(int num) { if (num == 0) return "0"; String res = ""; int temp = num; int remainder = temp % 7; while (temp
2017-03-09 16:14:52
242
原创 leetcode 453. Minimum Moves to Equal Array Elements
public class Solution { // 将每次n-1个数加1直到数列全都相等,与每次将数列一个元素减一直到数列值都相等,需要的操作次数相等 public int minMoves(int[] nums) { int sum = 0; int min = Integer.MAX_VALUE; for (int val : nums )
2017-03-08 16:47:11
281
原创 leetcode 455. Assign Cookies
public class Solution { public int findContentChildren(int[] g, int[] s) { Arrays.sort(g); Arrays.sort(s); int idxG = 0, idxS = 0; while(idxG<g.length && idxS < s.length ) {
2017-03-08 15:31:34
249
原创 leetcode 404. Sum of Left Leaves
/** * Definition for a binary tree node. * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) { val = x; } * } */public class Solution {
2017-03-07 14:02:08
212
原创 leetcode 383. Ransom Note
public class Solution { public boolean canConstruct(String ransomNote, String magazine) { int[] alphabet1 = new int[26]; int[] alphabet2 = new int[26]; for (char c: ransomN
2017-03-07 13:26:14
237
原创 leetcode 167. Two Sum II - Input array is sorted
public class Solution { public int[] twoSum(int[] numbers, int target) { int front = 0, end = numbers.length-1; int sum = numbers[front]+numbers[end]; while(sum!=target) {
2017-03-06 12:12:41
404
原创 leetcode 506. Relative Ranks
import java.util.Set;import java.util.TreeSet;/** * 506. Relative Ranks * @author tangmin * @create 2017年3月6日 上午11:53:43 */public class RelativeRanks { Set treeSet = new TreeSet(); public St
2017-03-06 11:54:36
324
原创 leetcode 283. Move Zeroes
public class Solution { public void moveZeroes(int[] nums) { int idx = 0; for (int i=0;i<nums.length;i++) if(nums[i]!=0) nums[idx++] = nums[i]; for (;idx<nums.length
2017-03-05 14:31:57
225
原创 leetcode
private ArrayList nodes = new ArrayList(); public int getMinimumDifference(TreeNode root) { traverse(root); // 中序遍历,并将结果按顺序存放起来,根据BST的性质 int min = Integer.MAX_VALUE; for(int i =
2017-03-04 16:03:34
211
原创 leetcode 492. Construct the Rectangle
public int[] constructRectangle(int area) { int sqrt = (int)Math.sqrt(area); int len =sqrt,wid=sqrt; while(true){ int mul = len*wid; if(mul==area) r
2017-03-04 14:23:09
281
原创 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 {
2017-03-03 13:45:58
189
原创 leetcode 104. Maximum Depth of Binary Tree
/** * 104. Maximum Depth of Binary Tree * @param root * @return * 2017年3月3日上午11:16:00 */ public int maxDepth(TreeNode root) { TreeNode pTreeNode = root; if
2017-03-03 11:33:40
216
原创 leetcode 371. Sum of Two Integers
public class Solution { public int getSum(int a, int b) { if (b ==0 ) { return a; } int sum = a^b; int car = (a&b)<<1; return getSum(sum, car); }}
2017-03-02 14:05:37
184
原创 leetcode 448. Find All Numbers Disappeared in an Array
public class Solution { public List findDisappearedNumbers(int[] nums) { int[] arr = new int[nums.length+1]; for (int i = 0; i < nums.length; i++) { arr[nums[i]] = 1; }
2017-03-01 13:01:48
218
原创 leetcode 136. Single Number
public class Solution { public int singleNumber(int[] nums) { int single = nums[0]; for (int i = 1; i < nums.length; i++) { single ^=nums[i]; } return single; }}
2017-03-01 11:00:27
201
原创 leetcode 520. Detect Capital
public class Solution { public boolean detectCapitalUse(String word) { char[] arr = word.toCharArray(); // 0-all lower case; 1- all upper case; 2-first Upper rest Lower if (arr.length<
2017-03-01 10:48:35
256
原创 leetcode 485. Max Consecutive Ones
/** * leetcode 485. Max Consecutive Ones * @param nums * @return * 2017年2月28日下午3:39:21 */ public int findMaxConsecutiveOnes(int[] nums) { int maxLen = 0; int count = 0; for (int
2017-02-28 16:03:28
229
原创 leetcode 463. Island Perimeter
/** * leetcode 463. Island Perimeter * @param grid * @return * 2017年2月28日下午3:06:42 */ public int islandPerimeter(int[][] grid) { int perimeter = 0; for (int i = 0; i < grid.length; i++)
2017-02-28 15:27:26
306
原创 leetcode 496. Next Greater Element I
import java.util.HashMap;/** * * Feb 27, 2017 2:39:11 PM * @author tangmin * */public class NextGreaterElement { public static void main(String[] args) { // TODO Auto-generated method st
2017-02-27 15:10:47
258
原创 leetcode 500. Keyboard Row
package com.swjtu.easy.twosum;import java.util.ArrayList;import java.util.HashSet;/** * @author tangmin * @create 2017年2月26日 下午12:11:23 */public class KeyboardRow { public static void main(
2017-02-26 13:16:54
231
原创 leetcode 476. Number Complement
package com.swjtu.easy.twosum;/** * * @author tangmin * @create 2017年2月26日 上午11:53:21 */public class NumberComplement { public static void main(String[] args) { int num = 5; System.out.pr
2017-02-26 11:54:36
277
原创 Add two numbers
package com.swjtu.easy.twosum;/** * LeetCode Problems List No.2 Add Two Numbers * remarks: * java linked list 节点的构建顺序(先创建的节点在尾部); * 各位数字相加要处理进位问题(单个进位、连续进位等); * linked list 长度是否相等的情况;
2017-02-25 21:14:33
235
原创 JavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer
JavaServer Faces 2.2 can not be installed : One or more constraints have not been satisfiedJavaServer Faces 2.2 requires Dynamic Web Module 2.5 or newer修改jst.web=2.4,jst.jsf=2.0org.eclipse
2017-02-20 14:38:34
2918
原创 Ubuntu14.04LTS firefox无法使用问题解决
Ubuntu14.04LTS firefox无法使用问题解决Firefox is configured to use a proxy server that is refusing connections.To Reset Firefox do the following:Go to Firefox > Help > Troubleshooting Information. Click the “
2016-11-07 16:29:21
3249
原创 MyEclipse2014部署maven web项目失败
MyEclipse2014 作为开发Web项目的常用工具,在使用中提供了很大的开发便利。但是也会遇到一些问题。比如项目无法正确部署到tomcat等问题。 it could not be completely removed in the undeployment phase 分析:可能是maven在build成功后,还没有生成可发布的jar包 解决:在项目上右键Refresh后就生成了(不知道
2016-10-31 21:43:50
1347
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人