- 博客(38)
- 收藏
- 关注
原创 leetcode--Populating Next Right Pointers in Each Node II
Follow up for problem "Populating Next Right Pointers in Each Node".What if the given tree could be any binary tree? Would your previous solution still work?Note:You may only use constant
2015-05-28 17:51:42 428
原创 leetcode-Contains Duplicate,STL unique,unique_copy等函数的使用
leetcode题目描述:Given an array of integers, find if the array contains any duplicates. Your function should return true if any value appears at least twice in the array, and it should return false if
2015-05-28 11:41:10 594
原创 leetcode---Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which minimizes the sum of all numbers along its path.Note: You can only move either down or right at
2015-05-20 16:44:25 515
原创 leetcode---Generate Parentheses
Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:"((()))", "(()())", "(())()", "()(())", "()()
2015-05-20 15:59:17 463
原创 leetcode--Gray Code
题目描述The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the se
2015-05-17 19:22:32 305
原创 leetcode--Sort Colors
题目描述:Given an array with n objects colored red, white or blue, sort them so that objects of the same color are adjacent, with the colors in the order red, white and blue.Here, we will use the
2015-05-17 17:27:29 334
原创 leetcode--Best Time to Buy and Sell Stock i ii iii
Best Time to Buy and Sell StockSay you have an array for which the ith element is the price of a given stock on day i.If you were only permitted to complete at most one transaction
2015-05-16 22:13:19 461
原创 leetcode--Swap Nodes in Pairs
Given a linked list, swap every two adjacent nodes and return its head.For example,Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use only constant space. Y
2015-05-16 18:38:52 364
原创 leetcode--Unique Paths
A robot is located at the top-left corner of a m x n grid (marked 'Start' in the diagram below).The robot can only move either down or right at any point in time. The robot is trying to reach the
2015-05-16 16:43:00 527
转载 栈和堆的区别--(内存和数据结构)
在计算机领域,堆栈是一个不容忽视的概念,我们编写的C语言程序基本上都要用到。但对于很多的初学着来说,堆栈是一个很模糊的概念。堆栈:一种数据结构、一个在程序运行时用于存放的地方,这可能是很多初学者的认识,因为我曾经就是这么想的和汇编语言中的堆栈一词混为一谈。我身边的一些编程的朋友以及在网上看帖遇到的朋友中有好多也说不清堆栈,所以我想有必要给大家分享一下我对堆栈的看法,有说的不对的地方请朋友们不吝赐教
2015-05-15 12:17:51 395
原创 将一个字符串部分前置
输入10个整形数,输入一个整形m,将整形数m个数字前置,如 1 2 3 4 5 6 7 8 9 10,m=3,输出 8 9 10 1 2 3 4 5 6 7解题思路:使用两个堆栈即可。代码如下:#include #includeusing namespace std;void main(){ int a[10]={0}; for (int i=0;i<10;i++)
2015-05-14 23:30:30 530
原创 leetcode-Convert Sorted Array to Binary Search Tree
题目描述:Given an array where elements are sorted in ascending order, convert it to a height balanced BST.即给定一个升序排列的数组,现在将它转换成一个平衡二叉树。解题思路;数组排好序,相当于我们最后y
2015-05-14 22:36:59 403
原创 leetcod--Reverse Bits
题目描述:everse bits of a given 32 bits unsigned integer.For example, given input 43261596 (represented in binary as 00000010100101000001111010011100), return 964176192 (represented in binary as00
2015-05-13 17:43:03 469
原创 24点算法
24点游戏的算法,其中最主要的思想就是穷举法。所谓穷举法就是列出4个数字加减乘除的各种可能性,包括括号的算法。我们可以将表达式分成以下几种:首先我们将4个数设为a,b,c,d,,其中算术符号有+,-,*,/,。其中有效的表达式有a,ab-cd,等等。列出所有有效的表达式。其中我们用枚举类型将符号定义成数字常量,比如用1表示+,2表示-等。如下是我对穷举法的一种编程语言。在编程的头部要对变量做下定义
2015-05-13 11:34:41 2429
原创 可怕的阶乘
计算阶乘n!是一件可怕的事情,因为当n并不是很大时,n!将是一个很大的值。例如13! = 6227020800,已经超过了我们常用的unsigned int类型的取值范围。请设计一个程序,使其可以计算100以内的数的阶乘,结果用字符串的形式输出详细描述:接口说明原型:void CalcNN(int n, char *pOut)输入参数:int n 需要计算的
2015-05-12 23:07:14 1089
原创 约瑟夫问题、约瑟夫环
约瑟夫问题(有时也称为约瑟夫斯置换,是一个出现在计算机科学和数学中的问题。在计算机编程的算法中,类似问题又称为约瑟夫环。又称“丢手绢问题”.)1问题来历编辑据说著名犹太历史学家 Josephus有过以下的故事:在罗马人占领乔塔帕特后,39 个犹太人与Josephus及他的朋友躲到一个洞中,39个犹太人决定宁愿死也不要被敌人抓到,于是决定了一个自杀方式,41个人排成一个圆圈,由第
2015-05-12 11:14:14 1916
原创 leetcode--Single Number II
题目描述Given an array of integers, every element appears three times except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it w
2015-05-11 17:59:08 442
原创 leetcode-Populating Next Right Pointers in Each Node
题目描述Given a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate each next pointer to point to its next righ
2015-05-10 20:10:58 462
原创 leetcode-Search Insert Position
题目描述Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in th
2015-05-10 18:33:17 345
原创 leetcode--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: Recu
2015-05-10 17:07:53 379
原创 leetcodeBinary Tree Inorder Traversal
题目描述Given a binary tree, return the inorder traversal of its nodes' values.For example:Given binary tree {1,#,2,3}, 1 \ 2 / 3return [1,3,2].Note: Recursi
2015-05-10 16:28:43 544
原创 leetcode--Linked List Cycle &Linked List Cycle II
Problem:Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?https://oj.leetcode.com/problems/linked-list-cycle/Problem II:
2015-05-10 15:26:04 549
原创 华为机试题--及格分数、亮灯个数
题目一:及格分数描述:10个学生考完期末考试评卷完成后,A老师需要划出及格线,要求如下:(1) 及格线是10的倍数;(2) 保证至少有60%的学生及格;(3) 如果所有的学生都高于60分,则及格线为60分 输入:输入10个整数,取值0~100输出:输出及格线,10的倍数输入样例:61 51 49 30 20 10 70 80 90 99输出样例:50代
2015-05-10 15:02:35 1112
原创 华为机试--地铁换乘问题
问题描述:描述:已知2条地铁线路,其中A为环线,B为东西向线路,线路都是双向的。经过的站点名分别如下,两条线交叉的换乘点用T1、T2表示。编写程序,任意输入两个站点名称,输出乘坐地铁最少需要经过的车站数量(含输入的起点和终点,换乘站点只计算一次)。地铁线A(环线)经过车站:A1 A2 A3 A4 A5 A6 A7 A8 A9 T1 A10 A11 A12 A13 T2 A14 A15
2015-05-10 14:52:06 1046
原创 leetcode-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 soluti
2015-05-09 17:43:19 652
原创 leetcode--Integer to Roman
题目描述:Given an integer, convert it to a roman numeral.Input is guaranteed to be within the range from 1 to 3999.题目解析:将一个整形数的罗马形式表示出来。罗马数字和整形数转换规则参考http://blog.csdn.net/sinat_24520925/arti
2015-05-09 17:04:36 378
原创 leetcode-Single Number
题目描述:Given an array of integers, every element appears twice except for one. Find that single one.Note:Your algorithm should have a linear runtime complexity. Could you implement it withou
2015-05-08 10:45:41 577
原创 leetcode-Unique Binary Search Trees:
题目描述:Given n, how many structurally unique BST's (binary search trees) that store values 1...n?For example,Given n = 3, there are a total of 5 unique BST's. 1 3 3 2
2015-05-07 15:55:39 648 2
原创 leetcode-Reverse Integer
题目描述Reverse digits of an integer.Example1: x = 123, return 321Example2: x = -123, return -321方法一:将数字转换为一串字符串,后将字符串逆转,再转成数字即可:代码如下: int reverse(int x) { int n; int flag=1;
2015-05-07 11:25:20 454
原创 leetcode-Add Two Numbers :
题目描述:You are given two linked lists representing two non-negative numbers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i
2015-05-07 10:13:32 432
原创 Binary Tree Level Order Traversal 、Binary Tree Level Order Traversal II
题目描述:Binary Tree Level Order TraversalGiven 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,
2015-05-06 11:09:22 472
原创 Reverse Linked List II
题目描述:Reverse a linked list from position m to n. Do it in-place and in one-pass.For example:Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.Note:Given m,
2015-05-05 11:54:23 374
原创 Symmetric Tree
题目描述:Given a binary tree, check whether it is a mirror of itself (ie, symmetric around its center).For example, this binary tree is symmetric: 1 / \ 2 2 / \ / \3 4 4 3
2015-05-04 21:35:38 360
原创 leetcode--Add binary
题目描述:Add BinaryGiven two binary strings, return their sum (also a binary string).For example,a = "11"b = "1"Return "100".解题思路:求两个二进制组成的数字的和。首先有几种特殊的情况,a、b均为空,a为空、b非空,a非空、b为空;我们
2015-05-04 16:06:30 480
原创 leetcode-Remove Duplicates from Sorted Array
题目描述Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in
2015-05-04 14:58:59 423
原创 Remove Duplicates from Sorted List
题目描述: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 1->1->2->3->3, return 1->2->3.解题思路:删除链表中
2015-05-04 10:51:17 378
原创 leetcode-Balanced Binary Tree
题目描述Given a binary tree, determine if it is height-balanced.For this problem, a height-balanced binary tree is defined as a binary tree in which the depth of the two subtrees of every node n
2015-05-04 09:56:51 505
原创 leetcode-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 "()[]{}" ar
2015-05-03 13:11:46 527
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人