自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 PAT - 1144 The Missing Number(20 分) || LeetCode 41. First Missing Positive

这道题同时在PAT和LeetCode中出现哈不过PAT并没有要求用 O(1)空间复杂,可是LeetCode要求用 O(1),时间复杂度都适用O(N);1144 The Missing Number(20 分)Given N integers, you are supposed to find the smallest positive integer that is NOT in the give...

2018-06-14 13:19:29 192

原创 PAT - 1145 Hashing - Average Search Time(25 分)

The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer keys from the table and output the average sea...

2018-06-14 11:37:03 276

原创 PAT—1146 Topological Order (25)

This is a problem given in the Graduate Entrance Exam in 2018: Which of the following is NOT a topological order obtained from the given directed graph? Now you are supposed to write a program to test...

2018-06-13 16:03:48 200

原创 PAT —1147 Heaps (30)

因为对自己不太自信,所以才报了甲级-  -然后从后往前刷题,30分钟做完第一道之后,我觉得我应该报顶级的,不过无所谓了,先考着甲级吧。In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, ...

2018-06-13 14:56:12 237

原创 LeetCode 51 | 52. N-Queens (回溯)

经典回溯问题~~~The n-queens puzzle is the problem of placing n queens on an n×n chessboard such that no two queens attack each other.Given an integer n, return all distinct solutions to the n-queens puzzle....

2018-06-12 16:58:30 119

原创 LeetCode 36 | 37 | 39 | 40 | 46 | 47 . (回溯)

这道题是让你判断现有的数字是不是合法的,也就是说只需要去判断数字,不用去判断空的部分。(其实是数独解法的判断部分)36题的解析:9个数组来记录每行的重复情况,用数组下标来表示该数,比如 row[ 2 ] [ 3 ],表示第二行数字3的情况,如果 row[2][3] = 0,说明第三行已记录的没有3; 如果row[2][3] = 1,说明第二行已记录的已经有3,表示重复,直接return false...

2018-06-11 14:12:54 156

原创 LeetCode 34. Search for a Range (二分查找)

所有不会做这道题的人应该好好的去研究下STL源码的lower_bound和upper_bound,两个都是用二分查找法实现的。只要仿照着写就好了。http://www.cplusplus.com/reference/algorithm/lower_bound/http://www.cplusplus.com/reference/algorithm/upper_bound/lower_bound:t...

2018-06-09 21:14:39 139

原创 LeetCode 33. Search in Rotated Sorted Array (二分查找)

Suppose an array sorted in ascending order is rotated at some pivot unknown to you beforehand.(i.e., [0,1,2,4,5,6,7] might become [4,5,6,7,0,1,2]).You are given a target value to search. If found in t...

2018-06-09 19:50:36 115

原创 LeetCode18. 4 Sum (双指针)

无论是4 sum还是 3sum都是一样的问题,本质上都是双指针的问题:3 sum是固定一个数,剩下来的双指针; 4sum是固定两个两个数,剩下来的双指针;关于预处理排序我之前见过另外一道题,是3个长度为N的序列,从三个序列中分别选一个数,使其相加为0。可以保证 N^2的复杂度。也是对其中两个先排序,然后可以算出一张表格,呈从上到下,从左到右的增加。那么查找的时候至多 2 * N步。 哎,这种题目就...

2018-06-08 10:34:10 111

原创 Leetcode 31. Next Permutation

https://www.cnblogs.com/eudiwffe/p/6260699.html我觉得它写的挺好的,STL里面确实有permutation的,而且我觉得写的真的很好permutations后面还有一道题,求全排序的,呜完全可以用STL里的方法来做。Implement next permutation, which rearranges numbers into the lexicog...

2018-06-06 21:07:20 97

翻译 LeetCode 19. Remove Nth Node From End of List (我觉得别人的代码比我更好)

Given a linked list, remove the n-th node from the end of list and return its headExample:Given linked list : 1->2->3->4->5, and n = 2;After removing the second node from the end, the link...

2018-06-06 20:20:31 156

原创 OS - Cache synchronization

Let’s say you’re building a local cache for Netflix videos at your favorite ISP. Here are some requirements for your cache:Your goal is to deliver videos to customers as fast as possible, but use as l...

2018-06-05 18:54:09 191

原创 LeetCode26/27/28 三道easy Remove Duplicates from Sorted Array / Remove Element / Implement strStr( )

26. Remove Duplicates from Sorted Array (就是STL里面的move)Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.Do not allocate extra ...

2018-06-01 16:22:54 130

原创 LeetCode 23. Merge k Sorted Lists (单链表 + 递归)

