自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 496. Next Greater Element I

You are given two arrays (without duplicates) nums1 andnums2 where nums1’s elements are subset of nums2. Find all the next greater numbers fornums1's elements in the corresponding places of nums2.

2018-01-23 13:54:22 218

原创 728. Self Dividing Numbers

A self-dividing number is a number that is divisible by every digit it contains.For example, 128 is a self-dividing number because 128 % 1 == 0, 128 % 2 == 0, and 128 % 8 == 0.Also, a self-divid

2018-01-20 12:14:10 249

原创 739. Daily Temperatures

Given a list of daily temperatures, produce a list that, for each day in the input, tells you how many days you would have to wait until a warmer temperature. If there is no future day for which this

2018-01-18 14:18:06 226

原创 744. Find Smallest Letter Greater Than Target

Given a list of sorted characters letters containing only lowercase letters, and given a target lettertarget, find the smallest element in the list that is larger than the given target.Letters als

2018-01-18 10:55:41 232

原创 763. Partition Labels

A string S of lowercase letters is given. We want to partition this string into as many parts as possible so that each letter appears in at most one part, and return a list of integers representing th

2018-01-17 12:55:58 269

原创 760. Find Anagram Mappings

Given two lists Aand B, and B is an anagram ofA. B is an anagram of A means B is made by randomizing the order of the elements inA.We want to find an index mapping P, from A toB. A mapping P[i

2018-01-16 12:57:27 301

原创 矩阵构造

下面四张图片分别是3*3、4*4、5*5和7*7的矩阵,请总结并找出他们的规律。 编写程序让用户输入一个整数n(1-25之间),输出满足上述规律的n*n矩阵,要求每个整数占4列,右对齐。 void fun(int** res,int n,int pos,int num,int ans)  {      int i,j;      int number=n

2017-09-08 11:36:55 526

原创 计算天数

struct date  {      int year;      int month;      int day;  };  int checkyear(int y)  {      if(y%4==0 && y%100!=0 || y%400==0) //是闰年          return 1;      else          r

2017-09-07 17:01:31 551

原创 链表习题4

(1)          将统一提供的contacts.dat文件复制到计算机D盘根目录中,该文件以二进制形式存放了数量未知个通讯录数据,每条通讯录数据的结构定义如下:struct Contactor{         charname[20];                  //姓名,在数据文件中不存在重复的姓名         int age;               

2017-09-07 15:13:09 309

原创 671. Second Minimum Node In a Binary Tree

Given a non-empty special binary tree consisting of nodes with the non-negative value, where each node in this tree has exactlytwo or zero sub-node. If the node has two sub-nodes, then this node's v

2017-09-06 17:39:45 247

原创 669. Trim a Binary Search Tree

Given a binary search tree and the lowest and highest boundaries as L andR, 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 resu

2017-09-05 13:53:20 211

原创 670. Maximum Swap

Given a non-negative integer, you could swap two digits at most once to get the maximum valued number. Return the maximum valued number you could get.Example 1:Input: 2736Output: 7236Explanati

2017-09-05 11:32:28 374

原创 79. Word Search

Given a 2D board and a word, find if the word exists in the grid.The word can be constructed from letters of sequentially adjacent cell, where "adjacent" cells are those horizontally or vertically n

2017-09-04 17:25:25 211

原创 链表习题3

1.        编写一个函数,读取二进制文件中的所有整数,并构建一个整数链表。2.        编写一个函数,在屏幕上显示第1步中生成的整数链表的所有整数,要求每行输出6个,每个占9列,右对齐。3.        编写一个函数,对第1步生成链表中的每个结点内的整数作逆序处理。在main函数中输出结点数据逆序处理后的整数链表,输出格式与第2步相同。4.        编写一个函

2017-09-04 16:29:19 344

原创 链表习题2

本作业的数据文件为per.dat,该文件是一个二进制文件,利用如下结构体存储了十个人的信息。struct person{    charname[20];//姓名    int age;    //年龄    int  height; //身高    int  weight; //体重};请编写程序,实现如下功能1)将是个人的信息读取出,并显示在屏幕上,每人

2017-09-04 11:16:49 356

原创 链表习题

在这两个数据文件中,1.dat文件中的用餐记录数据已经按照用餐金额进行了增序排列。请按要求完成如下操作: 1.        编写一个函数,读取1.dat文件中的所有用餐记录数据,并构建一个用餐记录链表。2.     编写一个函数,在屏幕上显示第1步中生成的用餐记录链表中的所有数据,要求每行输出1条记录,显示内容和格式要求如下:学生学号占25列,左对齐

2017-09-03 23:10:43 459

原创 406. Queue Reconstruction by Height

Suppose you have a random list of people standing in a queue. Each person is described by a pair of integers(h, k), where h is the height of the person and k is the number of people in front of this

2017-09-03 11:05:29 222

原创 611. Valid Triangle Number

Given an array consists of non-negative integers, your task is to count the number of triplets chosen from the array that can make triangles if we take them as side lengths of a triangle.Example 1:

2017-09-02 22:03:45 279

原创 628. Maximum Product of Three Numbers

Given an integer array, find three numbers whose product is maximum and output the maximum product.Example 1:Input: [1,2,3]Output: 6Example 2:Input: [1,2,3,4]Output: 24Note:The

2017-09-02 16:24:26 244

原创 645. Set Mismatch

The set S originally contains numbers from 1 to n. But unfortunately, due to the data error, one of the numbers in the set got duplicated toanother number in the set, which results in repetition of

2017-09-02 14:19:53 241

原创 653. Two Sum IV - Input is a BST

Given a Binary Search Tree and a target number, return true if there exist two elements in the BST such that their sum is equal to the given target.Example 1:Input: 5 / \ 3 6 / \

2017-09-01 23:40:25 200

原创 547. Friend Circles

There are N students in a class. Some of them are friends, while some are not. Their friendship is transitive in nature. For example, if A is adirect friend of B, and B is a direct friend of C, then

2017-09-01 18:00:48 231

原创 657. Judge Route Circle

Initially, there is a Robot at position (0, 0). Given a sequence of its moves, judge if this robot makes a circle, which means it moves back tothe original place. The move sequence is represented

2017-09-01 15:47:59 206

原创 打牌

题目要求:题目描述:    牌只有1到9,手里拿着已经排好序的牌a,对方出牌b,用程序判断手中牌是否能够压过对方出牌。     规则:出牌牌型有5种       [1]一张 如4 则5...9可压过     [2]两张 如44 则55,66,77,...,99可压过     [3]三张 如444 规则如[2]     [4]四张 如4444 规则如[2]     [

2017-08-17 16:06:33 491

原创 找出第K小的数

题目描述:            查找一个数组的第K小的数,注意同样大小算一样大。       如  2 1 3 4 5 2 第三小数为3。      输入:      输入有多组数据。      每组输入n,然后输入n个整数(1    输出:      输出第k小的整数。      样例输入:      6      2 1 3 5 2 2 

2017-08-16 17:53:26 1135

原创 捡石子

题目描述在一个圆形操场的四周摆放着 n堆石子。 现要将石子有次序地合并成一堆。 规定每次选2 堆石子合并成新的一堆,合并的费用为新的一堆石子数。试设计一个算法,计算出将 n堆石子合并成一堆的最小总费用。输入输入数据第1行有1个正整数 n(1≤n≤1000),表示有 n堆石子,每次选2堆石子合并。第2行有 n个整数, 分别表示每堆石子的个数(每堆石子的取值范围为[1,1000]) 。

2017-08-16 16:54:51 460

原创 201. Bitwise AND of Numbers Range

Given a range [m, n] where 0 For example, given the range [5, 7], you should return 4.5:101     6:110       7:111    4:100从最高位开始相同的bitsint rangeBitwiseAnd(int m, int n) {    //取第i位上的bi

2017-08-16 14:43:49 186

原创 169. Majority Element

题目:Given an array of size n, find the majority element. The majority element is the element that appearsmore than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority elem

2017-08-15 10:27:53 211

原创 129. Sum Root to Leaf Numbers

Given a binary tree containing digits from 0-9 only, each root-to-leaf path could represent a number.An example is the root-to-leaf path 1->2->3 which represents the number123.Find the total sum

2017-08-14 17:03:04 198

原创 c语言 词频统计

c语言没有向量可以存储单词信息,需要自己定义数据结构,此处方便用了结构体数组,因为无法确定单词数量,所以申请的空间很大,也可以用链表做,但是链表查找较为繁琐,时间上较慢。#include#include#include#include//词频统计//存储单词用结构体typedef struct node{ char word[26];//一个单词 int count;//出

2017-08-14 11:30:49 8908 2

原创 53. Maximum Subarray

Related Topics:Dynamic Programming一开始想复杂了,想用二维数组存下标i到下标j的最大sum,其实用两个变量即可解决。sum存每一次向后移一位后的最大和,res是存此次最大和与之前的最大和相比较所得的最大和class Solution {public:    int maxSubArray(vector& nums) {        int

2017-07-26 00:21:22 198

原创 516. Longest Palindromic Subsequence

Related Topics: Dynamic Programming这道题主要在于用两个指针,找到从下标i到下标j的最长回文串class Solution {public:    int longestPalindromeSubseq(string s) {        int dp[s.size()][s.size()];        for(int i=0;i

2017-07-24 18:21:42 203

原创 213. House Robber II

Related Topics:Dynamic Programming1.抢劫了第1个房间,那么第n个房间不能抢(0~n-2)2.不抢劫第1个房间,那么第n个房间可以抢劫(1~n-1)好像最后没用到r,因为写的时候默认数组大小为nums,size()-1,应该是用r-l+1比较规范class Solution {public:    int rob(v

2017-07-23 21:34:55 216

原创 198. House Robber

Related Topics:Dynamic Programming比较基础的动态规划题,思路就是找到动态方程 dp[i]=max(dp[i-2]+nums[i-1],dp[i-1]);dp[i]没有考虑num[i]是否该偷,只是存偷到i-1个房子的最大值,可以是dp[i-1](偷),dp[i-2]+nums[i-1](不偷)class Solution {public: 

2017-07-23 21:09:51 194

原创 347. Top K Frequent Elements

Related Topics:Hash Table,Heap哈希表部分较为容易,关键就是对哈希表值的排序,题目设定为nlogn,则较容易想到堆排序,还不太了解,先这么copy着。class Solution {public:    vector topKFrequent(vector& nums, int k) {        vector res;        u

2017-07-22 18:28:55 180

原创 219. Contains Duplicate II

Related Topic: Hash Table,Array思路:value存相同数的下标,对下标们排序,相邻下标相减看是否不超过kclass Solution {public:    bool containsNearbyDuplicate(vector& nums, int k) {        unordered_map> hashmap;        fo

2017-07-22 17:25:16 197

原创 217. Contains Duplicate

Related Topics:Hash Table,Array如果数组里的数字全部不重复则返回false,如果有一个数重复2次以上则返回true,哈希表key存数字,value存出现次数class Solution {public:    bool containsDuplicate(vector& nums) {        unordered_map hashma

2017-07-22 16:53:02 179

原创 49. Group Anagrams

Related Topics:Hash Table,String思路:肯定是需要哈希表来存键值对了,重要的是key值的选取,涉及到哈希表的创建,遍历等操作,很基础,对哈希表的运用有了基本的了解。class Solution {public:    vector> groupAnagrams(vector& strs) {        vector> res;

2017-07-22 16:23:18 155

原创 202. Happy Number

Related Topics:Hash Table,Math首先最先想到的思路是将n的每一位数平方后加起来,将新值更新到n中,一旦n=1则为幸福数字,但会出现n一直不等于1的情况,此时就要判断在什么情况下n永远不会等于1,可以对每一次n拆分得到的一位数字做标记,当所有的数字使用次数大于n的位数时即可以判断,n永远不会等于1好像没有用到哈希表来做,希望以后能有所改进。class So

2017-07-22 14:07:08 181

原创 476. Number Complement

Related Topics:Bit Manipulation思路:获得num的每一位取非后赋给新的数n需要注意的是如何置n的每一位为1或者0:int n|=(1class Solution {public:    int findComplement(int num) {        int n=0,i=0;        while(num){  

2017-07-20 16:35:29 196

空空如也

空空如也

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

TA关注的人

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