自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

nudt_oys的博客

欢迎访问个人网站:https://www.cnblogs.com/littleorange/

  • 博客(288)
  • 收藏
  • 关注

原创 POJ 3264 Balanced Lineup(线段树区间查询)

Balanced Lineup       DescriptionFor the daily milking, Farmer John's N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decide

2017-08-12 13:33:43 451

原创 LeetCode 103 Binary Tree Zigzag Level Order Traversal(二叉树层序遍历)

Given a binary tree, return the zigzag level order traversal of its nodes' values. (ie, from left to right, then right to left for the next level and alternate between).For example:Given binary tr

2017-08-11 21:09:14 874

原创 LeetCode 155 Min Stack(实现具有特殊操作的栈)

Design a stack that supports push, pop, top, and retrieving the minimum element in constant time.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get

2017-08-10 13:04:42 845

原创 LeetCode 654 Maximum Binary Tree(构建二叉搜索树)

Given an integer array with no duplicates. A maximum tree building on this array is defined as follow:The root is the maximum number in the array.The left subtree is the maximum tree constructed f

2017-08-06 19:11:58 1067

原创 LeetCode 304 Range Sum Query 2D - Immutable(维护二维数组的前缀和)

Given a 2D matrix matrix, find the sum of the elements inside the rectangle defined by its upper left corner (row1, col1) and lower right corner (row2, col2).The above rectangle (with the red bo

2017-08-04 18:37:10 878

原创 LeetCode 303 Range Sum Query - Immutable(维护前缀和)

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive.Example:Given nums = [-2, 0, 3, -5, 2, -1]sumRange(0, 2) -> 1sumRange(2, 5) -> -1sumRan

2017-08-03 19:17:45 812

原创 HDOJ 1754 I Hate It(线段树)

I Hate ItProblem Description很多学校流行一种比较的习惯。老师们很喜欢询问,从某某到某某当中,分数最高的是多少。这让很多学生很反感。不管你喜不喜欢,现在需要你做的是,就是按照老师的要求,写一个程序,模拟老师的询问。当然,老师有时候需要更新某位同学的成绩。 Input本题目包含多组测试,请处理到文件结束。在每个测试的第一行

2017-08-02 13:25:40 273

原创 LeetCode 307 Range Sum Query - Mutable(树状数组 || 线段树)

Given an integer array nums, find the sum of the elements between indices i and j (i ≤ j), inclusive. The update(i, val) function modifies nums by updating the element at index i to val.Example:Given

2017-07-30 21:18:55 861

原创 LeetCode 108 Convert Sorted Array to Binary Search Tree(二分 + 递归建树)

Given an array where elements are sorted in ascending order, convert it to a height balanced BST.题目大意:给出一个已经排好序的数组,构建一棵二叉搜索树。解题思路:采用二分法,递归地构建BST。注意二分结束条件。代码如下:/** * Definition for a binary

2017-07-24 21:26:23 567

原创 LeetCode 646 Maximum Length of Pair Chain(贪心)

You are given n pairs of numbers. In every pair, the first number is always smaller than the second number.Now, we define a pair (c, d) can follow another pair (a, b) if and only if b . Chain

2017-07-23 13:58:20 929

原创 LeetCode 637 Average of Levels in Binary Tree(二叉树层序遍历)

Given a non-empty binary tree, return the average value of the nodes on each level in the form of an array.Example 1:Input: 3 / \ 9 20 / \ 15 7Output: [3, 14.5, 11]Explanat

2017-07-21 19:05:21 1267

原创 LeetCode 513 Find Bottom Left Tree Value(二叉树层序遍历)

Given a binary tree, find the leftmost value in the last row of the tree.Example 1:Input: 2 / \ 1 3Output:1Example 2: Input: 1 / \ 2 3 / /

2017-07-19 19:49:55 391

原创 LeetCode 515 Find Largest Value in Each Tree Row(二叉树层序遍历)

You need to find the largest value in each row of a binary tree.Example:Input: 1 / \ 3 2 / \ \ 5 3 9 Output: [1, 3, 9]题目大意:给出一棵二叉树,求出每一层的最

2017-07-18 19:44:42 335

原创 LeetCode 232 Implement Queue using Stacks(利用栈实现队列)

Implement the following operations of a queue using stacks.push(x) -- Push element x to the back of queue.pop() -- Removes the element from in front of queue.peek() -- Get the front element.empty(

2017-07-18 18:56:06 517

原创 LeetCode 225 Implement Stack using Queues(利用队列实现栈)

Implement the following operations of a stack using queues.push(x) -- Push element x onto stack.pop() -- Removes the element on top of the stack.top() -- Get the top element.empty() -- Return whet

2017-07-18 13:21:46 1260

原创 LeetCode 319 Bulb Switcher(数学Tricks)

There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it's off or turning off

2017-07-17 13:53:37 642

原创 LeetCode 198 House Robber(基础DP)

You are a professional robber planning to rob houses along a street. Each house has a certain amount of money stashed, the only constraint stopping you from robbing each of them is that adjacent house

2017-07-15 21:29:17 745

原创 LeetCode 199 Binary Tree Right Side View(二叉树层序遍历)

Given a binary tree, imagine yourself standing on the right side of it, return the values of the nodes you can see ordered from top to bottom.For example:Given the following binary tree, 1

2017-07-14 22:41:47 738

原创 LeetCode 102 Binary Tree Level Order Traversal(二叉树层序遍历)

Given a binary tree, return the level order traversal of its nodes' values. (ie, from left to right, level by level).For example:Given binary tree [3,9,20,null,null,15,7], 3 / \ 9 20

2017-07-13 19:51:18 934

原创 LeetCode 129 Sum Root to Leaf Numbers(递归求和)

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number 123.Find the total

2017-07-12 20:04:54 941

原创 LeetCode 38 Count and Say(字符串生成)

The count-and-say sequence is the sequence of integers with the first five terms as following:1. 12. 113. 214. 12115. 1112211 is read off as "one 1" or 11.11 is read o

2017-07-08 08:47:08 2990 1

原创 LeetCode 98 Validate Binary Search Tree(判断二叉搜索树)

Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than the node’s key. The r

2017-07-05 20:14:38 915

原创 LeetCode 20 Valid Parentheses(用栈判断括号匹配)

Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.The brackets must close in the correct order, "()" and "()[]{}" are all vali

2017-07-04 19:42:48 1332

原创 利用归并排序求逆序数

假设A[1…n]是一个有n个不同元素的数组,若i < j 且 A[i] > A[j],则对偶(i, j)称为A的一个逆序对。例如,对于数组[2, 3, 8, 6, 1],它的所有逆序对为(1, 5),(2, 5),(3, 4),(3, 5),(4, 5),共有5个逆序对,所以逆序数为5。  当数组中元素数量较少时,我们可以通过手工计算数组的逆序数;但是如果数组中元素比较多时,手工计算比较麻烦,我们

2017-07-03 20:47:21 1403

原创 LeetCode 14 Longest Common Prefix(最长公共前缀)

Write a function to find the longest common prefix string amongst an array of strings.题目大意:写一个函数,找出一组字符串的最长公共字串。解题思路:以第一个字符串为参照,逐个比较第一个字符串的第i个字符和其他字符串的第i个字符,直到遇到不相等的字符退出循环。代码如下:char* longestCo

2017-07-03 19:58:54 678

原创 LeetCode 563 Binary Tree Tilt(递归 + 中间结果保存)

Given a binary tree, return the tilt of the whole tree.The tilt of a tree node is defined as the absolute difference between the sum of all left subtree node values and the sum of all right subtree

2017-06-30 19:59:05 446

原创 LeetCode 538 Convert BST to Greater Tree(二叉树的右中左遍历)

Given a Binary Search Tree (BST), convert it to a Greater Tree such that every key of the original BST is changed to the original key plus sum of all keys greater than the original key in BST.Exampl

2017-06-29 19:19:44 522

原创 LeetCode 606 Construct String from Binary Tree

You need to construct a string consists of parenthesis and integers from a binary tree with the preorder traversing way.The null node needs to be represented by empty parenthesis pair "()". And you

2017-06-29 09:11:29 362

原创 LeetCode 617 Merge Two Binary Trees(递归合并二叉树)

Given two binary trees and imagine that when you put one of them to cover the other, some nodes of the two trees are overlapped while the others are not.You need to merge them into a new binary tree

2017-06-27 23:51:40 2457

原创 LeetCode 257 Bianry 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"]题目大意:给出一个二叉树,返回其所

2017-06-25 23:28:08 581

原创 CSS中的相对定位和绝对定位

相对定位   在CSS中,我们可以将position属性的值设置成relative来对元素进行相对定位。如果对某元素设置了相对定位,那么该元素仍然会出现在标准文档流中它原本的位置。然后我们可以通过设置left、top等属性,让这个元素以它原来的位置为参照物进行移动。只要position属性的值为relative,无论是否对该元素进行移动,元素仍然占有原来的空间。因此,使用相对定位移动元素会使它覆盖

2017-06-14 23:58:37 429

原创 LeetCode 1 Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same 

2017-05-31 18:30:28 510

原创 LeetCode 507 Perfect Number(完美数字)

We define the Perfect Number is a positive integer that is equal to the sum of all its positive divisors except itself.Now, given an integer n, write a function that returns true when it is a perfec

2017-05-29 14:57:34 2433

原创 LeetCode 145 Binary Tree Postorder Traversal(二叉树后序遍历)

Given a binary tree, return the postorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [3,2,1].Note: Recursive solution is t

2017-05-28 09:56:05 609

原创 LeetCode 144 Binary Tree Preorder Traversal(二叉树前序遍历)

Given a binary tree, return the preorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,2,3].Note: Recursive solution is tr

2017-05-28 09:48:56 657

原创 LeetCode 94 Binary Tree Inorder Traversal(二叉树中序遍历)

Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree [1,null,2,3], 1 \ 2 / 3return [1,3,2].Note: Recursive solution is

2017-05-28 09:29:13 816

原创 LeetCode 450 Delete Node in a BST(删除BST节点)

Given a root node reference of a BST and a key, delete the node with the given key in the BST. Return the root node reference (possibly updated) of the BST.Basically, the deletion can be divided int

2017-05-24 16:12:37 583

原创 C语言宏定义小结

在C语言中,宏定义的形式如下: #define name replacement-text  这是最简单的一种宏替换——后续所有出现name的地方都会被替换成replacement-text。#define指令中的name与普通变量名的命名方式相同,而replacement-text可以是任意的字符串。如果一个宏定义比较长,可以在待续行的末尾加上一个反斜杠\。就像下面这样: #defi

2017-05-22 23:04:49 504

原创 LeetCode 23 Merge k Sorted Lists(归并)

Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.题目大意:合并k个有序链表并分析时间复杂度。解题思路:每两个链表进行一次合并,再对合并好的链表重复上述过程。k个链表需要合并O(k)次,每次合并需要O(n)的时间,所以总的时间复杂度为O(kn)。

2017-05-19 22:00:41 944

原创 LeetCode 160 Intersection of Two Linked Lists(链表)

Write a program to find the node at which the intersection of two singly linked lists begins.For example, the following two linked lists:A: a1 → a2 ↘

2017-05-19 17:09:29 656

空空如也

空空如也

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

TA关注的人

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