- 博客(74)
- 资源 (2)
- 收藏
- 关注
原创 1009 数字1的数量
给定一个十进制正整数N,写下从1开始,到N的所有正数,计算出其中出现所有1的个数。例如:n = 12,包含了5个1。1,10,12共包含3个1,11包含2个1,总共5个1。Input输入N(1 OutPut输出包含1的个数Input示例12Output示例5用f(n) 表示1-n所有数字中1的总数,len表示数字n的位数,g(x)
2015-01-27 12:53:52
772
原创 1083 矩阵取数问题
一个N*N矩阵中有不同的正整数,经过这个格子,就能获得相应价值的奖励,从左上走到右下,只能向下向右走,求能够获得的最大价值。例如:3 * 3的方格。1 3 32 1 32 2 1能够获得的最大价值为:11。Input第1行:N,N为矩阵的大小。(2 <= N <= 500)第2 - N + 1行:每行N个数,中间用空格隔开,对应格子中奖
2015-01-26 16:36:40
1518
原创 1007 正整数分组
将一堆正整数分为2组,要求2组的和相差最小。例如:1 2 3 4 5,将1 2 4分为1组,3 5分为1组,两组和相差1,是所有方案中相差最少的。Input第1行:一个数N,N为正整数的数量。第2 - N+1行,N个正整数。(N OutPut输出这个最小差Input示例512345Output示例1题目实为0-1背包
2015-01-26 15:47:43
1116
原创 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.Note:Elements in a triplet (a,b,
2015-01-17 18:19:39
609
原创 Scramble String
Given a string s1, we may represent it as a binary tree by partitioning it to two non-empty substrings recursively.Below is one possible representation of s1 = "great": great / \ g
2014-12-22 21:46:18
702
原创 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,#,#,15,7}, 3 / \ 9 20
2014-12-22 19:32:24
507
原创 Wildcard Matching
Implement wildcard pattern matching with support for '?' and '*'.'?' Matches any single character.'*' Matches any sequence of characters (including the empty sequence).The matching should cover
2014-12-21 20:22:54
741
原创 Unique Paths II
Follow up for "Unique Paths":Now consider if some obstacles are added to the grids. How many unique paths would there be?An obstacle and empty space is marked as 1 and 0 respectively in the gr
2014-12-20 20:19:59
451
原创 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 th
2014-12-20 20:04:40
529
原创 Maximum Subarray
Find the contiguous subarray within an array (containing at least one number) which has the largest sum.For example, given the array [−2,1,−3,4,−1,2,1,−5,4],the contiguous subarray [4,−1,2,1]
2014-12-20 19:52:58
421
原创 Minimum Path Sum
Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right whichminimizes the sum of all numbers along its path.Note: You can only move either down or right
2014-12-20 19:02:04
512
原创 Combinations
Given two integers n and k, return all possible combinations ofk 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],
2014-12-14 16:52:20
447
原创 Triangle
Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below.For example, given the following triangle[ [2], [3,4],
2014-12-10 22:20:36
493
原创 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 3But the
2014-12-10 16:16:58
515
原创 Same Tree
Given 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 same value/** * Defi
2014-12-10 15:16:56
508
原创 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, n satisfy the
2014-12-08 19:48:05
446
原创 Binary 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: Recursive solution
2014-12-08 19:20:39
471
原创 Path Sum
Given 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 tree and s
2014-12-08 19:11:24
433
原创 Convert Sorted List to Binary Search Tree
Given a singly linked list where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for singly-linked list. * struct ListNode { * int val; * Lis
2014-12-08 16:53:04
500
原创 Convert Sorted Array to Binary Search Tree
Given an array where elements are sorted in ascending order, convert it to a height balanced BST./** * Definition for binary tree * struct TreeNode { * int val; * TreeNode *left; *
2014-12-04 22:55:39
458
原创 平衡二叉树的的插入
平衡二叉树的建立:#include #include #include using namespace std; struct TreeNode { int val; int bf; TreeNode *left; TreeNode *right; TreeNode(int x) : val(x),bf(0), left(NUL
2014-12-04 22:22:29
433
原创 Text Justification
Given an array of words and a length L, format the text such that each line has exactlyL characters and is fully (left and right) justified.You should pack your words in a greedy approach; tha
2014-12-04 11:57:06
428
原创 Restore IP Addresses
Given a string containing only digits, restore it by returning all possible valid IP address combinations.For example:Given "25525511135", return ["255.255.11.135", "255.255.111.35"]. (Order
2014-12-03 20:52:03
509
原创 Next Permutation
Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possib
2014-12-03 17:40:06
416
原创 Reverse Nodes in k-Group
Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it
2014-12-02 21:57:44
499
原创 Permutations II
Given a collection of numbers that might contain duplicates, return all possible unique permutations.For example,[1,1,2] have the following unique permutations:[1,1,2], [1,2,1], and [2,1,1].
2014-12-02 21:07:47
409
原创 Permutations
Given a collection of numbers, return all possible permutations.For example,[1,2,3] have the following permutations:[1,2,3], [1,3,2], [2,1,3], [2,3,1],[3,1,2], and [3,2,1]. class Solutio
2014-12-02 20:52:36
527
原创 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./** * Definition for singly-linked list. * struct L
2014-12-02 20:26:16
419
原创 Merge k Sorted Lists
Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity1.非递归归并/** * Definition for singly-linked list. * struct ListNode { * int val; * Li
2014-12-02 20:00:30
510
原创 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 1 \
2014-12-01 21:00:41
394
原创 Unique Binary Search Trees II
Given n, generate all structurally unique BST's (binary search trees) that store values 1...n.For example,Given n = 3, your program should return all 5 unique BST's shown below. 1
2014-12-01 20:50:50
437
原创 Count and Say
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 11.11 is read off as "two 1s" or 21.21 is read off as "
2014-12-01 19:29:50
382
原创 Word Break II
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word.Return all such possible sentences. For example, givens
2014-12-01 18:09:03
381
原创 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 without u
2014-11-30 22:49:36
399
原创 Word Break
Given a string s and a dictionary of words dict, determine if s can be segmented into a space-separated sequence of one or more dictionary words.For example, givens = "leetcode",dict = ["l
2014-11-30 22:09:03
375
原创 Copy List with Random Pointer
A linked list is given such that each node contains an additional random pointer which could point to any node in the list or null.Return a deep copy of the list/** * Definition for singly-li
2014-11-30 20:26:20
429
原创 Gas Station
There are N gas stations along a circular route, where the amount of gas at stationi is gas[i].You have a car with an unlimited gas tank and it costs cost[i] of gas to travel from stationi t
2014-11-30 20:25:06
396
原创 1090. Highest Price in Supply Chain
A supply chain is a network of retailers(零售商), distributors(经销商), and suppliers(供应商)-- everyone involved in moving a product from supplier to customer.Starting from one root supplier, everyone on th
2014-11-30 15:31:09
1846
原创 1089. Insert or Merge (25)
1089. Insert or Merge (25)时间限制 200 ms内存限制 65536 kB代码长度限制 16000 B判题程序 Standard 作者 CHEN, YueAccording to Wikipedia:Insertion sort iterates, consumin
2014-11-30 10:45:19
2090
原创 1088. Rational Arithmetic (20)
1088. Rational Arithmetic (20)时间限制 200 ms内存限制 65536 kB代码长度限制 16000 B判题程序 Standard 作者 CHEN, YueFor two rational numbers, your task is to implement th
2014-11-30 10:36:43
1625
devshl.dll
2014-06-10
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人