随笔分类 -  算法题

摘要:层次遍历,深刻理解树和递归。/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int... 阅读全文
posted @ 2015-04-25 22:42 Pickle 阅读(179) 评论(0) 推荐(0)
摘要:关于镜像树的相关操作,利用递归可以很简单的解决问题。 注意判断根节点是不是null/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNod... 阅读全文
posted @ 2015-04-25 21:32 Pickle 阅读(153) 评论(0) 推荐(0)
摘要:对分数排序 参考了网上的答案 而且如果不Order by 有一个BUG就是 如果表为空则什么都不输出包括null才是正确的。 # Write your MySQL query statement belowselect s.Score, count(rank.Score) as Rankfrom ... 阅读全文
posted @ 2015-04-20 23:30 Pickle 阅读(203) 评论(0) 推荐(0)
摘要:题目大概意思是要求找出第n高的Salary,直接写一个Function。作为一个SQL新手我学到了1.SQL中Function的写法和变量的定义,取值。2.limit查询分 页的方法。 在这个题目中limit n-1, 1是从n-1开始取出一条数据。这样说比较直观。CREATE FUNCTION ... 阅读全文
posted @ 2015-04-20 23:01 Pickle 阅读(220) 评论(0) 推荐(0)
摘要:题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息 有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group by后面的属性,另一种是聚集函数。 2)在选取最大Salary时必须使用e1.Salary=e... 阅读全文
posted @ 2015-04-20 22:22 Pickle 阅读(214) 评论(0) 推荐(0)
摘要:Description:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. 选出比... 阅读全文
posted @ 2015-04-19 23:01 Pickle 阅读(283) 评论(0) 推荐(0)
摘要:Discription:Write a SQL query to delete all duplicate email entries in a table named Person, keeping only unique emails based on its smallest Id. 删除重... 阅读全文
posted @ 2015-04-19 22:16 Pickle 阅读(204) 评论(0) 推荐(0)
摘要:Description: Suppose that a website contains two tables, the Customers table and the Orders table. Write a SQL query to find all customers who never ... 阅读全文
posted @ 2015-04-19 21:55 Pickle 阅读(191) 评论(0) 推荐(0)
摘要:Description:Write a SQL query to find all duplicate emails in a table named Person. 找出表中重复的Email。# Write your MySQL query statement belowselect Email... 阅读全文
posted @ 2015-04-18 09:02 Pickle 阅读(170) 评论(0) 推荐(0)
摘要:Description:The Employee table holds all employees including their managers. Every employee has an Id, and there is also a column for the manager Id.G... 阅读全文
posted @ 2015-04-16 23:44 Pickle 阅读(214) 评论(0) 推荐(0)
摘要:Description: Write a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 ||... 阅读全文
posted @ 2015-04-16 23:17 Pickle 阅读(192) 评论(0) 推荐(0)
摘要:Description:Write a SQL query for a report that provides the following information for each person in the Person table, regardless if there is an add... 阅读全文
posted @ 2015-04-16 22:48 Pickle 阅读(164) 评论(0) 推荐(0)
摘要:Description:Given two binary trees, write a function to check if they are equal or not. Two binary trees are considered equal if they are structurall... 阅读全文
posted @ 2015-04-12 22:20 Pickle 阅读(187) 评论(0) 推荐(0)
摘要:Description: Given two sorted integer arrays A and B, merge B into A as one sorted array. Note: You may assume that A has enough space (siz... 阅读全文
posted @ 2015-04-11 23:04 Pickle 阅读(167) 评论(0) 推荐(0)
摘要:Description:Given a sorted linked list, delete all duplicates such that each element appear only once. For example, Given 1->1->2, return 1->2. Given... 阅读全文
posted @ 2015-04-11 22:31 Pickle 阅读(178) 评论(0) 推荐(0)
摘要:Description: You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct wa... 阅读全文
posted @ 2015-04-11 11:33 Pickle 阅读(184) 评论(0) 推荐(0)
摘要:题意:给一个数按位存放在一个int数组中,要求返回这个数加一后的数组。 懒人解法:public class Solution { public int[] plusOne(int[] digits) { java.math.BigInteger Bigdigits = new jav... 阅读全文
posted @ 2015-04-11 11:12 Pickle 阅读(207) 评论(0) 推荐(0)
摘要:Java的字符串也很强大。public class Solution { public int lengthOfLastWord(String s) { if(s.length() == 0) return 0; String[] str = s.trim(... 阅读全文
posted @ 2015-04-03 18:22 Pickle 阅读(138) 评论(0) 推荐(0)
摘要:Java对二进制的支持还是比较好的,用上BIgInteger连溢出都不用考虑了。public class Solution { public String addBinary(String a, String b) { java.math.BigInteger ia = new java.m... 阅读全文
posted @ 2015-04-03 18:20 Pickle 阅读(161) 评论(0) 推荐(0)
摘要:判断是不是符合数独的规则。数独的规则:每一行每一列不能有重复的数字,每一个3X3方格中不能有重复的数字,但是这个题中可以为空即都是'.'。 (要养成良好的编程习惯啊,要不一点低级错误不容易发现,浪费生命!)public class Solution { public boolean isVal... 阅读全文
posted @ 2015-04-03 14:09 Pickle 阅读(267) 评论(0) 推荐(0)