这道题我是用递归做的,注定了只打败了一半的人-  -  讲真,这道题和MergeSort根本没有任何差别啊不过我的是尾递归,尾递归总是可以改成while循环的。改了的话应该会快很多吧。Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity.Example:In...

2018-06-01 15:26:12 172

原创 LeetCode 24. Swap Nodes in Pairs(单链表)

这道题只打败了39%的人,呜呜呜,大家都是 O(N) 线性时间,怎么别人就那么优秀呢-  -单链表操作,除了有点烦没其他的。Given a linked list, swap every two adjacent nodes and return its head.Example:Given 1->2->3->4, you should return the list as 2-...

2018-05-31 12:07:34 136

原创 LeetCode 49. Group Anagrams (哈希表)

这道题肯定是哈希表了,我一开始很傻的自己写了个哈希函数,还是一看就知道是会有重合的那种哈希函数算了 还是用自带的unordered map吧 = =  进行哈希判断重复之前先排个序,原来string还有string.begin( )这个东西,毕竟string也是可以迭代的XDDGiven an array of strings, group anagrams together.Example:In...

2018-05-31 10:58:45 156

原创 LeetCode 22. Generate Parentheses (Catalan数字 + 递归)

这题看的第一眼,这不就是Catalan Number么 - - 这不就是递归么。这是我之前学Catalan Number的教材的部分摘录,看完就知道怎么写啦。Catalan numbers:Set P of balanced parentheses strings are recursively defined as• λ ∈ P (λ is empty string)• Ifα,β ∈ P,th...

2018-05-29 14:17:25 237

原创 LeetCode 21. Merge Two Sorted Lists (简单链表)

Merge two sorted linked lists and return it as a new list. The new list should be made by splicing together the nodes of the first two lists.Example:Input: 1->2->4, 1->3->4Output: 1->1...

2018-05-29 13:13:18 89

原创 LeetCode 20. Valid Parentheses (栈)

这道题比较简单,用一个栈就好了,比什么前缀后缀表达式要简单的多啊有木有 - -Given a string containing just the characters '(', ')', '{', '}', '[' and ']', determine if the input string is valid.An input string is valid if:Open brackets m...

2018-05-28 12:32:59 152

翻译 LeetCode 17. Letter Combinations of a Phone Number (迭代)

迭代和递归一直都是我的弱项(说的好像我有强项一样- - )  不过迭代和递归感觉很多用在无法确定输出长度的时候。就当作给自己记下来好了Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mappin...

2018-05-28 11:48:20 203

原创 LeetCode 16. 3Sum Closest (预处理排序)

Given an array nums of n integers and an integer target, find three integers in nums such that the sum is closest to target. Return the sum of the three integers. You may assume that each input would ...

2018-05-27 20:28:44 124

原创 LeetCode 15. 3Sum (预处理排序)

这道题我也觉得很棒,自己还是用的暴力的方法去做,然后就超时了啦,呜呜呜。。。然后感叹一下讨论区的大佬真聪明。Given an array nums of n integers, are there elements a, b, c in nums such that a + b + c = 0? Find all unique triplets in the array which gives t...

2018-05-24 20:00:53 148

原创 LeetCode 14. Longest Common Prefix

这道题我做的不太好,虽然AC了,但是因为要急着去吃饭,所以就不优化了- - Write a function to find the longest common prefix string amongst an array of strings.If there is no common prefix, return an empty string "".Example 1:Input: ["f...

2018-05-24 17:08:37 83

原创 LeetCode 11. Container With Most Water

前面两道Hard类型的题目 等我彻彻底底弄明白了再仔仔细细写一篇先。这道Medium的题我觉得超级棒的说。出题的人太有水平了,比直方图面积的单调栈要简单,暴力解法会超时,但是O(N)的解法是又精巧又直观,我自己就没想出来,看了提示才知道的。Given n non-negative integers a1, a2, ..., an, where each represents a point at ...

2018-05-24 16:46:33 146

原创 LeetCode 9. Palindrome Number

这道题比上一题还无聊 - -最后还说不要让我用整数转字符串,那么就reverse好了,如果reverse后相等,就返回true,10分钟的题;Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.Example 1:Inp...

2018-05-24 11:53:41 103

原创 LeetCode 8. String to Integer (atoi)

Implement atoi which converts a string to an integer.The function first discards as many whitespace characters as necessary until the first non-whitespace character is found. Then, starting from this ...

2018-05-24 11:40:58 105

原创 LeetCode 7. Reverse Integer ( 简单题,注意INT_MAX 和INT_MIN就可以 )

这道题也是信心题~~Given a 32-bit signed integer, reverse digits of an integer.Example 1:Input: 123Output: 321Example 2:Input: -123Output: -321Example 3:Input: 120Output: 21Note:Assume we are dealing with a...

2018-05-21 12:25:51 552

原创 LeetCode 6. ZigZag Conversion (就找规律啊 - - )

The 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 font for better legibility)P A H NA P L S I I G...

