自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(120)
  • 收藏
  • 关注

原创 28. Implement strStr()

public class Solution { public int strStr(String haystack, String needle) { if(haystack == null || needle == null || needle.length() > haystack.length()) { return -1; }e

2017-03-26 19:28:41 218

原创 139. Word Break

public class Solution { boolean find = false; public boolean wordBreak(String s, List<String> wordDict) { boolean[] f = new boolean[s.length()+1]; f[0] = true; for(int i =

2017-03-18 11:41:51 229

原创 47. Permutations II

public class Solution { public List<List<Integer>> permuteUnique(int[] nums) { Set<List<Integer>> set = new HashSet<>(); perm(set,new ArrayList<>(),0,nums); List<List<Intege

2017-03-17 23:51:39 220

原创 130. Surrounded Regions

public class Solution { public void solve(char[][] board) { if(board == null || board.length <=2 || board[0].length <= 2) { return; } int m = board.length, n = b

2017-03-15 22:28:12 209

原创 32. Longest Valid Parentheses

public class Solution { public int longestValidParentheses(String s) { if(s == null || s.length() <=1) { return 0; } int[] f = new int[s.length()]; int m

2017-03-15 21:33:06 167

原创 230. Kth Smallest Element in a BST

public class Solution { int count = 0; int value = 0; public int kthSmallest(TreeNode root, int k) { dfs(root,k); return value; } public void dfs(TreeNode root,int k)

2017-03-11 15:24:44 180

原创 22. Generate Parentheses

public class Solution { public List<String> generateParenthesis(int n) { List<String> list = new ArrayList<>(); if(n<=0) { return list; } dfs(list,0,2*n,

2017-03-11 15:14:04 198

原创 401. Binary Watch

public class Solution { public List<String> readBinaryWatch(int num) { List<String> list = new ArrayList<>(); if(num==0) { list.add("0:00"); return list;

2017-03-11 13:34:45 171

原创 242. Valid Anagram

public class Solution { public boolean isAnagram(String s, String t) { int ls = s.length(); int lt = t.length(); if(ls!= lt) { return false; } cha

2017-03-11 12:48:53 184

原创 public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p== null

public class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if(p== null && q== null) { return true; }else if(p != null && q==null || p==null && q!= null)

2017-03-11 12:43:21 604

原创 404. Sum of Left Leaves

public class Solution { int sum = 0; public int sumOfLeftLeaves(TreeNode root) { dfs(root); return sum; } public void dfs(TreeNode root) { if(root == null) {

2017-03-11 11:12:04 178

原创 504. Base 7

public class Solution { public String convertToBase7(int num) { int nums = num; if(nums >=-6 && nums <= 6) { return nums+""; } boolean isne = num>=0?fals

2017-03-11 10:56:47 182

原创 453. Minimum Moves to Equal Array Elements

public class Solution { /* public int minMoves(int[] nums) { if(nums == null || nums.length == 1) { return 0; } int min = nums[0]; for(int i = 1; i< nums.l

2017-03-11 10:46:20 145

原创 455. Assign Cookies

public class Solution { public int findContentChildren(int[] g, int[] s) { if(g == null || s == null || g.length == 0 || s.length == 0) { return 0; } Arrays.sort

2017-03-11 09:14:54 143

原创 506. Relative Ranks

public class Solution { class Rank { int pos; int score; Rank(int pos, int score) { this.pos = pos; this.score = score; } } public St

2017-03-11 08:35:39 177

原创 258. Add Digits

public class Solution { public int addDigits(int num) { int sum = 0; while(num>=10) { sum = 0; while(num!=0) { sum+=(num%10);

2017-03-10 23:55:20 157

原创 104. Maximum Depth of Binary Tree

public class Solution { public int maxDepth(TreeNode root) { if(root == null) { return 0; }else { int left = maxDepth(root.left)+1; int right = m

2017-03-10 23:46:18 150

原创 495. Teemo Attacking

public class Solution { public int findPoisonedDuration(int[] timeSeries, int duration) { if(timeSeries == null || timeSeries.length == 0) { return 0; }else if(timeSerie

2017-03-10 23:41:14 182

原创 508. Most Frequent Subtree Sum

public class Solution { int max = 1; public int[] findFrequentTreeSum(TreeNode root) { Map<Integer,Integer> map = new HashMap<>(); dfs(map,root); int maxi = 0; for(I

2017-03-10 23:28:02 146

原创 520. Detect Capital

public class Solution { public boolean detectCapitalUse(String word) { int count = 0; String str = word.toLowerCase(); for(int i = 0; i < word.length();i++) { if(

2017-03-10 22:38:18 145

原创 496. Next Greater Element I

public class Solution { public int[] nextGreaterElement(int[] findNums, int[] nums) { int lf = findNums.length; int[] res = new int[lf]; int i=0,j=0; for(i=0;i<lf;i+

2017-03-10 22:13:23 144

原创 338. Counting Bits

public class Solution { public int[] countBits(int num) { List<Integer> list = new ArrayList<>(); for(int i=0;i<=num;i++) { list.add(cacuate(i)); } int[]

2017-03-10 21:54:45 122

原创 500. Keyboard Row

public class Solution { public String[] findWords(String[] words) { String[] keys={"qwertyuiopQWERTYUIOP","asdfghjklASDFGHJKL","zxcvbnmZXCVBNM"}; List<String> list = new ArrayLis

2017-03-10 21:42:37 156

原创 70. Climbing Stairs

public class Solution { public int climbStairs(int n) { if(n<=0) { return 0; } if(n==1 || n == 2) { return n; } int[] nums = new int[

2017-03-10 16:48:34 135

原创 87. Scramble String

public class Solution { public boolean isScramble(String s1, String s2) { if (s1.length() != s2.length()) return false; if (s1.equals(s2)) return true; char[] c1 = s1.t

2017-03-10 14:39:28 145

原创 91. Decode Ways

public class Solution { public int numDecodings(String s) { if(s == null || s.length() == 0) { return 0; } if(s.length()==1) { return s.charAt(0) == '

2017-03-10 14:14:54 125

原创 131. Palindrome Partitioning

public class Solution { public void help(boolean f[][],String s,List<List<String>> result, List<String> path, int pos) { if(s.length() == pos) { result.add(new ArrayList<>(path)

2017-03-10 10:48:15 102

原创 115. Distinct Subsequences

public class Solution { public int numDistinct(String s, String t) { int[][] nums = new int[t.length()+1][s.length()+1]; for(int i = 0; i< s.length()+1;i++) { nums[0][i]

2017-03-10 09:56:36 120

原创 96. Unique Binary Search Trees

public class Solution { public int numTrees(int n) { int[] res = new int[n+1]; res[0]=1; res[1]=1; for(int i = 2; i<= n; i++) { for(int j = 0; j < i; j++

2017-03-09 22:23:03 113

原创 97. Interleaving String

public class Solution { public boolean isInterleave(String s1, String s2, String s3) { if(s1.length()+s2.length() !=s3.length()) { return false; }else { bool

2017-03-09 21:56:37 127

原创 516. Longest Palindromic Subsequence

public class Solution { public int longestPalindromeSubseq(String s) { int[][] num = new int[s.length()][s.length()]; for(int i = s.length()-1; i>=0;i--) { num[i][i] = 1

2017-03-09 20:48:07 153

原创 463. Island Perimeter

public static int islandPerimeter(int[][] grid) { int count = 0; if ( grid == null || grid[0].length == 0 ) { return count; } for ( int i = 0; i < grid.lengt

2016-12-26 22:38:28 181

原创 202. Happy Number

public static boolean isHappy(int n) { if(n <= 0) { return false; } Set<Integer> set = new HashSet<>(); boolean res = true; int x = n; while(

2016-12-25 10:27:54 237

原创 136. Single Number

public static int singleNumber(int[] nums) { Arrays.sort(nums); int count = 0; int i = 0; while(i < nums.length){ if(i == 0 || nums[i] == nums[i-1]) {

2016-12-19 17:14:23 175

原创 36. Valid Sudoku

public static boolean isValidSudoku(char[][] board) { if(board == null ) { return true; } int len = board.length; for(int i = 0; i < len; i++) {

2016-12-15 20:25:59 169

原创 79. Word Search

public static boolean exist(char[][] board, String word) { if(board == null || board.length == 0) { return false; } boolean res = false; for(int i = 0; i < b

2016-12-15 15:11:34 182

原创 73. Set Matrix Zeroes

public static void setZeroes(int[][] matrix) { if(matrix == null || matrix.length == 0 ) { return ; } int[] path = new int[matrix.length*matrix[0].length];

2016-12-15 11:11:51 156

原创 75. Sort Colors

public static void sortColors(int[] nums) { int count0 = 0,count1 = 0; for(int i = 0; i < nums.length; i++) { if(nums[i] == 0) { count0++; }else if(nu

2016-12-15 10:40:22 155

原创 90. Subsets II

public List<List<Integer>> subsetsWithDup(int[] nums) { List<List<Integer>> list = new ArrayList<>(); list.add(new ArrayList<>()); for(int i = 1; i <= nums.length; i++) {

2016-12-14 16:34:05 136

原创 78. Subsets

public static List<List<Integer>> subsets(int[] nums) { List<List<Integer>> list = new ArrayList<>(); for(int i = 1; i <= nums.length; i++) { List<List<Integer>> tlist = rec

2016-12-14 15:25:38 168

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除