自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(153)
  • 收藏
  • 关注

原创 关于string,const char*,char*的互转问题

首先需要明确的是:string自带的c_str() 可以返回一个指向string对象首字符的c语言风格字符指针(const char*)也就是说const char* 可以用来接收c_str() 的返回值,但是char* 不可以所以有:1.a. string s 转为 const char* const char* cc = s.c_str();//(其实这样转不安全,如果s被析构了或者s内容被改了,cc要么指向一片内存垃圾,要么指向的内容被改了自己却不知道)1.b. string

2021-10-01 22:38:38 338

原创 用sand(),rand()随机生成浮点数double

生成-150到150的随机数 srand(time(0)); double x = (double)rand()/RAND_MAX*300-150;生成a到b的随机数 srand(time(0)); double x = (double)rand()/RAND_MAX*(b-a)+a;

2021-01-18 16:38:31 2338 1

原创 12. Integer to Roman

Integer to RomanRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X 10L 50C 100D 500M 1000For example, 2.

2020-11-18 20:48:21 211

原创 119. Pascal‘s Triangle II

Pascal’s Triangle IIGiven an integer rowIndex, return the rowIndexth row of the Pascal’s triangle.Notice that the row index starts from 0.In Pascal’s triangle, each number is the sum of the two numbers directly above it.Follow up:Could you optimize.

2020-11-02 20:41:41 127

原创 用pair<int,int>建立优先队列(小根堆)

比较对象是pair的第一个元素priority_queue<pair<int,int>,vector<pair<int,int>>,greater<pair<int,int>>>pq;取元素1.pq.top().first;2.pq.top().second;

2020-10-28 10:57:05 2876 2

原创 1337. The K Weakest Rows in a Matrix

The K Weakest Rows in a MatrixGiven a m * n matrix mat of ones (representing soldiers) and zeros (representing civilians), return the indexes of the k weakest rows in the matrix ordered from the weakest to the strongest.A row i is weaker than row j, if.

2020-10-28 10:55:06 99

原创 38. Count and Say

Count and SayThe count-and-say sequence is a sequence of digit strings defined by the recursive formula:countAndSay(1) = “1”countAndSay(n) is the way you would “say” the digit string from countAndSay(n-1), which is then converted into a different digi.

2020-10-23 19:30:30 235

原创 1518. Water Bottles

Water BottlesGiven numBottles full water bottles, you can exchange numExchange empty water bottles for one full water bottle.The operation of drinking a full water bottle turns it into an empty bottle.Return the maximum number of water bottles you can.

2020-10-20 23:13:45 245

原创 1493. Longest Subarray of 1‘s After Deleting One Element

Longest Subarray of 1’s After Deleting One ElementGiven a binary array nums, you should delete one element from it.Return the size of the longest non-empty subarray containing only 1’s in the resulting array.Return 0 if there is no such subarray.Exam.

2020-10-09 20:36:11 125

原创 1253. Reconstruct a 2-Row Binary Matrix

Reconstruct a 2-Row Binary MatrixMedium869Add to ListShareGiven the following details of a matrix with n columns and 2 rows :The matrix is a binary matrix, which means each element in the mat...

2020-04-14 12:18:36 167

原创 1276. Number of Burgers with No Waste of Ingredients

Number of Burgers with No Waste of IngredientsMedium6177Add to ListShareGiven two integers tomatoSlices and cheeseSlices. The ingredients of different burgers are as follows:Jumbo Burger: 4 t...

2020-04-14 11:47:00 156

原创 1282. Group the People Given the Group Size They Belong To

Group the People Given the Group Size They Belong ToMedium194121Add to ListShareThere are n people whose IDs go from 0 to n - 1 and each person belongs exactly to one group. Given the array gr...

2020-04-14 11:13:14 217

原创 1296. Divide Array in Sets of K Consecutive Numbers

Divide Array in Sets of K Consecutive NumbersMedium19919Add to ListShareGiven an array of integers nums and a positive integer k, find whether it’s possible to divide this array into sets of k...

2020-04-13 16:41:47 168

原创 1338. Reduce Array Size to The Half

