Description Today, the math teacher taught Alice Hui Yang’s triangle. However, the teacher came up with a new one, called Sama’s triangle (some of you may be familiar with this name). In this triangle, there is only 30 row, and the ith row has…
Total Accepted: 32628 Total Submissions: 129569 Difficulty: Medium Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is comple…
Count the number of prime numbers less than a non-negative number, n. 计算小于n的质数的个数,当然就要用到大名鼎鼎的筛法了,代码如下,写的有点乱不好意思. class Solution { public: int countPrimes(int n) { vector<, ); vector<int> ret; ; i <= n; ++i) vtor[i] = i; ; i < n; ++i){//边界条件…
Given a complete binary tree, count the number of nodes. Definition of a complete binary tree from Wikipedia:In a complete binary tree every level, except possibly the last, is completely filled, and all nodes in the last level are as far left as pos…
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 "one 2, then one 1" or 1211. Given an…
Description Old Sama is a great and powerful magician in the word. One day, a little girl, Anny, touched Sama’s crystal and broke into his magic 2D space. However, Sama is very amiable. So he wanted to send Anny back to the real world instead of trap…
Description Give you a number S of length n,you can choose a position and remove the number on it.After that,you will get a new number. More formally,you choose a number x(1<=x<=n),then you will get the number Rx=S1S2…..Sx-1 Sx+1……Sn..The problem is…
Description Cyy likes something symmetrical, and Han Move likes something circular. Han Move gave you a circular string whose length is N, i.e. the i-th character of the string is the neighbor of the ( (i-1) mod N )-th character and ( (i+1)…
Farmer John has a farm. Betsy, a famous cow, loves running in farmer John's land. The noise she made makes John mad. So he wants to restrict the area Betsy can run. There are nn (4<n\le 20000004<n≤2000000) points of interest (or POI) on the farm, th…
All LeetCode Questions List(Part of Answers, still updating) 题目汇总及部分答案(持续更新中) Leetcode problems classified by company 题目按公司分类(Last updated: October 2, 2017) . Top Interview Questions # Title Difficulty Acceptance 1 Two Sum Medium 17.70% 2 Add Two N…
1.day2题目 1.判断下列逻辑语句的True,False. 1)1 > 1 or 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2)not 2 > 1 and 3 < 4 or 4 > 5 and 2 > 1 and 9 > 8 or 7 < 6 2.求出下列逻辑语句的值. 1),8 or 3 and 4 or 2 and 0 or 9 and 7 2),0 or 2 and 3 and…
using UnityEngine; using System.Collections; using System.Collections.Generic; public struct SegmentPoint { public Vector3 normal; public Vector3 pos; }; public class DrawMesh_Plane : MonoBehaviour { MeshFilter meshFilter; /// <summary> /// 面片…
Problem Link: http://oj.leetcode.com/problems/pascals-triangle-ii/ Let T[i][j] be the j-th element of the i-th row in the triangle, for 0 <= j <= i, i = 0, 1, ... And we have the recursive function for T[i][j] T[i][j] = 1, if j == 0 or j == i T[i][j…
Prolbem Link: http://oj.leetcode.com/problems/pascals-triangle/ Just a nest-for-loop... class Solution: # @return a list of lists of integers def generate(self, numRows): # Initialize the triangle res = [] for i in xrange(numRows): res.append([1] * (…
Problem Link: http://oj.leetcode.com/problems/triangle/ Let R[][] be a 2D array where R[i][j] (j <= i) is the minimum sum of the path from triangle[0][0] to tirangle[i][j]. We initialize R[0][0] = triangle[0][0], and update R[][] from i = 1 to n-1: R…
Given an array of integers, how many three numbers can be found in the array, so that we can build an triangle whose three edges length is the three numbers that we find? Example Given array S = [3,4,6,7], return 3. They are: [3,4,6] [3,6,7] [4,6,7]…
Time limit: 30.000 seconds限时30.000秒 Problem问题 A triangle is a basic shape of planar geometry. It consists of three straight lines and three angles in between. Figure 1 shows how the sides and angles are usually labeled. Figure: Triangle A look into a…
Total Accepted: 31557 Total Submissions: 116793 Given a triangle, find the minimum path sum from top to bottom. Each step you may move to adjacent numbers on the row below. [ [2], [3,4], [6,5,7], [4,1,8,3] ] The minimum path sum from top to botto…
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 [ [], [,4], [6,,7], [4,,8,3] ] The minimum path sum from top to bottom is 11 (i.e.,…
Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Return [1,3,3,1]. Note:Could you optimize your algorithm to use only O(k) extra space? [思路] 我们为了满足空间复杂度的要求,我们新建两个ArrayList,一个负责存储上一个Pascal行的结果,一个根据上一个Pascal行得出当前P…
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] Subscribe to see which companies asked this question [思路] 这道题目很简单,代码如下: public class Solution { publ…
Given numRows, generate the first numRows of Pascal's triangle. For example, given numRows = 5,Return [ [1], [1,1], [1,2,1], [1,3,3,1], [1,4,6,4,1] ] 帕斯卡三角,很简单的问题,见代码: class Solution { public: vector<vector<int>> generate(int numRows) { vector…
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 [ [], [,4], [6,,7], [4,,8,3] ] 一开始的题目的意思理解错了 ,以为是位数相差一就是临近的意思,但实际上这里意思是图形上面的那种临近,和原…
题目: Given an array of integers, how many three numbers can be found in the array, so that we can build an triangle whose three edges length is the three numbers that we find? Example Given array S = [3,4,6,7], return 3. They are: [3,4,6] [3,6,7] [4,6…