自定义博客皮肤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/

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

原创 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 747

原创 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 483

原创 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 839

原创 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 1143

原创 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 286

原创 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 240

原创 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 373

原创 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 1098

原创 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 539

原创 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 655

原创 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 641

原创 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 806

原创 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 820

原创 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 2823 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 823

原创 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 1194

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

假设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 1250

原创 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 593

空空如也

空空如也

空空如也

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

TA关注的人 TA的粉丝

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