04 2015 档案
摘要:求二叉树的最小深度。/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x) ...
阅读全文
摘要:判断一颗二叉树中是否存在一天路径(从根节点到叶子节点)的val值之和等于给定的sum。注意判断root为null的时候。 成也递归败也递归。。。。。/** * Definition for binary tree * public class TreeNode { * int val; *...
阅读全文
摘要:判断小于n数中素数的个数,如果用普通的判断方法会超时,这里使用筛选法。 具体请参考:http://blog.csdn.net/liukehua123/article/details/5482854public class Solution { public int countPrimes(i...
阅读全文
摘要:删除链表中的指定元素。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } ...
阅读全文
摘要:把上一个类似的题目中的list反转就可以了。/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * Tree...
阅读全文
摘要:递归求二叉树的最大深度。/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int x...
阅读全文
摘要:层次遍历,深刻理解树和递归。/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNode right; * TreeNode(int...
阅读全文
摘要:关于镜像树的相关操作,利用递归可以很简单的解决问题。 注意判断根节点是不是null/** * Definition for binary tree * public class TreeNode { * int val; * TreeNode left; * TreeNod...
阅读全文
摘要:刚才在做DBMS课程设计的时候遇到了一个以前遇到过的问题不过这次我没有一眼认出来,想了好一会才想起来。 就是在用split()方法来分割路径名字符串的时候,比如String path = “E:\split\ikonw";String[] tpath = path.split("\\"); 你以为...
阅读全文
摘要:对分数排序 参考了网上的答案 而且如果不Order by 有一个BUG就是 如果表为空则什么都不输出包括null才是正确的。 # Write your MySQL query statement belowselect s.Score, count(rank.Score) as Rankfrom ...
阅读全文
摘要:题目大概意思是要求找出第n高的Salary,直接写一个Function。作为一个SQL新手我学到了1.SQL中Function的写法和变量的定义,取值。2.limit查询分 页的方法。 在这个题目中limit n-1, 1是从n-1开始取出一条数据。这样说比较直观。CREATE FUNCTION ...
阅读全文
摘要:题目大概的意思是选出每个Department里工资最高的人的信息并组成相应的表信息 有几个值得注意的地方:1)使用group by语句时,前面的select语句后面的内容只能有两种情况一种是group by后面的属性,另一种是聚集函数。 2)在选取最大Salary时必须使用e1.Salary=e...
阅读全文
摘要:Description:Given a Weather table, write a SQL query to find all dates' Ids with higher temperature compared to its previous (yesterday's) dates. 选出比...
阅读全文
摘要: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. 删除重...
阅读全文
摘要: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 ...
阅读全文
摘要:Description:Write a SQL query to find all duplicate emails in a table named Person. 找出表中重复的Email。# Write your MySQL query statement belowselect Email...
阅读全文
摘要: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...
阅读全文
摘要:Description: Write a SQL query to get the second highest salary from the Employee table.+----+--------+| Id | Salary |+----+--------+| 1 | 100 ||...
阅读全文
摘要:第一次刷SQL题目感觉还是不错的。这个题目(https://leetcode.com/problems/combine-two-tables/)大概是说把第一张表和第二张表连接起来。而且第二张表中的Person的Address中的属性可能为NULL。这明显就是个左外链接。?123# Write yo...
阅读全文
摘要: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...
阅读全文
摘要:package algorithm01;import java.util.Scanner;/** * 给出先序遍历和中序遍历序列求出二叉树的后续遍历序列 * @author wxisme * */public class ToReverse { public static void main(Str...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:题意:给一个数按位存放在一个int数组中,要求返回这个数加一后的数组。 懒人解法:public class Solution { public int[] plusOne(int[] digits) { java.math.BigInteger Bigdigits = new jav...
阅读全文
摘要:TCP协议是面向连接的,相对于UDP协议来说效率较低,但是比较安全,数据不容易丢失。TCP协议类似打电话的过程,在一端拨号时必须等待对方回应,确定两端建立了连接通道才能传送信息。 在Java中TCP被封装成了类方便使用。ServerSocket类可以创建服务端并指定端口,Socket类可以建立起通...
阅读全文
摘要:UDP协议是非面向连接的,相对于TCP协议效率较高,但是不安全。UDP协议类似发信息的过程,不管接收方是在线还是关机状态,都会把信息发送出去。但是如果接收方不处于接收信息的状态,发送出去的数据包就会丢失。convert()方法是用来转换字节数组和基本类型。/** * 创建基于udp协议的服务接受端...
阅读全文
摘要:Java的字符串也很强大。public class Solution { public int lengthOfLastWord(String s) { if(s.length() == 0) return 0; String[] str = s.trim(...
阅读全文
摘要:Java对二进制的支持还是比较好的,用上BIgInteger连溢出都不用考虑了。public class Solution { public String addBinary(String a, String b) { java.math.BigInteger ia = new java.m...
阅读全文
摘要:判断是不是符合数独的规则。数独的规则:每一行每一列不能有重复的数字,每一个3X3方格中不能有重复的数字,但是这个题中可以为空即都是'.'。 (要养成良好的编程习惯啊,要不一点低级错误不容易发现,浪费生命!)public class Solution { public boolean isVal...
阅读全文
摘要:自从JavaAPI&RegExp用熟练了之后就变得越来越任性越来越懒了):public class Solution { public int strStr(String haystack, String needle) { return haystack.indexOf(ne...
阅读全文
摘要:线性表的删除操作,这里可以用ArrayList实现简单的完成。(偷懒)public class Solution { public int removeElement(int[] A, int elem) { ArrayList arr = new ArrayL...
阅读全文
摘要:删除数组里重复的元素,返回数组的元素个数。可以利用set集合元素不重复的特点来保存。public class Solution { public int removeDuplicates(int[] A) { java.util.SortedSet set = ...
阅读全文
摘要:依然是链表的简单操作,把两个链表按大小顺序和成一个链表,但是还是要注意细节。下面是效率不高但是简单易懂的一种解法。需要注意两个链表都为空的情况。/** * Definition for singly-linked list. * public class ListNode { * int ...
阅读全文
摘要:题目意思非常简单,判断所给字符串中的括号是否匹配,需要注意的问题:)(这样是不匹配的。 public class Solution { public boolean isValid(String s) { Stack stack = new Stack(); ...
阅读全文
摘要:删除链表中倒数第n个节点,需要考虑的细节:链表为空时,链表只有一个节点时,n=1时。/** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ...
阅读全文
摘要:程序比较简单,但是能体现基本原理。package com.wxisme.webcrawlers;import java.io.*;import java.net.*;/** * Web Crawlers * @author wxisme * */public class WebCrawlers {...
阅读全文
摘要:题目虽然简单但是要高效准确还是要很细心才是,粗心是BUG的最大制造者。public class Solution { public String longestCommonPrefix(String[] strs) { if(strs.length == 0) ...
阅读全文
摘要:题目没有太大意思if else就能过了。public class Solution { public int romanToInt(String s) { int num = 0, i; for(i=0; i<s.length(); i++) ...
阅读全文
摘要:用Java刷这道题没有太大意义。public class Solution { public boolean isPalindrome(int x) { boolean ans = false; StringBuilder sb = new Str...
阅读全文
摘要:把所给的字符串按照规定转化成相应的数字。要考虑溢出的情况,含有非法字符的情况,数字前有空格的情况。但是还是比较简单的。public class Solution { public int atoi(String str) { StringBuilder s = ...
阅读全文
摘要:反转数字,考虑溢出的情况。直接返回零(好坑啊)。public class Solution { public int reverse(int x) { if(x == 0) return 0; StringBuilder sb = new St...
阅读全文
摘要:在循环时最好不好随意的使用或改变限制循环的条件和控制循环的变量。因为这样可能会带来难以发现的错误。比如在字符串循环里删除了里面的元素。字符串长度减少,而字符串长度是循环的控制条件,这样很可能会导致输出结果不正确而你却找不到错误,因为它难以发现。
阅读全文