自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 快速排序-总结与改进

之前的几次面试都有问到快速排序,我的写法都是按照算法导论上随便写写的:一:基本快速排序:(参照算法导论)#快速排序def quicksort(nums,p,r): if p<r: q=partition(nums,p,r) quicksort(nums,p,q-1) quicksort(nums,q+1,r) returndef pa

2017-03-23 12:04:22 437

原创 剑指offer-python代码-第二章

开始看剑指offer,粗略的捋一捋里面的面试题:以下代码大多用python3写的,少部分会用C++ python代码看上去更加简洁明了,里面也穿插和补充了我的部分总结。p38:二维数组中的查找:从右上角或者左下角开始:def searchMatrix( matrix, target): """ :type matrix: List[List[int]] :type targ

2017-03-09 15:48:46 434

原创 20分钟回顾基础排序与二分查找

来来,复习基础的数据结构吧~~知乎上有人讲,如果只是应付面试,重要程度: 数据结构:二叉树>散列表>栈>队列>堆>一般树>图>其他 算法:二分法>冒泡>快速排序>加密算法>其他排序算法>随机数的算法>其他下面需要20分钟就能 浏览完,最最基础的:基本排序与二分查找~~排序#插入排序def insertion_sort(nums): for i in range(1,len(nums))

2017-03-02 14:00:15 369

原创 频数相关的leetcode:451 Sort Characters By Frequency& 347 Top K Frequent Elements

利用字典,zip函数,再排序,则这两个题投机取消的很简单。347 Top K Frequent Elementsclass Solution(object): def topKFrequent(self, nums, k): d={} for i in nums: if i in d: d[i]+=1

2017-03-06 17:22:46 324

原创 二叉树回顾

遍历:前序遍历: 节点-左-右使用一个栈来实现,非递归:class Solution(object): def preorderTraversal(self, root): """ :type root: TreeNode :rtype: List[int] """ if not root:return []

2017-03-05 15:10:09 300

原创 445. Add Two Numbers II

回顾一下,链表: 445. Add Two Numbers II 这个题目,最开始就考虑反转链表,但是题目不允许,我采取了用 栈 把链表里的数取出来的做法。。 后面的做法和 add two numbers 1 差不多了class ListNode(object): def __init__(self, x): self.val = x self.n

2017-03-04 13:04:09 367

原创 动态规划leetcode 回顾

Counting Bits看看数 0 0 dp[0]=0 1 1 dp[1]=dp[1-1]+1 2 10 dp[2]=dp[2-2]+14 100 dp[4]=dp[4-4]+18 1000 dp[8]=dp[8-8]+1动态规划:dp[i]=dp[i-offset]+1 代码:class Solution(object): def countBits(self, n

2017-03-02 16:28:35 311

原创 485 Max Consecutive Ones

485 Max Consecutive Ones 求连续的1的个数 第一个想到的老办法,用两个指针:start来记录开始与结束class Solution(object): def findMaxConsecutiveOnes(self, nums): """ :type nums: List[int] :rtype: int

2017-03-01 21:40:52 276

原创 263.Ugly Number||202 happy number||476 Number Complement||136 Single Number

leetcode

2017-03-01 21:21:30 289

翻译 整理:A Critical Review of Recent Progress in Mid-Range Wireless Power Transfer

之前写申请书,再写申请书的之前,看过一些论文,短短的整理整理一些。 原文:A Critical Review of Recent Progress in Mid-Range Wireless Power Transfer 中文大概:介绍无线电能传输起源于特斯拉,依据传输的机制可分为: - 辐射式无线电能传输 - 非辐射式无线电能传输辐射式无线电能传输传输距离较远,但是由于全方向电能传输的特性

2017-03-01 16:51:38 1384

原创 python复习

缕一缕之前的python 3语法细节,很多常用的基本的就不写了~~列表方法appendcountextendindexinsertpopremove (移除第一个匹配)reverse (改变原列表,不返回值)sort sorted 参数key元组不可变tuple([1,2,3]) #(1,2,3)字符串ASCII转换# Get the ASCII number

2017-03-01 16:40:37 355

原创 写完申请书,又要更新了

经历了漫长的看论文、写申请书的1月,2月,学校装空调的寒假,一回来就要准备改改小论文,再准备实习啦~~~

