- 博客(48)
- 资源 (33)
- 收藏
- 关注
原创 leetcode86. Partition List
Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative order of the nodes in each of
2016-02-26 15:19:57 372
原创 leetcode82. Remove Duplicates from Sorted List II
Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example,Given 1->2->3->3->4->4->5, return 1->2->5.Given 1->1-
2016-02-26 14:51:32 333
原创 leetcode80 Remove Duplicates from Sorted Array II
Follow up for "Remove Duplicates":What if duplicates are allowed at most twice?For example,Given sorted array nums = [1,1,1,2,2,3],Your function should return length = 5, with the first fi
2016-02-26 11:04:12 326
原创 leetcode77 Combinations
Given two integers n and k, return all possible combinations of k numbers out of 1 ... n.For example,If n = 4 and k = 2, a solution is:[ [2,4], [3,4], [2,3], [1,2], [1,3], [1,4],]
2016-02-26 10:27:49 312
原创 leetcode328. Odd Even Linked List
Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.You should try to do it in
2016-02-25 10:10:38 397
原创 AVL搜索树相关源代码
AVL树又被称为平衡二叉树#include#include#include#includeusing namespace std;typedef struct AVLTree{ int nData; struct AVLTree *pLeft; struct AVLTree *pRight; int nHeight;}AVLTree;int Max(int a, int
2016-02-09 14:59:09 332
原创 poj1008 Maya Calendar
Maya CalendarTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 72431 Accepted: 22294DescriptionDuring his last sabbatical, professor M. A. Ya made a surpr
2016-01-16 13:19:10 339
原创 poj DNA Sorting
DNA SortingTime Limit: 1000MS Memory Limit: 10000KTotal Submissions: 91873 Accepted: 36916DescriptionOne measure of ``unsortedness'' in a sequence is the number o
2016-01-16 12:22:00 402
原创 华为OJ 合唱队
package he011101;import java.util.Scanner;public class Main { public static void main(String[] args) { Scanner reader = new Scanner(System.in); while(reader.hasNext()){ int N = reader.ne
2016-01-11 17:33:53 542
原创 nyoj35 表达式求值
表达式求值时间限制:3000 ms | 内存限制:65535 KB难度:4描述 ACM队的mdd想做一个计算器,但是,他要做的不仅仅是一计算一个A+B的计算器,他想实现随便输入一个表达式都能求出它的值的计算器,现在请你帮助他来实现这个计算器吧。比如输入:“1+2/4=”,程序就输出1.50(结果保留两位小数)输入第一行输入一个整数n,共有n组测试数据(n每组测试数据
2016-01-07 21:20:15 305
原创 leetcode54 Spiral Matrix
Given a matrix of m x n elements (m rows, n columns), return all elements of the matrix in spiral order.For example,Given the following matrix:[ [ 1, 2, 3 ], [ 4, 5, 6 ], [ 7, 8, 9 ]]
2015-11-25 13:47:19 275
原创 nyoj90 整数划分
整数划分时间限制:3000 ms | 内存限制:65535 KB难度:3描述将正整数n表示成一系列正整数之和:n=n1+n2+…+nk, 其中n1≥n2≥…≥nk≥1,k≥1。 正整数n的这种表示称为正整数n的划分。求正整数n的不 同划分个数。 例如正整数6有如下11种不同的划分: 6; 5+1; 4+2,4+1+1; 3+3,3
2015-11-23 12:54:13 371
原创 leetcode40 Combination Sum II
Given a collection of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.Each number in C may only be used once in the combina
2015-11-22 16:21:21 332
原创 leetcode39 Combination Sum
Total Accepted: 69250 Total Submissions: 238683 Difficulty: MediumGiven a set of candidate numbers (C) and a target number (T), find all unique combinations in C where the candidate numbers sums to T.
2015-11-22 16:19:12 273
原创 leetcode25 Reverse Nodes in k-Group
Reverse Nodes in k-GroupMy SubmissionsQuestionTotal Accepted: 47206 Total Submissions: 181287 Difficulty: HardGiven a linked list, reverse the nodes of a linked list k at a tim
2015-11-18 17:19:25 434
原创 leetcode 18 4Sum
/**Given an array S of n integers, are there elements a, b, c, and d in S such that a + b + c + d = target? Find all unique quadruplets in the array which gives the sum of target.Note:Elements in a qu
2015-11-11 21:15:03 262
原创 nyoj104 最大和
最大和时间限制:1000 ms | 内存限制:65535 KB难度:5描述给定一个由整数组成二维矩阵(r*c),现在需要找出它的一个子矩阵,使得这个子矩阵内的所有元素之和最大,并把这个子矩阵称为最大子矩阵。 例子:0 -2 -7 0 9 2 -6 2 -4 1 -4 1 -1 8 0 -2 其最大子矩阵为:9
2015-11-03 21:33:10 316
原创 nyoj1242 Distribution
Distribution时间限制:1000 ms | 内存限制:65535 KB难度:1描述One day , Wang and Dong in the Dubai desert expedition, discovered an ancient castle. Fortunately, they found a map of the castle.The map mark
2015-11-02 19:22:51 299
原创 leetcode29 Divide Two Integers
Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.public class Solution { public int divide(int dividend, int divisor) { i
2015-11-02 15:19:15 302
原创 nyoj14 会场安排问题
会场安排问题时间限制:3000 ms | 内存限制:65535 KB难度:4描述学校的小礼堂每天都会有许多活动,有时间这些活动的计划时间会发生冲突,需要选择出一些活动进行举办。小刘的工作就是安排学校小礼堂的活动,每个时间最多安排一个活动。现在小刘有一些活动计划的时间表,他想尽可能的安排更多的活动,请问他该如何安排。输入第一行是一个整型数m(m每组
2015-10-24 11:13:26 349
原创 leetcode257 Binary Tree Paths
Given a binary tree, return all root-to-leaf paths.For example, given the following binary tree: 1 / \2 3 \ 5All root-to-leaf paths are:["1->2->5", "1->3"]import java
2015-10-22 10:14:45 259
原创 leetcode38 Count and Say
package leetcode38;import java.util.ArrayList;/** * The count-and-say sequence is the sequence of integers beginning as follows: * 1, 11, 21, 1211, 111221, ... * * 1 is read off as "one 1" or
2015-10-21 16:24:51 302
原创 leetcode203 Remove Linked List Elements
Remove all elements from a linked list of integers that have value val.ExampleGiven: 1 --> 2 --> 6 --> 3 --> 4 --> 5 --> 6, val = 6Return: 1 --> 2 --> 3 --> 4 --> 5public class Solution {
2015-10-20 15:48:25 291
原创 leetcode15 3Sum
/**Given an array S of n integers, are there elements a, b, c in S such that a + b + c = 0? Find all unique triplets in the array which gives the sum of zero.*/import java.util.ArrayList;import jav
2015-10-14 16:55:48 221
原创 leetcode14 Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings.public class Solution { public String longestCommonPrefix(String[] strs) { StringBuilder sb = new StringBuil
2015-10-14 15:07:17 289
原创 leetcode11 Container With Most Water
Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Fin
2015-10-13 17:28:25 239
原创 leetcode8 String to Integer (atoi)
Implement atoi to convert a string to an integer.Hint: Carefully consider all possible input cases. If you want a challenge, please do not see below and ask yourself what are the possible input ca
2015-10-12 21:27:11 311
原创 leetcode5 Longest Palindromic Substring
Longest Palindromic SubstringGiven a string S, find the longest palindromic substring in S. You may assume that the maximum length of S is 1000, and there exists one unique longest palindromic subst
2015-10-11 19:52:01 275
原创 leetcode112 Path Sum
Path SumGiven a binary tree and a sum, determine if the tree has a root-to-leaf path such that adding up all the values along the path equals the given sum.For example:Given the below binary
2015-10-11 10:21:33 427
原创 leetcode21 Merge Two Sorted Lists
/*Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.*/public class Solution { public static ListNode merg
2015-10-09 09:59:55 242
原创 leetcode202 Happy Number
Write an algorithm to determine if a number is "happy".A happy number is a number defined by the following process: Starting with any positive integer, replace the number by the sum of the squares
2015-10-09 09:10:06 276
原创 矩阵相关运算的java实现
使用java实现的矩阵的相关运算,包括加、减、乘、乘方,矩阵乘方采用分治法实现/** * 矩阵的加、减、乘、乘方,其中两矩阵为同阶方阵 * @author * */public class Matrix { /* * 加法 */ public static int[][] add(int[][] A, int[][] B){ int[][] result = new i
2015-10-06 11:11:33 667
原创 leetcode206 Reverse Linked List
Reverse Linked ListReverse a singly linked list.public class Solution {public ListNode reverseList(ListNode head) {if(head==null || head.next==null)return head;if(head.next.next=
2015-10-05 22:17:05 296
原创 leetcode83 Remove Duplicates from Sorted List
Remove Duplicates from Sorted List My Submissions Question Solution Total Accepted: 79132 Total Submissions: 227516 Difficulty: EasyGiven a sorted linked list, delete all duplicates such that each
2015-10-05 21:38:31 245
原创 leetcode235 Lowest Common Ancestor of a Binary Search Tree
Lowest Common Ancestor of a Binary Search TreeGiven a binary search tree(BST), find the lowest common ancestor (LCA) of two given nodes in the BST.Accordingto the definition of LCA onWikipedia: “T
2015-10-03 21:37:53 248
原创 nyoj 60 谁获得了最高奖学金
谁获得了最高奖学金时间限制:1000 ms | 内存限制:65535 KB难度:2描述 某校的惯例是在每学期的期末考试之后发放奖学金。发放的奖学金共有五种,获取的条件各自不同: 1) 院士奖学金,每人8000元,期末平均成绩高于80分(>80),并且在本学期内发表1篇或1篇以上论文的学生均可获得; 2) 五四奖学金,每人4000元,期末平均成绩
2015-10-01 12:50:03 407
原创 Nyoj 10 skiing Java实现
Nyoj 10 skiing时间限制:3000 ms | 内存限制:65535 KB难度:5描述Michael喜欢滑雪百这并不奇怪,因为滑雪的确很刺激。可是为了获得速度,滑的区域必须向下倾斜,而且当你滑到坡底,你不得不再次走上坡或者等待升降机来载你。Michael想知道载一个区域中最长底滑坡。区域由一个二维数组给出。数组的每个数字代表点的高度。下面是一个例子 1 2 3
2015-10-01 09:56:07 352
原创 一种排序 Java实现
一种排序时间限制:3000 ms | 内存限制:65535 KB难度:3描述现在有很多长方形,每一个长方形都有一个编号,这个编号可以重复;还知道这个长方形的宽和长,编号、长、宽都是整数;现在要求按照一下方式排序(默认排序规则都是从小到大);1.按照编号从小到大排序2.对于编号相等的长方形,按照长方形的长排序;3.如果编号和长都相同,按照长方形的宽排序;
2015-09-30 16:38:40 698
原创 街区最短路径问题
街区最短路径问题时间限制:3000 ms | 内存限制:65535 KB难度:4描述一个街区有很多住户,街区的街道只能为东西、南北两种方向。住户只可以沿着街道行走。各个街道之间的间隔相等。用(x,y)来表示住户坐在的街区。例如(4,20),表示用户在东西方向第4个街道,南北方向第20个街道。现在要建一个邮局,使得各个住户到邮局的距离之和
2015-09-29 21:58:18 386
原创 nyoj6
喷水装置(一)时间限制:3000 ms | 内存限制:65535 KB难度:3描述现有一块草坪,长为20米,宽为2米,要在横中心线上放置半径为Ri的喷水装置,每个喷水装置的效果都会让以它为中心的半径为实数Ri(0的圆被湿润,这有充足的喷水装置i(1个,并且一定能把草坪全部湿润,你要做的是:选择尽量少的喷水装置,把整个草坪的全部湿润。输入第一行m表示有m组测试数据每
2015-09-29 19:38:58 418
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人