2018-05-21 11:52:41 98

原创 Leetcode 5. Longest Palindromic Substring (straight forward DP)

为什么直接到第五题呢- -  因为第四题好难,我得消化一下Given a string s, find the longest palindromic substring in s. You may assume that the maximum length of s is 1000.Example 1:Input: "babad"Output: "bab"Note: "aba" is al...

2018-05-20 19:56:32 159

原创 数据结构基础 - 散列3 QQ帐户的申请与登陆

实现QQ新帐户申请和老帐户登陆的简化版功能。最大挑战是:据说现在的QQ号码已经有10位数了。输入格式:输入首先给出一个正整数N(≤10​5​​),随后给出N行指令。每行指令的格式为:“命令符(空格)QQ号码(空格)密码”。其中命令符为“N”(代表New)时表示要新申请一个QQ号,后面是新帐户的号码和密码;命令符为“L”(代表Login)时表示是老帐户登陆,后面是登陆信息。QQ号码为一个不超过10位...

2018-05-19 13:09:19 315

原创 Leetcode 3. Longest Substring Without Repeating Characters (滑动窗口解法)

话说我有一个小习惯,我会去看一下 Debugu code in playground, 我觉得它的题目的输入输出的代码都写的特别的棒。Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc",...

2018-05-17 16:09:04 261

原创 Leetcode 2. Add Two Numbers

You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and return i...

2018-05-17 14:03:18 93

原创 LeetCode 1. Two Sum

Given an array of integers, return indices of the two numbers such that they add up to a specific target.You may assume that each input would have exactly one solution, and you may not use the same el...

2018-05-17 11:10:10 88

原创 HomeWork ( 一) P46:Interlude: Process API

总的来说这一页的习题就是让你看懂,我们有哪些API!以及这些API最基本的调用方法和特性。Homework (Code)In this homework, you are to gain some familiarity with the process management APIs about which you just read. Don’t worry – it’s even more ...

2018-05-16 20:05:37 785

原创 排序碎碎念(五):数据结构基础— Sort with Swap(0, i)

这是这道题目是一个表排序的问题,也就是(cycle sort)可以去Google搜索一下,有更多的资料。可以参考一下其他的资料,比如:https://en.wikipedia.org/wiki/Cycle_sort https://www.geeksforgeeks.org/an-in-place-algorithm-for-string-transformation/你也可以看一下讲解 点击打开...

2018-05-14 17:16:28 126

原创 排序碎碎念(四):数据结构基础— PAT Judge

这道题我一开始是用C写的,但是自己写的用堆排序出了一点问题,我就换成了C++的sort函数,等我有空了,再去实现个完整的C语言版本吧。 - -这道题我的思路是1)结构体中不仅仅包含score[k],还要包含status[k],因为每一个题目都有四种状态,这四种状态有利于判断和输出。#define NotSubmitted -1#define CompileError 0#define Submit...

2018-05-14 11:14:51 173

原创 排序碎碎念(三):数据结构基础— 统计工龄 QuickSort

其实呢,1)Quicksort也有十分简便的写法的,比如pivot就挑第一个好啦,比如对所有的直接递归,不用考虑一定的间隔用插入排序什么的,但是要知道的是在C++的内置sort函数中确实就像老师说的那样,是判断子集的长度,小于某个值就使用插入排序,这个版本的快排是比简单粗暴版的快排要好很多的。2)输出统计的那个函数不要写错这道题就基本过了。 当然你用heapsort也可以过这道题。10-排序4 统...

2018-05-12 19:53:54 180

原创 排序碎碎念(二):数据结构基础— Insert or Heap

这道题和上一题差不多,稍微修改一点就好了。09-排序3 Insertion or Heap Sort(25 分)According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, i...

2018-05-12 13:09:20 127

原创 排序碎碎念(一):数据结构基础— Insert or Merge

09-排序2 Insert or Merge(25 分)According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort removes one el...

2018-05-11 17:01:19 209

原创 C++ 重载 [ ] , C++ 模版类的一些事项

MOOC上 很难蒙混过关的CArray3d三维数组模板类:这道题目大概是希望自己能写一个实现下面这个功能的类;CArray3D<int> a(3,4,5)a[i][j][k] = 100;然后先看一下一些参考资料:来源:http://en.cppreference.com/w/cpp/language/operatorsUser-defined classes that provid...

2018-05-10 13:10:29 525

空空如也

空空如也

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

TA关注的人

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