2017-02-28 15:17:57 356

原创 78. Subsets && 90. Subsets II

这个题目就是求子集,如【1,2】的子集就是【1】【2】【1,2】【】,别忘了空集。我想到的最容易的做法就是分治,用递归的方法求,求完之后再加上空集。 比如说:求【1,2】的子集。 1. 先求【1】的子集【1】 2. 再求【2】的子集【2】 3. 把子集”加”起来 [a+b for a in l1 for b in l2]+l1+l2 1. 最后再加上空集整体代码如下:class Solut

2016-12-10 14:13:33 260

原创 3. Longest Substring Without Repeating Characters

Given a string, find the length of the longest substring without repeating characters.Examples:Given "abcabcbb", the answer is "abc", which the length is 3.Given "bbbbb", the answer is "b", with the le

2016-12-10 13:18:56 236

原创 15.3Sum &16.3Sum Closest

第16题是找一个和target最接近的数,两个指针双层遍历即可:class Solution(object): def threeSumClosest(self, nums, target): result=nums[0]+nums[1]+nums[2] nums.sort() for i in range(len(nums)-2):

2016-12-08 16:37:09 222

原创 C++基础知识:友元

封装封装(英语:Encapsulation)是指,一种将[抽象] “抽象化 (计算机科学)”)性函数接口的实现细节部分包装、隐藏起来的方法。封装的优点: - 确保用户代码不会无意间破坏封装对象的状态 - 被封装的类的具体实现细节可以随时改变,无需调整用户级别的代码。 摘自《C++primer》友元采用类的机制后实现了数据的隐藏与封装,类的数据成员一般定义为私有成员,成员函数一般定义为公有的,依

2016-11-30 21:59:29 316

原创 89. Gray Code

The gray code is a binary numeral system where two successive values differ in only one bit.Given a non-negative integer n representing the total number of bits in the code, print the sequence of gray

2016-11-30 21:09:58 223

原创 377. Combination Sum IV

Given an integer array with all positive numbers and no duplicates, find the number of possible combinations that add up to a positive integer target.Example:_**nums**_ = [1, 2, 3]_**target**_ = 4The

2016-11-30 11:07:49 255

原创 319. Bulb Switcher

