自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(62)
  • 资源 (1)
  • 收藏
  • 关注

原创 leetcode 92. Reverse Linked List II

反转指定两个位置之间的树。ListNode *reverseBetween(ListNode *head, int m, int n) { if(m==n)return head; n-=m; ListNode prehead(0); prehead.next=head; ListNode* pre=&prehead; while(--m)pre=pr

2017-02-28 21:14:10 316

原创 leetcode 84 Remove Duplicates from Sorted List II

删除一个链表里面重复出现过的元素。 11123 -〉 23自己的思路:/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class

2017-02-28 16:03:42 319

原创 leetcode 41 finding missing positive

找到数组中第一个消失的正整数。先桶排序,将值为i的数和第 i-1 位 交换,然后遍历数组找到第一个值不等于位置 +1 的即可。class Solution {public: int firstMissingPositive(vector<int>& nums) { int l=nums.size(); for(int i=0;i<l;i++){

2017-02-27 20:41:47 246

原创 leetcode-38-count and say

1, 11, 21, 1211, 111221, …1 is read off as “one 1” or 11. 11 is read off as “two 1s” or 21. 21 is read off as “one 2, then one 1” or 1211.求第n个序列的输出。基本思路,迭代。 循环计算下一个输出,循环调用next函数。 int b=8; char a=b

2016-10-18 09:46:37 236

原创 leetcode-37-sudoku solver

题目:求解数独,假设只有一种结果。回溯法递归判断每一个 空位置的 所有可能性。 比如 第一个为空 的位置 为1是是有效的,然后递归调用 solvesudoku(新的第一个位置为1的board),依次递归。如果false了,在返回到第一个位置为第二个有效数字的情况。注意: board[i][j] = ‘1’ + k; int 和 char 可以直接加,vector。// LeetCode, Su

2016-09-26 11:11:09 260

原创 leetcode-36-valid sudoku

Determine if a Sudoku is valid, according to: Sudoku Puzzles - The Rules.The Sudoku board could be partially filled, where empty cells are filled with the character ‘.’.A partially filled sudoku which

2016-09-21 15:05:17 232

原创 leetcode-35-search insert position

Given a sorted array and a target value, return the index if the target is found. If not, return the index where it would be if it were inserted in order.You may assume no duplicates in the array.Here

2016-09-14 20:52:05 172

原创 leetcode-34-search for a range

Given a sorted array of integers, find the starting and ending position of a given target value.Your algorithm’s runtime complexity must be in the order of O(log n).If the target is not found in the ar

2016-09-14 14:41:15 207

原创 leetcode-33-search in rotated array

Suppose a sorted array 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 the array return its index

2016-09-09 16:24:04 281

原创 leetcode-32-Longest Valid Parentheses

Given a string containing just the characters ‘(’ and ‘)’, find the length of the longest valid (well-formed) parentheses substring.For “(()”, the longest valid parentheses substring is “()”, which has

2016-08-30 09:20:02 405

原创 leetcode-02-add two numbers-c++

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

2016-08-26 15:56:06 561

原创 leetcode-31-Next Permutation

题目: Implement next permutation, which rearranges numbers into the lexicographically next greater permutation of numbers.If such arrangement is not possible, it must rearrange it as the lowest possible

2016-08-24 15:25:22 234

原创 leetcode-30-Substring with Concatenation of All Words

You are given a string, s, and a list of words, words, that are all of the same length. Find all starting indices of substring(s) in s that is a concatenation of each word in words exactly once and wit

2016-08-02 17:28:01 402

原创 leetcode-29-Divide Two Integers

题目:Divide two integers without using multiplication, division and mod operator.If it is overflow, return MAX_INT.题目大意:不用乘法除法和取余运算符来完成除法运算。 思路:只能用减法咯。 a 除以 b 每次我们可以使用2分法来加速这个过程。每次减运算时对除数乘以2加倍,直到它比被除数

2016-07-05 17:07:36 266

原创 leetcode-28-Implement strStr()

题目:Returns the index of the first occurrence of needle in haystack, or -1 if needle is not part of haystack.题目大意:给两个字符串haystack和needle。返回needle在haystack中第一次出现的位置。思路:遍历haystack。如果在i位置满足条件就返回当前位置。注意边界条件。

2016-06-02 22:01:42 202

原创 leetcode-27-Remove Element

题目:Given an array and a value, remove all instances of that value in place and return the new length.Do not allocate extra space for another array, you must do this in place with constant memory.The or

2016-06-01 11:17:10 203

原创 leetcode-26-Remove Duplicates from Sorted Array

题目:Given a sorted array, remove the duplicates in place such that each element appear only once and return the new length.Do not allocate extra space for another array, you must do this in place with c

2016-06-01 10:49:31 220

原创 leetcode-25-Reverse Nodes in k-Group

Given a linked list, reverse the nodes of a linked list k at a time and return its modified list.If the number of nodes is not a multiple of k then left-out nodes in the end should remain as it is.You

2016-05-31 22:24:04 233

原创 leetcode-24-Swap Nodes in Pairs

题目:iven 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.交换链表每两个元素的位置。思路: 1.出现单个的情况链表不变 2.链表为空或者只有一个元素,返回head头

2016-05-19 21:50:56 570 2

原创 c语言文件操作总结

周末填坑

2016-05-17 16:42:18 775 1

原创 树莓派远程连接的三种方式总结

总结远程连接树莓派的三种方式,对大部分linux系统同样适用。 首先需要将树莓派连接上网,ifconfig记录ip地址。第一种:ssh远程连接 在linux下使用 ssh [email protected] 可以登录。在windows下使用putty这个工具,下载地址文末。 操作如图。 ***Open Username:pi Passwd:raspberry***(必要条件)

2016-05-17 09:27:18 50166 3

原创 leetcode-23-Merge k Sorted Lists

题意:合并k个有序链表。tags:divide and conquer。分治算法。思路在代码注释里面。 测试通过时间神奇的在32ms。一般为400ms。/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x)

2016-05-11 22:17:51 315

转载 堆VS栈

一、预备知识—程序的内存分配 一个由C/C++编译的程序占用的内存分为以下几个部分 1、栈区(stack)— 由编译器自动分配释放 ,存放函数的参数值,局部变量的值等。其 操作方式类似于数据结构中的栈。 2、堆区(heap) — 一般由程序员分配释放, 若程序员不释放,程序结束时可能由OS回 收 。注意它与数据结构中的堆是两回事,分配方式倒是类似

2016-05-11 15:59:41 709

原创 leetcode-22-Generate Parentheses

Given n pairs of parentheses, write a function to generate all combinations of well-formed parentheses.For example, given n = 3, a solution set is:“((()))”, “(()())”, “(())()”, “()(())”, “()()()”题目大意:

2016-05-10 22:41:18 312

原创 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。 将两个有序链表按序合并。 主要是链表的操作,与链表有关的题就拿c++做了。思路:依次比较两个链表的当前元素的

2016-05-10 17:30:33 857

原创 leetcode-19-Remove Nth Node From End of List

题意:删除链表从后往前开始的第n个节点。单链表的操作。别人说用python来实现单链表没有意义,好吧我不知道怎么反驳暂且附和好了。python用list可以实现堆栈和队列(pop(0)啥的…)。熟悉了链表的操作之后,本题的意思就在于从后往前的数,两个指针。第一个先走n步,然后第二个出发,到第一个继续走到最后一个元素的时候,第二个此时的位置的节点就是我们要删除的节点。要注意的是可能要删除的是第一个元素

2016-05-05 16:27:40 244

转载 C++ 单链表基本操作分析与实现

链表  链表是一种物理存储单元上非连续、非顺序的存储结构,数据元素的逻辑顺序是通过链表中的指针链接次序实现的。链表由一系列结点(链表中每一个元素称为结点)组成,结点可以在运行时动态生成。每个结点包括两个部分:一个是存储数据元素的数据域,另一个是存储下一个结点地址的指针域。 相比于线性表顺序结构,链表比较方便插入和删除操作。创建头节点  手动new一个新的Node,将Node的next置为NULL即可

2016-05-05 16:17:20 910

原创 leetcode-20-Valid Parentheses

题意:判断三种括号出现的次序是否正确。 比如:([{}]),{}[] ,()都为true。{[}]为false。直接用栈。遍历一遍遇到左边的括号入栈,在栈不为空的情况下遇到第一个右边的括号时候判断栈顶元素是否对应。class Solution(object): def isValid(self, s): """ :type s: str :r

2016-05-04 19:56:28 224

原创 leetcode-18-4sum

class Solution {public: vector<vector<int> > fourSum(vector<int> &num, int target) { vector<vector<int> > ret; int len = num.size(); if (len <= 3) return ret;

2016-04-28 17:10:08 202

原创 leetcode-17-Letter Combinations of a Phone Number

Given a digit string, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below.Input:Digit string “23”

2016-04-27 18:32:04 289

原创 leetcode-16-3sum closest

题目:给一个list,一个target。找list中3个数相加最接近target的值。class Solution(object): def threeSumClosest(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int

2016-04-27 11:37:20 211

原创 leetcode-15-3sum

题目大意:给一个数组,选出其中所有的3个数加起来等于0的组合。 python:class Solution(object): def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ nums.sort()

2016-04-19 17:29:19 223

原创 leetcode-14-Longest Common Prefix

Write a function to find the longest common prefix string amongst an array of strings. 题意:求最长前缀字符串。 python:class Solution(object): def longestCommonPrefix(self, strs): """ :type s

2016-04-13 17:15:37 256

原创 leetcode-13-roman to integer

罗马数字转换为阿拉伯数字,同样是0-3999之内。class Solution(object): def romanToInt(self, s): """ :type s: str :rtype: int """ a=0 d=["MMM","MM","M"] for i in ra

2016-04-13 16:13:25 238

原创 leetcode-12-integer to roman

百度了一下罗马数字转换规则,百度百科居然就有完整的代码。。 基本字符 I V X L C D M 相应的阿拉伯数字表示为 1 5 10 50 100 500 1000 相同的数字连写、所表示的数等于这些数字相加得到的数、如:Ⅲ=3; 小的数字在大的数字的右边、所表示的数等于这些数字相加得到的数、 如:Ⅷ=8、Ⅻ=12; 小的数字、(限于 Ⅰ、X 和 C)在大的

2016-04-13 15:05:15 260

原创 leetcode-11-Container With Most Water

Given n non-negative integers a1, a2, …, an, where each represents a point at coordinate (i, ai). n vertical lines are drawn such that the two endpoints of line i is at (i, ai) and (i, 0). Find two lin

2016-04-13 14:35:14 338 3

原创 leetcode-10-Regular Expression Matching

正则匹配。最懒的方法,python直接re.match()。。class Solution: # @return a boolean def isMatch(self, s, p): return re.match('^' + p + '$', s) != None 必须要首尾匹配才行。。 例如:a='hello'b='helloworld're.

2016-04-12 22:25:46 225

原创 leetcode-09-Palindrome Number

class Solution(object): def isPalindrome(self, x): """ :type x: int :rtype: bool """ b=x if x<0:return False if x>=2147483648:return False

2016-04-05 21:35:24 601

原创 leetcode-08-String to Integer (atoi)

cpp:class Solution { public: int myAtoi(string str) { if(str.length() == 0) { return 0; } int i = 0; while(str[i] == ' ')

2016-04-05 17:16:53 200

原创 leetcode-07-reverse integer-python

Reverse digits of an integer. 反转一个数,注意符号,溢出范围。题目说的是32位int。 自己的思路:转换成list,先拿出符号,然后不断pop掉的字符加在一起最后如果没溢出就输出。感觉很妙,像堆栈的感觉。class Solution(object): def reverse(self, x): """ :type x: int

2016-04-01 11:35:22 341

linux-headers-3.18.5+_3.18.5+-2_armhf

linux-headers-3.18.5+_3.18.5+-2_armhf

2016-04-13

空空如也

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

TA关注的人

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