Reduce Array Size to The HalfMedium11114Add to ListShareGiven an array arr. You can choose a set of integers and remove all the occurrences of these integers in the array.Return the minimum ...

2020-04-13 16:18:46 130

原创 1400. Construct K Palindrome Strings

Construct K Palindrome StringsMedium699Add to ListShareGiven a string s and an integer k. You should construct k non-empty palindrome strings using all the characters in s.Return True if you ...

2020-04-13 14:46:33 245

原创 2020中南大学研究生招生夏令营机试题

2020中南大学研究生招生夏令营机试题1.缺失的彩虹1.缺失的彩虹题目描述众所周知,彩虹有7种颜色,我们给定七个 字母和颜色 的映射,如下所示:‘A’ -> “red”‘B’ -> “orange”‘C’ -> “yellow”‘D’ -> “green”‘E’ -> “cyan”‘F’ -> “blue”‘G’ -> “purple”...

2020-04-12 22:37:14 538

原创 2019年中南大学研究生复试机试题

2019年中南大学研究生复试机试题爬楼梯游戏爬楼梯游戏题目描述现有n阶楼梯,PIPI从第一阶走到第n阶,每次可以跨一阶或者两阶,问PIPI从第一阶走到第n阶总共有多少种可能。为了防止结果过大,需要让结果对p取模。ps: p = 1e9+7.输入输入包含多组测试用例。每组样例第一行输入楼梯的阶数n。(1<=n<=1000000)输出对于每组样例,输出方案数。最后结果对1...

2020-04-10 16:41:22 589

原创 2019年中南大学研究生招生夏令营机试题

