- 博客(43)
- 资源 (11)
- 收藏
- 关注
原创 645. Set Mismatch
class Solution {public: vector findErrorNums(vector& nums) { int a=nums.size(); vector res; for(int i=0;i<a;i++) { for(in
2017-12-31 09:09:59 139
原创 342. Power of Four
Given an integer (signed 32 bits), write a function to check whether it is a power of 4.Example:Given num = 16, return true. Given num = 5, return false.Follow up: Could you solve it without
2017-12-30 23:05:52 136
转载 [LeetCode] Plus One 加一运算
[LeetCode] Plus One 加一运算Given a non-negative number represented as an array of digits, plus one to the number.The digits are stored such that the most significant digit is at the head of
2017-12-29 16:21:48 416
转载 Climbing Stairs 爬梯子问题
You are climbing a stair case. It takes n steps to reach to the top.Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? 这个爬梯子问题最开始看的时候没搞懂是让干啥的,
2017-12-29 15:57:32 494
原创 405. Convert a Number to Hexadecimal
不知道数字怎么转化成字符串。难过class Solution {public: string toHex(int num) { if(num<10) return to_string(num); if(10<=10<16) return to_string(97+num-10); else if (num>16) return
2017-12-29 15:22:41 149
转载 458. Poor Pigs
There are 1000 buckets, one and only one of them contains poison, the rest are filled with water. They all look the same. If a pig drinks that poison it will die within 15 minutes. What is the minimum
2017-12-28 12:25:18 148
原创 326. Power of Three
递归一次成功:class Solution {public: bool isPowerOfThree(int n) { if (n==3||n==1) return true; if(n<1||n%3!=0) return 0; else return isPowerOfThree(n/3); }};以为
2017-12-28 10:54:53 173
原创 Power of Two 判断2的次方数
立马想到递归,思路正确:class Solution {public: bool isPowerOfTwo(int n) { if (n==2) return true; if(n%2!=0) return false; if (n>2) return isPowerOfTwo(n/2); }};忘了考虑n为0、1和负数的
2017-12-27 23:00:57 425
原创 720. Longest Word in Dictionary
只会求最长的单词,求最小的没思路:class Solution {public: string longestWord(vector& words) { int a=words.size(); int t=0; int max= words[0].size(); for (int i=0;i<a;
2017-12-27 22:41:56 201
转载 504. Base 7
class Solution {public: string convertToBase7(int num) { if(num==0) return "0"; string res=""; bool positive=num>0; while(num!=0){ res=num2string(num%7
2017-12-27 21:44:11 124
转载 Reverse String II 翻转字符串之二
Given a string and an integer k, you need to reverse the first k characters for every 2k characters counting from the start of the string. If there are less than k characters left, reverse all of them
2017-12-27 21:08:23 174
原创 674. Longest Continuous Increasing Subsequence
看了别人int max 后面的比我第三次写的还简洁,没有 if else if 这么乱。就再思考: for(int i=1;iclass Solution {public: int findLengthOfLCIS(vector& nums) { int a=nums.size(); int cnt=1; if (a==0) ret
2017-12-26 17:35:35 133
原创 674. Longest Continuous Increasing Subsequence
看了别人的一句 int max=1(不断更新max。。 思路!!!!)后 写了个简单的,不需要vector保存结果。class Solution {public: int findLengthOfLCIS(vector& nums) { int a=nums.size(); int cnt=1; if (a==0) return 0;
2017-12-26 17:34:36 137
转载 C++中的istringstream 的用法
今天看到了一个比较有用的c++的输入输出控制类。C++引入了ostringstream、istringstream、stringstream这三个类,要使用他们创建对象就必须包含这个头文件。istringstream类用于执行C++风格的串流的输入操作。ostringstream类用于执行C风格的串流的输出操作。strstream类同时可以支持C风格的串流的输入输出操作。istri
2017-12-26 16:55:19 528
转载 Delete Node in a Linked List 删除链表的节点
Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Supposed the linked list is 1 -> 2 -> 3 -> 4 and you are given the third node with value
2017-12-26 16:41:33 215
原创 674. Longest Continuous Increasing Subsequence
自己写了个,res容器计算所有递增的数,找出最大的数列。有点繁琐。[cpp] view plain copyclass Solution { public: int findLengthOfLCIS(vectorint>& nums) { int a=nums.size(); int cnt=1; vectorint> res;
2017-12-26 16:40:08 137
原创 Student Attendance Record I 学生出勤记录之一
自己做:class Solution {public: bool checkRecord(string s) { int start=0,n=s.size(); int cnt1=0,cnt2=0; if (s[0]=='A'&&s[1]=='A') return false; for(int i=start;i<n-2;i+
2017-12-25 15:15:13 229
原创 Missing Number 丢失的数字
class Solution {public: int missingNumber(vector& nums) { sort(nums.begin(),nums.end()); int a=nums.size(); int res=0; for(int i=0;i<a;i++){
2017-12-25 14:40:42 448
原创 leetcode-628-Maximum Product of Three Numbers]
class Solution {public: int maximumProduct(vector& nums) { sort(nums.begin(),nums.end()); int a=nums.size(); return nums[a-3]*nums[a-2]*nums[a-1]; }};
2017-12-25 11:33:21 187
转载 Intersection of Two Arrays II 两个数组相交之二
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2, 2].Note:Each element in the result should appear as many tim
2017-12-24 23:05:56 268
转载 Roman to Integer 罗马数字转化成整数
Given a roman numeral, convert it to an integer.Input is guaranteed to be within the range from 1 to 3999. 罗马数转化成数字问题,我们需要对于罗马数字很熟悉才能完成转换。以下截自百度百科:罗马数字是最早的数字表示方式,比阿拉伯数字早2000多年,起源于罗马。
2017-12-23 21:42:13 187
转载 Valid Anagram
Valid AnagramGiven two strings s and t, write a function to determine if t is an anagram of s.For example,s = "anagram", t = "nagaram", return true.s = "rat", t = "car", return false.N
2017-12-23 21:29:11 110
转载 Two Sum II - Input array is sorted 两数之和之二 - 输入数组有序
Given an array of integers that is already sorted in ascending order, find two numbers such that they add up to a specific target number.The function twoSum should return indices of the two numbers
2017-12-22 18:29:46 186
原创 455. Assign Cookies
class Solution {public: int findContentChildren(vector& g, vector& s) { sort(g.begin(), g.end()); sort(s.begin(), s.end()); int res=0,k=0; int a=g.size(),b=s
2017-12-22 11:27:03 124
原创 561. Array Partition I
开始思路正确;按顺序排列,每隔一个数相加。class Solution {public: int arrayPairSum(vector& nums) { int res = 0; sort(nums.begin(), nums.end()); int a=sizeof(nums); for(int i=
2017-12-21 18:55:22 120
原创 520. Detect Capital
Given a word, you need to judge whether the usage of capitals in it is right or not.We define the usage of capitals in a word to be right when one of the following cases holds:All letters in t
2017-12-20 20:41:15 131
原创 野指针
#include#includeusing namespace std;int main(){//char ch = 'a';//char * ptr = &ch;//char * str="即可让尽快";//cout //cout //double num =1024.5;//double num = 1024.5;double *
2017-12-19 22:15:04 141 1
原创 指针地址输出
#include#includeusing namespace std;int main(){char ch = 'a';char * ptr = &ch;char * str="即可让尽快";cout cout //double num =1024.5;//double* ptr = #//cout //cout ret
2017-12-19 21:59:29 1022
原创 c++填充输出
#include#includeusing namespace std;int main(){double attack = 21;cout cout cout return 0;}
2017-12-19 17:27:02 1274
转载 Intersection of Two Arrays
Given two arrays, write a function to compute their intersection.Example:Given nums1 = [1, 2, 2, 1], nums2 = [2, 2], return [2].Note:Each element in the result must be unique.The result
2017-12-19 15:15:41 133
转载 Max Consecutive Ones
Given a binary array, find the maximum number of consecutive 1s in this array.Example 1:Input: [1,1,0,1,1,1]Output: 3Explanation: The first two digits or the last three digits are consecutiv
2017-12-17 15:51:30 171
原创 292. Nim Game
题目:You are playing the following Nim Game with your friend: There is a heap of stones on the table, each time one of you take turns to remove 1 to 3 stones. The one who removes the last stone
2017-12-17 15:02:02 138
转载 Self Dividing Numbers
Given a binary search tree and the lowest and highest boundaries as L and R, trim the tree so that all its elements lies in [L, R] (R >= L). You might need to change the root of the tree, so the res
2017-12-16 13:56:45 132
原创 Reshape the Matrix 重塑矩阵
In MATLAB, there is a very useful function called 'reshape', which can reshape a matrix into a new one with different size but keep its original data.You're given a matrix represented by a two-dim
2017-12-16 11:15:52 324
转载 Reverse Words in a String III 翻转字符串中的单词之三
Given a string, you need to reverse the order of characters in each word within a sentence while still preserving whitespace and initial word order.Example 1:Input: "Let's take LeetCode contest"
2017-12-16 10:18:18 229
原创 728. Self Dividing Numbers
class Solution {public: vector selfDividingNumbers(int left, int right) { vector re; for(int i=left; i<=right;i++){ int temp=i; while(temp !=0 && tem
2017-12-15 21:57:11 165
原创 657. Judge Route Circle
class Solution {public: bool judgeCircle(string moves) { int x = 0, y = 0; for (int i = 0; i < moves.length(); i++) { if (moves.[i]=="R")
2017-12-15 20:29:03 120
原创 454. 4Sum II
自己做:class Solution {public: int fourSumCount(vector& A, vector& B, vector& C, vector& D) { int a=A.size(); int t=0; for (int i=0;i<a;i++){ for(int j
2017-12-14 17:10:49 215
原创 521. Longest Uncommon Subsequence I
class Solution {public: int findLUSlength(string a, string b) { if (a==b) return -1; else return max(a.size(),b.size()); }};时间beat 1.92%,别人的答案:
2017-12-14 15:56:05 144
第3章 视频对象分割.ppt
2020-02-19
第2章 运动估计.ppt
2020-02-19
Improving neural networks by preventing co-adaptation of feature detectors
2017-05-03
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人