自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

晨识草的博客

竹密不妨流水过,山高不碍白云飞

  • 博客(218)
  • 收藏
  • 关注

原创 14-Longest Common Prefix

类别:string题目描述Write a function to find the longest common prefix string amongst an array of strings.算法分析两层for循环判断两两之间的相同前缀,然后取长度最小的相同前缀即为最小共同前缀。代码实现class Solution {public: string commonBetwTwo(stri

2017-12-14 00:12:20 200

原创 26-Remove Duplicates from Sorted Array

难度:easy 类别:array题目描述算法分析直接使用vector的erase函数即可,注意删除掉某个相同的数字之后,因为后面的数字需要与被删除数字前面的那个数字进行比较,所以i需要保持不变,所以i–和for循环中的i++使得i保持不变。代码实现class Solution {public: int removeDuplicates(vector<int>& nums) {

2017-12-13 22:36:54 191

原创 9-palindrome Number(回文)

难度:easy题目描述https://leetcode.com/problems/palindrome-number/description/ 算法分析首先得到x的反转数字,注意判断反转得到的数字是否在32为有符号int的范围内部,如果不在范围内,返回false,如果x是负数,返回false,最后判断x和反转后的整数是否相等即可代码实现class Solution {public: bo

2017-12-13 22:19:03 151

原创 100、101、104-递归

类别:depth first search 难度:easy100-Same Tree给定两棵树的根节点,判断两棵树是否相同 只需要对空节点进行判断,然后分别递归判断左子树和右子树即可class Solution {public: bool isSameTree(TreeNode* p, TreeNode* q) { if(p == NULL && q == NULL)

2017-12-13 21:04:22 211

原创 88-Merge Sorted Array

类别:array 难度:easy题目描述Given two sorted integer arrays nums1 and nums2, merge nums2 into nums1 as one sorted array.算法分析将两个数组合并后暂存在一个新的数组当中,然后将新的数组的数值复制给nums1代码实现class Solution {public: void merge(ve

2017-12-11 14:35:42 145

原创 96-Unique Binary Search Trees

类别:dynamic programming 难度:medium题目描述算法分析 动态规划实现:(1)二叉搜索树的特点:左子树的所有节点小于根节点,右子树的所有节点大于根节点。 (2)当n = 0 || n = 1的时候,只有一种情况 (3)对于n个节点的二叉搜索树,每一个数值都可以作为根节点,总共有n中情况。(1~n分别为根节点的情况) 对于k为根节点的情况,它的左子树总共有k-1个

2017-12-11 12:28:59 130

原创 输入输出LL(1)语法分析程序

注:编译原理题目描述 代码实现对照分析表实现 // sicily 2, complier course#include <iostream>#include <vector>#include <cstring>#include <string.h>#include <iomanip>#include <stack>using namespace std;#define

2017-12-07 19:42:42 4054

原创 32-longest valid parentheses

类别:dynamic programming 难度:hard题目描述算法分析这道题目涉及到括号匹配的问题,第一想法是使用stack来实现,事实上确实可以这样做。 首先需要把字符串中的符号压栈并进行匹配判断 这里不同的时候,压入栈的不是符号而是符号所在的下标,便于后面对连续匹配符号的长度的比较。 对于最后留在栈中的下标,相邻两个下标的差减1就是连续子串的长度,对每个字串的长度进行比较得到最长字

2017-12-07 16:18:29 147

原创 1000-输入输出LL(1)语法分析程序

注:编译原理题目题目描述 代码实现#include <iostream>#include <vector>#include <cstring>#include <string.h>#include <iomanip>using namespace std;#define MAXSIZE 1000string result[MAXSIZE][MAXSIZE];string e

2017-12-07 13:17:57 559

原创 279-perfect squares

类别:dynamic programming 难度:medium题目描述Given a positive integer n, find the least number of perfect square numbers (for example, 1, 4, 9, 16, …) which sum to n.For example, given n = 12, return 3 because

2017-12-06 22:27:06 186

原创 62-Unique Paths

类别:dynamic programming 难度:medium题目描述https://leetcode.com/problems/unique-paths/description/ 算法分析单纯的只往下走或者是单纯的只往右走,都只有一种可能的走法,所以初始化的时候path[i][0] = path[0][j] = 1 对于每一个位置,走到这里的上一步可能是从上面下来或者是从左边过来,所以pa

2017-12-05 21:47:49 192

原创 198-House Robber

类别:dynamic programming 难度:easy题目描述https://leetcode.com/problems/house-robber/description/ You are a professional robber planning to rob houses along a street. Each house has a certain amount of money

2017-12-05 20:17:35 189

原创 121-Best Time to Buy and Sell Stock

类别:dynamic programmin 难度:easy题目描述https://leetcode.com/problems/best-time-to-buy-and-sell-stock/description/Say you have an array for which the ith element is the price of a given stock on day i.If you

2017-12-05 19:36:31 155

原创 70-Climbing Stairs

类别:dynamic programming 难度:easy题目描述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-04 14:06:17 161

原创 最小和(sicily算法)

1.题目要求从数列A[0], A[1], A[2], …, A[N-1]中选若干个数,要求对于每个i(0<=i2.算法分析动态规划,对于n个数的最小和,需要比较三种情况:(A[i-1], a[i] + A[i-1], a[i] + A[i - 2]),取三者中最小的一个,但是对于A[i], A[i] = min(A[i] + A[i - 1], A[i] + A[i - 2]);3.代码实现#inc

2017-12-03 20:40:36 832

原创 141-Linked List Cycle

难度:easy 类别:linked list1.题目描述Given a linked list, determine if it has a cycle in it.Follow up: Can you solve it without using extra space?2.算法分析用了一种比较取巧的方法。 如果一个单向链表中有环的话,那么不存在节点的next指针为NULL,因而可以遍历链表

2017-11-05 13:29:28 187

原创 234-Palindrome Linked List

难度:easy 类别:linked list1.题目描述Given a singly linked list, determine if it is a palindrome. 比较链表中的数值是不是回文。 Follow up: Could you do it in O(n) time and O(1) space?2.算法分析(1)计算链表的长度 (2)根据链表的长度将链表分成两个子链表

2017-11-05 00:18:10 149

原创 203-Remove Linked List Elements

难度:easy 类别:linked list1.题目描述Remove all elements from a linked list of integers that have value val.Example Given: 1 –> 2 –> 6 –> 3 –> 4 –> 5 –> 6, val = 6 Return: 1 –> 2 –> 3 –> 4 –> 52.算法分析遍历链表,比较h

2017-11-03 13:27:29 179

原创 328-Odd Even Linked List

难度:medium 类别:linked list1.题目描述Given a singly linked list, group all odd nodes together followed by the even nodes. Please note here we are talking about the node number and not the value in the nodes.

2017-11-03 13:09:35 160

原创 86-partition list

难度:medium 类别:linked list1.题目描述Given a linked list and a value x, partition it such that all nodes less than x come before nodes greater than or equal to x.You should preserve the original relative ord

2017-11-03 12:48:17 186

原创 92-reverse linked list II

难度:medium 类别:linked list1.题目描述Reverse a linked list from position m to n. Do it in-place and in one-pass.For example: Given 1->2->3->4->5->NULL, m = 2 and n = 4,return 1->4->3->2->5->NULL.2.算法分析从左到右遍

2017-11-03 11:00:02 161

原创 82-Remove Duplicates from sorted list II

难度:medium 类别:linked list1.题目描述Given a sorted linked list, delete all nodes that have duplicate numbers, leaving only distinct numbers from the original list.For example, Given 1->2->3->3->4->4->5, re

2017-11-02 23:49:02 142

原创 83-Remove Duplicates From Sorted List

难度:easy 类别:linked list1.题目描述Given a sorted linked list, delete all duplicates such that each element appear only once.For example, Given 1->1->2, return 1->2. Given 1->1->2->3->3, return 1->2->3.2.算

2017-11-02 23:12:45 155

原创 25-Reverse Nodes in k-Group

难度:hard 类别:linked list1.题目描述Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.k is a positive integer and is less than or equal to the length of the link

2017-11-02 22:51:19 134

原创 61-Rotate list

难度:medium 类别:linked list1.题目描述Given a list, rotate the list to the right by k places, where k is non-negative.For example: Given 1->2->3->4->5->NULL and k = 2, return 4->5->1->2->3->NULL.2.算法分析(1)处理

2017-11-01 22:52:31 219

原创 24-Swap Nodes In Pairs

难度:medium 类别:linked list1.题目描述Given a linked list, swap every two adjacent nodes and return its head.For example, Given 1->2->3->4, you should return the list as 2->1->4->3.Your algorithm should use

2017-11-01 22:02:37 164

原创 19-Remove Nth node from end list

难度:medium 类别:linked list1.题目描述Given a linked list, remove the nth node from the end of list and return its head. Given linked list: 1->2->3->4->5, and n = 2. After removing the second node from the

2017-11-01 17:50:36 192

原创 21-Merge Two Sorted Lists

难度:easy 类别:linked list1.题目描述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. 注:不仅是合并,同时要保持合并后有序。2.算法分析3.代码

2017-10-24 23:44:58 155

原创 237-delete node in single list

难度:easy 类别:linked list1.题目描述给定要删除的结点,要求将该结点删除2.实现分析因为是单向链表,并且没有给定head指针,所以要想办法处理next指针。将问题转换为将node->next给node并且删除node->next即可。3.代码class Solution {public: void deleteNode(ListNode* node) {

2017-10-24 23:19:23 205

原创 2-Add Two Numbers

1.题目描述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 ret

2017-10-19 23:03:21 190

原创 编译原理词法分析

1.题目描述 2.代码实现(1)注意标识符和无符号整数的重复问题,本人采用map解决。 (2)cin >> ch自动忽略空白字符。#include <iostream>#include <vector>#include <string>#include <map>using namespace std;struct pairs { int category; int ra

2017-10-16 16:38:17 441

原创 DES算法设计

代码实现注:理解整个过程,实现简单#include <iostream>#include <bitset>#include <cstdlib>using namespace std;bitset<48> subkeys[16];// initial IP permutation table// notice: values in IP are from 1 to 64int IP[]

2017-10-13 14:19:28 350

原创 206-Reverse Linked List

[难度] easy [类别] linked list1.题目描述反转链表2.算法描述(1)第一种算法实现使用栈作为中间辅助。 首先将链表的所有节点push到栈中,然后再从栈中pop出来,即可得到反转链表代码实现:ListNode* reverseList(ListNode* head) { stack<ListNode*> mystack; // get reversed li

2017-10-13 14:07:28 163

原创 445-Add Two Numbers II

[难度] medium [分类] linked list1.题目描述You are given two non-empty linked lists representing two non-negative integers. The most significant digit comes first and each of their nodes contain a single digit

2017-10-13 13:38:18 211

原创 690-Employee Importance

[难度] easy [分类] array1.题目描述You are given a data structure of employee information, which includes the employee’s unique id, his importance value and his direct subordinates’ id.For example, employee 1

2017-10-08 22:48:08 352

原创 674-Longest Continuous Increasing Subsequence

难度:easy 类别:array1.题目描述Input: [1,3,5,4,7] Output: 3 Explanation: The longest continuous increasing subsequence is [1,3,5], its length is 3. Even though [1,3,5,7] is also an increasing subsequence,

2017-09-24 19:10:57 241

原创 240. Search a 2D Matrix II

1.题目描述Write an efficient algorithm that searches for a value in an m x n matrix. This matrix has the following properties:Integers in each row are sorted in ascending from left to right. Integers in e

2017-09-19 21:10:11 309

原创 315-Count of Smaller Numbers After Self

1.题目描述You are given an integer array nums and you have to return a new counts array. The counts array has the property where counts[i] is the number of smaller elements to the right of nums[i]. Exampl

2017-09-18 15:22:32 427

原创 215-Kth Largest Element in an Array

难度:medium 类别:divide and conquer1.题目描述Find the kth largest element in an unsorted array. Note that it is the kth largest element in the sorted order, not the kth distinct element.For example, Given [3

2017-09-16 23:10:27 258

原创 169-Majority Element

1.题目描述Given an array of size n, find the majority element. The majority element is the element that appears more than ⌊ n/2 ⌋ times.You may assume that the array is non-empty and the majority element a

2017-09-16 09:15:32 221

空空如也

空空如也

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

TA关注的人

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