Anne

Anne.github.io


  • Home

  • About

  • Tags

  • Categories

  • Archives

PAT-B-1011-A+B和C

Posted on 2018-06-24
Read more »

PAT-B-1010-一元多项式求导

Posted on 2018-06-24 | In PAT-solutions

Question

设计函数求一元多项式的导数。(注:x^n^(n为整数)的一阶导数为n*x^n-1^。)

输入格式:以指数递降方式输入多项式非零项系数和指数(绝对值均为不超过1000的整数)。数字间以空格分隔。

输出格式:以与输入相同的格式输出导数多项式非零项的系数和指数。数字间以空格分隔,但结尾不能有多余空格。注意“零多项式”的指数和系数都是0,但是表示为“0 0”。

输入样例:

1
3 4 -5 2 6 1 -2 0

输出样例:

1
12 3 -10 1 6 0
Read more »

Jobdu-14-输出梯形

Posted on 2018-06-23 | In Jobdu

Question

题目描述:

输入一个高度h,输出一个高为h,上底边为h的梯形。

输入:
一个整数h(1<=h<=1000)。

输出:
h所对应的梯形。

样例输入:
4

样例输出:

1
2
3
4
****
******
********
**********
Read more »

374.Guess Number Higher or Lower

Posted on 2018-06-22 | In LeetCode

Binary Search, Easy

Question

We are playing the Guess Game. The game is as follows:

I pick a number from 1 to n. You have to guess which number I picked.

Every time you guess wrong, I’ll tell you whether the number is higher or lower.

You call a pre-defined API guess(int num) which returns 3 possible results (-1, 1, or 0):

1
2
3
-1 : My number is lower
1 : My number is higher
0 : Congrats! You got it!

Example:

1
2
3
n = 10, I pick 6.
Return 6.
Read more »

139.Word Break

Posted on 2018-06-22 | In LeetCode

Dynamic Programming, Medium

Question

Given a non-empty string s and a dictionary wordDict containing a list of non-empty words, determine if s can be segmented into a space-separated sequence of one or more dictionary words.

Note:

  • The same word in the dictionary may be reused multiple times in the segmentation.
  • You may assume the dictionary does not contain duplicate words.

Example 1:

1
2
3
Input: s = "leetcode", wordDict = ["leet", "code"]
Output: true
Explanation: Return true because "leetcode" can be segmented as "leet code".

Example 2:

1
2
3
4
Input: s = "applepenapple", wordDict = ["apple", "pen"]
Output: true
Explanation: Return true because "applepenapple" can be segmented as "apple pen apple".
Note that you are allowed to reuse a dictionary word.

Example 3:

1
2
Input: s = "catsandog", wordDict = ["cats", "dog", "sand", "and", "cat"]
Output: false
Read more »

279.Perfect Squares

Posted on 2018-06-22 | In LeetCode

Dynamic Programming, Medium

Question

Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, ...) which sum to n.

Example 1:

1
2
3
Input: n = 12
Output: 3
Explanation: 12 = 4 + 4 + 4.

Example 2:

1
2
3
Input: n = 13
Output: 2
Explanation: 13 = 4 + 9.
Read more »

63.Unique Paths II

Posted on 2018-06-22 | In LeetCode

Dynamic Programming, Medium

Question

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 bottom-right corner of the grid (marked ‘Finish’ in the diagram below).

Now consider if some obstacles are added to the grids. How many unique paths would there be?

img

An obstacle and empty space is marked as 1 and 0 respectively in the grid.

Note: m and n will be at most 100.

Example 1:

1
2
3
4
5
6
7
8
9
10
11
12
Input:
[
[0,0,0],
[0,1,0],
[0,0,0]
]
Output: 2
Explanation:
There is one obstacle in the middle of the 3x3 grid above.
There are two ways to reach the bottom-right corner:
1. Right -> Right -> Down -> Down
2. Down -> Down -> Right -> Right
Read more »

62.Unique Paths

Posted on 2018-06-22 | In LeetCode

Dynamic Programming, Medium

Question

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 bottom-right corner of the grid (marked ‘Finish’ in the diagram below).

How many possible unique paths are there?

img
Above is a 7 x 3 grid. How many possible unique paths are there?

Note: m and n will be at most 100.

Example 1:

1
2
3
4
5
6
7
Input: m = 3, n = 2
Output: 3
Explanation:
From the top-left corner, there are a total of 3 ways to reach the bottom-right corner:
1. Right -> Right -> Down
2. Right -> Down -> Right
3. Down -> Right -> Right

Example 2:

1
2
Input: m = 7, n = 3
Output: 28
Read more »

96.Unique Binary Search Trees

Posted on 2018-06-21 | In LeetCode

Tree, Medium

Question


Given n, how many structurally unique BST’s (binary search trees) that store values 1 … n?

Example:

1
2
3
4
5
6
7
8
9
10
Input: 3
Output: 5
Explanation:
Given n = 3, there are a total of 5 unique BST's:
1 3 3 2 1
\ / / / \ \
3 2 1 1 3 2
/ / \ \
2 1 2 3
Read more »

117.Populating Next Right Pointers in Each Node II

Posted on 2018-06-21 | In LeetCode

Tree, Medium

Question

Given a binary tree

1
2
3
4
5
struct TreeLinkNode {
TreeLinkNode *left;
TreeLinkNode *right;
TreeLinkNode *next;
}

Populate each next pointer to point to its next right node. If there is no next right node, the next pointer should be set to NULL.

Initially, all next pointers are set to NULL.

Note:

  • You may only use constant extra space.
  • Recursive approach is fine, implicit stack space does not count as extra space for this problem.

Example:

Given the following binary tree,

1
2
3
4
5
1
/ \
2 3
/ \ \
4 5 7

After calling your function, the tree should look like:

1
2
3
4
5
1 -> NULL
/ \
2 -> 3 -> NULL
/ \ \
4-> 5 -> 7 -> NULL
Read more »
1…567…14
Anne_ZAJ

Anne_ZAJ

boom pow

134 posts
14 categories
17 tags
0%
© 2019 Anne_ZAJ
Powered by Hexo
|
Theme — NexT.Pisces v5.1.3