2019年中南大学研究生招生夏令营机试题最小花费最小花费题目描述在n个人中,某些人的银行账号之间可以互相转账。这些人之间转账的手续费各不相同。给定这些人之间转账时需要从转账金额里扣除百分之几的手续费,请问A最少需要多少钱使得转账后B收到100元。输入输入包含多组测试用例。对于每组样例,第一行输入两个正整数n,m,分别表示总人数和可以互相转账的人的对数。(0<n<=2000...

2020-04-10 16:32:23 553

原创 6. ZigZag Conversion

ZigZag ConversionMedium14794240Add to ListShareThe string “PAYPALISHIRING” is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed ...

2020-04-08 20:29:46 124

原创 3. Longest Substring Without Repeating Characters

Longest Substring Without Repeating CharactersMedium8259500Add to ListShareGiven a string, find the length of the longest substring without repeating characters.Example 1:Input: “abcabcbb”O...

2020-04-08 17:43:57 122

原创 171. Excel Sheet Column Number(int不行就换unsigned long)

Excel Sheet Column NumberEasy807140Add to ListShareGiven a column title as appear in an Excel sheet, return its corresponding column number.For example:A -> 1B -> 2C -> 3...Z -&...

2020-04-08 16:38:14 131

原创 28. Implement strStr()

Implement strStr()Easy13571740Add to ListShareImplement strStr().Return the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.Example 1:Input: hay...

2020-04-08 15:05:11 80

原创 27. Remove Element

Remove ElementEasy12212464Add to ListShareGiven an array nums and a value val, remove all instances of that value in-place and return the new length.Do not allocate extra space for another ar...

2020-04-08 14:59:48 66

原创 26. Remove Duplicates from Sorted Array

Remove Duplicates from Sorted ArrayEasy22194634Add to ListShareGiven a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do n...

2020-04-08 14:49:37 63

原创 20. Valid Parentheses,括号匹配,一看就懂

Valid ParenthesesEasy4411203Add to ListShareGiven a string containing just the characters ‘(’, ‘)’, ‘{’, ‘}’, ‘[’ and ‘]’, determine if the input string is valid.An input string is valid if:...

2020-04-08 14:23:05 91

原创 13. Roman to Integer

Roman to IntegerEasy19173305Add to ListShareRoman numerals are represented by seven different symbols: I, V, X, L, C, D and M.Symbol ValueI 1V 5X ...

2020-04-08 14:11:16 78

原创 9. Palindrome Number

Palindrome NumberEasy20581499Add to ListShareDetermine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Input: 121Output: ...

2020-04-08 13:56:52 89

原创 1088: 回文串询问Ⅱ

题目描述PIPI要考考你对回文串的掌握了~现在有一个长度为n的字符串S,PIPI对此有q个询问,每次询问S中某个连续区间(从1开始)中回文子串的数目。输入多组数据。第一行为两个个整数n,q(1<=n<=1000,1<=q<=100000)第二行为一个长为n的字符串S。接下来q行,每行两个整数l,r,表示询问S中区间[l,r]中回文子串的数目。保证l<=r...

2020-04-07 14:33:46 509

原创 1090: 最少回文串分割

题目描述PIPI听说同学们最近学习了回文串算法,现在它想考考你~PIPI给你一个只含小写字母的字符串,请你将这个字符串拆分成几段,要求每段都是回文串,同时要求段数尽可能少。racecar本身为回文串,故答案为1fastcar只能拆成’f’,‘a’,‘s’,‘t’,‘c’,‘a’,‘t’,答案为7aaabcac可以拆成’aaa’,‘b’,‘cac’,答案为3输入多组输入第一行为一个字...

2020-04-07 12:49:47 384

原创 1070: PIPI的数组

题目描述PIPI现在有一个全部为正整数组成的数组,他想知道元素 v 第 k次出现在数组中的位置,胖虎能帮帮PIPI吗?PIPI是个好奇心很重的人,他会有m次询问哦~输入输入包含多组测试样例。对于每一组测试样例,第一行包含两个正整数 n,m .代表数组的长度和询问的次数。 (1<=n,m<=105)第二行包括n个正整数,每个正整数 v < 106。接下来包含m组询问,...

2020-04-06 21:20:18 181

原创 1041: 最大子矩阵

题目描述给你一个m×n的整数矩阵,在上面找一个x×y的子矩阵,使子矩阵中所有元素的和最大。输入输入数据的第一行为一个正整数T,表示有T组测试数据。每一组测试数据的第一行为四个正整数m,n,x,y(0<m,n<1000 AND 0<x<=m AND 0<y<=n),表示给定的矩形有m行n列。接下来这个矩阵,有m行,每行有n个不大于1000的正整数。输出对...

2020-04-06 15:55:57 581

原创 785. Is Graph Bipartite?

Is Graph Bipartite?MediumGiven an undirected graph, return true if and only if it is bipartite.Recall that a graph is bipartite if we can split it’s set of nodes into two independent subsets A an...

2020-04-05 22:12:29 129

原创 332. Reconstruct Itinerary,涉及multiset的运用

Reconstruct ItineraryMediumGiven a list of airline tickets represented by pairs of departure and arrival airports [from, to], reconstruct the itinerary in order. All of the tickets belong to a man...

2020-04-05 17:43:48 80

原创 210. Course Schedule II

Course Schedule IIMediumThere are a total of n courses you have to take, labeled from 0 to n-1.Some courses may have prerequisites, for example to take course 0 you have to first take course 1, w...

2020-04-05 12:46:45 93

原创 207. Course Schedule

Course ScheduleMediumThere are a total of numCourses courses you have to take, labeled from 0 to numCourses-1.Some courses may have prerequisites, for example to take course 0 you have to first t...

2020-04-05 12:36:19 121

原创 8. String to Integer (atoi)

String to Integer (atoi)MediumImplement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character ...

2020-04-05 12:19:12 67

原创 377. Combination Sum IV

Combination Sum IVMediumGiven an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:nums = [1, 2...

2020-04-03 12:56:25 97

原创 120. Triangle(动态规划两种解法,空间优化)

TriangleMediumGiven 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],[...

2020-04-01 13:17:15 198

原创 63. Unique Paths II

Unique Paths IIMediumA 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 i...

2020-03-31 23:09:06 88

原创 984. String Without AAA or BBB

String Without AAA or BBBMediumGiven two integers A and B, return any string S such that:S has length A + B and contains exactly A ‘a’ letters, and exactly B ‘b’ letters;The substring ‘aaa’ does...

2020-03-29 17:21:24 82

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除