- 博客(17)
- 资源 (5)
- 收藏
- 关注
原创 leetcode-169-Majority Element
Majority ElementGiven an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-emp
2015-06-30 20:20:47 387
原创 leetcode-51-N-Queens
N-QueensThe n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions
2015-06-27 00:37:47 536
原创 leetcode-116-Populating Next Right Pointers in Each Node
Populating Next Right Pointers in Each NodGiven a binary tree struct TreeLinkNode { TreeLinkNode *left; TreeLinkNode *right; TreeLinkNode *next; }Populate
2015-06-26 19:47:37 403
原创 八皇后
八皇后(可以扩展为N皇后问题)每行每列每个对角线都不允许有两个或两个以上的皇后回溯,递归求解#include/// 八皇后#includeusing namespace std;int c[10]; /// 第i行 列为a[i]int total;int n;/// 在一条主对角线上 则它们的 x-y相同 y=x+b/// 在一条负对角线上 则它们的 x+y相
2015-06-23 22:22:20 943
原创 leetcode-52-N-Queens II
N-Queens II Follow up for N-Queens problem.Now, instead outputting board configurations, return the total number of distinct solutions.n皇后问题 详文请见八皇后leetcode AC代码class
2015-06-23 21:38:00 581
原创 leetcode-206-Reverse Linked List
Reverse Linked ListReverse a singly linked list.click to show more hints.Hint:A linked list can be reversed either iteratively or recursively. Could you implement both?反转一个链表,用栈实现
2015-06-22 23:36:20 425
原创 leetcode-35-Search Insert Position
Search Insert PositionGiven 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
2015-06-22 22:49:14 383
原创 leetcode-141-Linked List Cycle
Linked List Cycle Given a linked list, determine if it has a cycle in it.Follow up:Can you solve it without using extra space?判断链表是否有环/** * Definition for singly-linked list. *
2015-06-22 22:04:06 385
原创 leetcode-226-Invert Binary Tree
Invert Binary TreeInvert a binary tree. 4 / \ 2 7 / \ / \1 3 6 9to 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this orig
2015-06-21 23:28:08 382
原创 leetcode-94-Binary Tree Inorder Traversal
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 / 3
2015-06-21 23:08:45 385
原创 中序遍历
#include ///中序遍历#include#includeusing namespace std;typedef struct Node{ int k; Node *lchild,*rchild;}Node,*Link;Link p;int x;void create(Link& T){ scanf("%d",&x); if(x==-1)
2015-06-21 21:37:31 487
原创 leetcode-217-Contains Duplicate
Contains Duplicate 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 retur
2015-06-21 03:07:19 363
原创 leetcode-136-Single Number
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 implem
2015-06-21 01:58:44 386
原创 leetcode-191-Number of 1 Bits
Number of 1 BitsWrite a function that takes an unsigned integer and returns the number of ’1' bits it has (also known as the Hamming weight).For example, the 32-bit integer ’11'
2015-06-21 01:51:10 261
原创 leetcode-100-Same Tree
Same TreeGiven two binary trees, write a function to check if they are equal or not.Two binary trees are considered equal if they are structurally identical and the nodes have the
2015-06-21 01:40:35 375
原创 leetcode-104-Maximum Depth of Binary Tree
Maximum Depth of Binary TreeGiven a binary tree, find its maximum depth.The maximum depth is the number of nodes along the longest path from the root node down to the farthest leaf nod
2015-06-20 13:10:25 469
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人