摘要: 题目地址:https://leetcode.com/problems/balanced-binary-tree/题目解答:/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode ... 阅读全文
posted @ 2015-04-11 12:55 buptubuntu 阅读(124) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/minimum-window-substring/题目解答:import java.util.HashMap;import java.util.Map;public class Solution { public Strin... 阅读全文
posted @ 2015-04-10 23:58 buptubuntu 阅读(221) 评论(0) 推荐(0)
摘要: 概述K最近邻(k-Nearest Neighbor,KNN)分类算法可以说是最简单的机器学习算法了。它采用测量不同特征值之间的距离方法进行分类。它的思想很简单:如果一个样本在特征空间中的k个最相似(即特征空间中最邻近)的样本中的大多数属于某一个类别,则该样本也属于这个类别。算法总结k-邻近算法是分类... 阅读全文
posted @ 2015-04-10 23:55 buptubuntu 阅读(128) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/reverse-linked-list-ii/解题思路:1.找到需要翻转的开始节点,从开始节点其依次进行翻转,注意过程中要维护三个节点,curr,curr.next,curr.next.next2.如果开始翻转节点为1,则返回翻转... 阅读全文
posted @ 2015-04-10 00:33 buptubuntu 阅读(104) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/number-of-islands/题目分析:需要找出水平或者垂直相连的‘1’的个数,第一思路是递归遍历直到上下左右走没有‘1’返回,同时需要注意遍历到一个‘1’将其修改为‘0’表示已经访问过了;然后每遍历完一次即表示一个isla... 阅读全文
posted @ 2015-04-09 09:34 buptubuntu 阅读(257) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/house-robber/解析:此问题采用动态规划,根据题意,到达第i个房子最大收益应该为第i-2个房子最大收益加上第i个房子钱数与到达第i-1个房子最大收益两者的最大值。题目答案:public class Solution { ... 阅读全文
posted @ 2015-04-08 14:26 buptubuntu 阅读(102) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/rising-temperature/题目解答:# Write your MySQL query statement belowselect w1.Id from Weather w1 inner joinWeather w2 o... 阅读全文
posted @ 2015-04-08 11:48 buptubuntu 阅读(104) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/wildcard-matching/动态规划解答:public class Solution { public boolean isMatch(String s, String p) { if(p.length... 阅读全文
posted @ 2015-04-08 09:18 buptubuntu 阅读(105) 评论(0) 推荐(0)
摘要: 题目地址:https://leetcode.com/problems/number-of-1-bits/解答:public class Solution { // you need to treat n as an unsigned value public int hammingWei... 阅读全文
posted @ 2015-04-07 17:06 buptubuntu 阅读(73) 评论(0) 推荐(0)
摘要: 题目链接:https://leetcode.com/problems/binary-tree-right-side-view/递归法解法:/** * Definition for binary tree * public class TreeNode { * int val; * T... 阅读全文
posted @ 2015-04-07 15:23 buptubuntu 阅读(183) 评论(0) 推荐(0)