There are n bulbs that are initially off. You first turn on all the bulbs. Then, you turn off every second bulb. On the third round, you toggle every third bulb (turning on if it’s off or turning off i

2016-11-29 22:00:38 260

原创 400. Nth Digit

Find the nth digit of the infinite integer sequence 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, …Note: n is positive and will fit within the range of a 32-bit signed integer (n < 231).Example 1:**Input:**3**O

2016-11-29 21:36:36 227

原创 445. Add Two Numbers II

You are given two linked lists representing two non-negative numbers. The most significant digit comes first and each of their nodes contain a single digit. Add the two numbers and return it as a linke

2016-11-28 22:10:37 321

原创 红黑树(未完待续)

二叉查找树特点若任意结点的左子树不空,则左子树上所有结点的值均小于它的根结点的值;若任意结点的右子树不空,则右子树上所有结点的值均大于它的根结点的值;任意结点的左、右子树也分别为二叉查找树。没有键值相等的结点(no duplicate nodes)。红黑树它在二叉查找树的基础上增加了着色和相关的性质使得红黑树相对平衡,从而保证了红黑树的查找、插入、删除的时间复杂度最坏为O(log n)。1

2016-11-28 22:03:51 474

原创 463. Island Perimeter

You are given a map in form of a two-dimensional integer grid where 1 represents land and 0 represents water. Grid cells are connected horizontally/vertically (not diagonally). The grid is completely s

2016-11-28 17:33:09 374

原创 435. Non-overlapping Intervals

Given a collection of intervals, find the minimum number of intervals you need to remove to make the rest of the intervals non-overlapping.Note:You may assume the interval’s end point is always bigger

2016-11-22 16:10:44 301

原创 86. Partition List

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 order of the nodes in each of the

2016-11-22 15:30:26 250

原创 423. Reconstruct Original Digits from English

Given a non-empty string containing an out-of-order English representation of digits 0-9, output the digits in ascending order.Note:Input contains only lowercase English letters.Input is guaranteed t

2016-11-21 22:37:47 344

原创 python bisect模块的应用方法与leetcode:436. Find Right Interval

这个模块只有几个函数,一旦决定使用二分搜索时,立马要想到使用这个模块.    >>>import bisect     >>>dir(bisect)     [‘builtins‘, ‘cached‘, ‘doc‘, ‘file‘, ‘loader‘, ‘name‘, ‘package‘, ‘spec‘, ‘bisect’, ‘bisect_left’, ‘bisect_right’, ‘ins

2016-11-21 17:07:54 649

原创 438. Find All Anagrams in a String

Given a string s and a non-empty string p, find all the start indices of p’s anagrams in s.Strings consists of lowercase English letters only and the length of both strings s and p will not be larger t

2016-11-17 11:31:39 366

原创 451. Sort Characters By Frequency

Given a string, sort it in decreasing order based on the frequency of characters. 就是按频数来排序呗!! 我的做法是先写成字典,然后用sorted和zip函数一起对字典的value进行排序。class Solution(object):    def frequencySort(self, s):

2016-11-17 10:35:13 227

原创 437. Path Sum III

root = [10,5,-3,3,2,null,11,3,-2,null,1], sum = 8 10 / \ 5 -3 / \ \ 3 2 11 / \ \3 -2 1Return 3\. The paths that sum to 8 are:1\. 5 -> 32\. 5 -> 2 -> 13\. -3 -> 1

2016-11-16 21:34:19 247

原创 459. Repeated Substring Pattern

代码比较简单,分为奇数偶数讨论。 如果有第19行,运行时间35ms;没有的话 39ms.class Solution(object): def repeatedSubstringPattern(self, str): """ :type str: str :rtype: bool """ n=len(str)

2016-11-16 20:36:31 210

原创 455. Assign Cookies

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi, which is the minimum size of a cook

2016-11-16 17:07:31 322

原创 33. Search in Rotated Sorted 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-11-16 16:53:57 199

原创 153和154. Find Minimum in Rotated Sorted Array II

Follow up for “Find Minimum in Rotated Sorted Array”: What if duplicates are allowed? Would this affect the run-time complexity? How and why?Suppose a sorted array is rotated at some pivot unk

2016-11-16 15:27:52 270

原创 leetcode:447. Number of Boomerangs

原题的输入输出:**Input:**[[0,0],[1,0],[2,0]]**Output:**2**Explanation:**The two boomerangs are **[[1,0],[0,0],[2,0]]** and **[[1,0],[2,0],[0,0]]**直译是找回旋镖的个数。 我将其理解为 :先确定点 i,找到点k,j使得点i、k距离与点ij的距离相等。class S

2016-11-15 22:31:14 361

原创 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 tw

2016-11-14 21:49:33 292

原创 c++中main 函数执行完后还能执行其它语句吗?

此问题来自:C和C++程序员面试秘笈 p15 方法:用atexit()函数来注册 程序正常终止时要被调用的函数用法:用 法: int atexit(void (*func)(void));其参数是一个指针函数,指向一个没有参数也没有返回值的函数例子:#include <stdio.h>#include<stdlib.h> //atexit包含在此void fn1(void);void fn2

2016-11-14 20:54:20 617

原创 leetcode:216. Combination Sum III

216. Combination Sum III大意是说在1-9中选k个不同的数,使他们的和是n,返回是所有的选择。 Example 1: 输入: k = 3, n = 7 输出:[[1,2,4]] Example 2: 输入: k = 3, n = 9 输出:[[1,2,6], [1,3,5], [2,3,4]]思路: 1. 输入的k 肯定在必须在 1-9

2016-11-11 11:03:30 228

原创 leetcode:453. Minimum Moves to Equal Array Elements

Given a non-empty integer array of size n, find the minimum number of moves required to make all array elements equal, where a move is incrementing n - 1 elements by 1.Example:**Input:**[1,2,3]**Outp

2016-11-09 21:45:04 269

原创 leetcode:17. Letter Combinations of a Phone Number

输入输出示例 Input:Digit string “23” Output: [“ad”, “ae”, “af”, “bd”, “be”, “bf”, “cd”, “ce”, “cf”].我采用了将输入拆成两部分,然后再把结果加起来的方法。class Solution(object): def letterCombinations(self, digits): "

2016-11-09 21:18:45 275

空空如也

空空如也

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

TA关注的人

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