自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 leetcode 14 Longest Common Prefix

Java:class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length == 0) return ""; String pre = strs[0]; int i = 1; while(i <= str...

2018-03-31 16:31:53 112

原创 leetcode 20 Valid Parentheses

Java:class Solution { public boolean isValid(String s) { Stack<Character> stack = new Stack<>(); for (char c : s.toCharArray()){ if(c=='(') stack.push(')');...

2018-03-29 11:51:18 110

原创 leetcode 125 Valid Palindrome

Java:class Solution { public boolean isPalindrome(String s) { if(s.isEmpty()) return true; int l=0, r=s.length()-1; while(l<=r){ char head = s.charA...

2018-03-28 15:22:19 109

原创 leetcode 67 Add Binary

Java:class Solution { public String addBinary(String a, String b) { StringBuilder ans = new StringBuilder(); int la = a.length() - 1; int lb = b.length() - 1; int c...

2018-03-27 15:56:03 127

原创 leetcode 58 Length of Last Word

Java:class Solution { public int lengthOfLastWord(String s) { return s.trim().length()-s.trim().lastIndexOf(" ")-1; //.trim()返回删除前后空格的副本 //.lastIndexOF()方法可返回一个指定的字符串值最后出现的...

2018-03-26 10:14:30 120

原创 python不换行print

python 2.x:方法一from __future__ import print_function#引入第三方包for i in range(5): print ( i, end='' )01234方法二for i in range(5): #后面加逗号,会有空格 print i, 0 1 2 3 4python 3:直接采用上面方法一,不需要...

2018-03-21 20:36:21 241

原创 leetcode 235 Lowest Common Ancestor of a Binary Search Tree

Java:class Solution { public TreeNode lowestCommonAncestor(TreeNode root, TreeNode p, TreeNode q) { while((root.val - p.val) * (root.val - q.val) >0){ root = p.val < root...

2018-03-21 09:30:48 135

原创 leetcode 129 Sum Root to Leaf Numbers

Java:class Solution { public int sumNumbers(TreeNode root) { return sumNum(root, 0); } public int sumNum(TreeNode root, int sum){ if(root == null) return 0; if...

2018-03-20 09:19:01 174

原创 leetcode 117 Populating Next Right Pointers in Each Node II

Java:public class Solution { public void connect(TreeLinkNode root) { if(root == null) return; TreeLinkNode ro = root; while(ro!=null){ TreeLi...

2018-03-19 20:33:50 134

原创 leetcode 116 Populating Next Right Pointers in Each Node

Java:public class Solution { public void connect(TreeLinkNode root) { if(root == null) return; TreeLinkNode ro = root; while(ro!=null){ TreeLinkNode f...

2018-03-18 21:20:07 138

原创 leetcode 114 Flatten Binary Tree to Linked List

Java:class Solution { private TreeNode ro = null; public void flatten(TreeNode root) { if(root == null) return; flatten(root.right); flatten(root.left); ro...

2018-03-17 16:26:50 123

原创 leetcode 113 Path Sum II

Java:class Solution { public List<List<Integer>> pathSum(TreeNode root, int sum) { List<List<Integer>> ans = new LinkedList<>(); List<Integer> r...

2018-03-16 14:37:30 187

原创 leetcode 106 Construct Binary Tree from Inorder and Postorder Traversal

Java:class Solution { public TreeNode buildTree(int[] inorder, int[] postorder) { return build(inorder, 0, inorder.length-1, postorder, 0,postorder.length-1); } public TreeNod...

2018-03-15 11:18:02 148

原创 leetcode 105 Construct Binary Tree from Preorder and Inorder Traversal

Java:class Solution { public TreeNode buildTree(int[] preorder, int[] inorder) { return build(preorder, 0, inorder, 0, inorder.length-1); } public TreeNode build(int[] preorde...

2018-03-14 14:46:26 159

原创 数据分析:USDA食品数据库

# -*- coding: utf-8 -*- import jsonimport pandas as pdfrom pandas import DataFramedb = json.load(open('usda_food/database.json'))#print len(db)#print db[0].keys()#print db[0]['nutrients'][...

2018-03-13 21:13:56 3962 7

原创 leetcode 103 Binary Tree Zigzag Level Order Traversal

Java:class Solution { public List<List<Integer>> zigzagLevelOrder(TreeNode root) { List<List<Integer>> ans = new ArrayList<>(); if (root == null) retu...

2018-03-13 10:57:15 125

原创 leetcode 95 Unique Binary Search Trees II

Java:class Solution { public List<TreeNode> generateTrees(int n) { if(n==0) return new ArrayList<>(); return genTrees(1,n); } public List<TreeNode> g...

2018-03-12 10:45:14 120

原创 leetcode 101 Symmetric Tree

Java:class Solution { public boolean isSymmetric(TreeNode root) { if (root == null) return true; return isSym(root,root); } public boolean isSym( TreeNode root1, TreeNode r...

2018-03-09 11:06:12 122

原创 leetcode 226 Invert Binary Tree

Java:class Solution { public TreeNode invertTree(TreeNode root) { if(root == null) return null; TreeNode left = root.left, right = root.right; root.left = invertTree(right)...

2018-03-07 10:03:02 132

原创 leetcode 112 Path Sum

Java:class Solution { public boolean hasPathSum(TreeNode root, int sum) { if (root == null ) return false; if (root.left == null && root.right == null && sum-root.v...

2018-03-07 09:29:06 152

原创 数据分析:1880 —— 2020全美婴儿姓名

# -*- coding: utf-8 -*-import pandas as pdimport matplotlib.pyplot as pltimport numpy as npnames1880 = pd.read_csv('names/yob1880.txt', names=[ 'name', 'sex', 'births' ])#print names1880#用bir...

2018-03-06 18:08:35 2252

原创 leetcode 111 Minimum Depth of Binary Tree

Java:class Solution { public int minDepth(TreeNode root) { if (root == null) return 0; int l = minDepth(root.left); int r = minDepth(root.right); return (l == 0 || ...

2018-03-06 10:21:26 157

原创 leetcode 110 Balanced Binary Tree

Java:class Solution { public boolean isBalanced(TreeNode root) { if (root == null) return true; return Math.abs(heigh(root.left)-heigh(root.right)) <= 1 && isBalanced(ro...

2018-03-06 09:57:33 128

原创 数据分析:MovieLen 1M 数据集

# -*- coding: utf-8 -*- import pandas as pd#数据来源 www.grouplens.org/node/73unames = ['user_id', 'gender', 'age', 'occupation', 'zip' ]users = pd.read_table('ml-1m/users.dat', sep='::' , header =...

2018-03-05 21:18:02 3101

原创 leetcode 107 Binary Tree Level Order Traversal II

Java:class Solution { public List<List<Integer>> levelOrderBottom(TreeNode root) { Queue<TreeNode> queue = new LinkedList<TreeNode>(); List<List<Integ...

2018-03-05 11:32:19 131

原创 leet code 100 Same Tree

Java:class Solution { public boolean isSameTree(TreeNode p, TreeNode q) { if ( p == null && q == null ) return true; if ( p == null || q == null ) return false; if ...

2018-03-05 09:01:04 137

空空如也

空空如也

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

TA关注的人

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