自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

ailinyingai的博客

努力 持之以恒

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

原创 0050

// 二分求解 这里幂n > 0static double powhelper(double x, int n){ if (n == 0) return 1; double res = powhelper(x, n / 2); if (n % 2 == 0) return res * res; else return res * res * x;} do...

2019-09-30 21:24:46 98

翻译 0049

class Solution {public: vector<vector<string>> groupAnagrams(vector<string>& strs) { map<string, vector<string>> mp; vector<vector<string&g...

2019-09-30 21:22:38 188

翻译 0048

class Solution {public: void rotate(vector<vector<int>>& matrix) { int size = matrix.size(); for (int i = 0; i < size - 1; i++) { for (int j = i; j ...

2019-09-30 21:21:16 121

原创 0047

class Solution {public: vector<vector<int> > permuteUnique(vector<int> &num) { vector<vector<int> > res; vector<int> out; vector&lt...

2019-09-30 21:16:53 170

原创 0046

class Solution { vector<vector<int>> permute(vector<int>& nums) { vector<vector<int>> result; if(nums.size() == 0) return result; result.push_back(vect...

2019-09-30 21:15:42 226

翻译 0045

class Solution: def jump(self, nums): result = reach = maxReach = 0 for index, num in enumerate(nums): if index > reach: reach = maxReach ...

2019-09-29 17:10:19 412

翻译 0044

class Solution: def isMatch(self, s, p): m, n = len(s), len(p) #状态数组,表示从s的i到p的j是否可以匹配 dp = [[False for j in range(n + 1)] for i in range(m + 1)] dp[0][0] = True ...

2019-09-29 17:08:18 273

原创 最短路径

Dijkstra算法可用于求解图中某源点到其余各顶点的最短路径。假设G={V,{E}}是含有n个顶点的有向图,以该图中顶点v为源点,使用Dijkstra算法求顶点v到图中其余各顶点的最短路径的基本思想如下:使用集合S记录已求得最短路径的终点,初始时S={v}。选择一条长度最小的最短路径,该路径的终点w属于V-S,将w并入S,并将该最短路径的长度记为Dw。对于V-S中任一顶点是s,将源点到顶点...

2019-09-29 17:06:25 442

翻译 0043

class Solution: def str2num(self, num): int_num = 0 pos = 1 for n in num[::-1]: int_num += (ord(n) - 48) * pos pos = pos * 10 print(int_num...

2019-09-29 17:06:01 247

原创 0042

class Solution: def trap(self, height): """ :type height: List[int] :rtype: int """ left = 0 right = len(height) - 1 res = 0 left_ma...

2019-09-28 15:35:19 347

翻译 0041

class Solution: def firstMissingPositive(self, nums): """ :type nums: List[int] :rtype: int """ for i in range(1, len(nums) + 2): # be careful the start and...

2019-09-28 15:25:05 127

原创 foobar

import threadingclass FooBar: def __init__(self, n): self.n = n self.foo_lock = threading.Semaphore() #添加信号量计数器,初始值为1 self.foo_lock.acquire() # 令两个计数器的值为0,造成线程阻塞 s...

2019-09-28 15:21:36 194

原创 文档记录

https://www.yuque.com/huarou/gd4szw/remeed

2019-09-28 13:43:57 204

原创 0040

class Solution: def Slover(self, candidates, target, res, path, idx): for i in range(idx, len(candidates)): new_target = target - candidates[i] if new_target < 0...

2019-09-28 13:34:58 155

翻译 0283

class Solution(object): def moveZeroes(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ N = len...

2019-09-28 13:33:12 258

原创 0039

class Solution(object): def combinationSum(self, candidates, target): """ :type candidates: List[int] :type target: int :rtype: List[List[int]] """ ...

2019-09-28 13:30:32 101

翻译 0038

class Solution: def count(self, snum): num_count = [] before = "" for s in snum: if s != before: num_count.append(["1" + s]) bef...

2019-09-28 13:21:28 109

翻译 0037 解决数独

class Solution: def solver(self, board): import copy # get the candidates based on rule of row cd_row = [["1", "2", "3", "4", "5", "6", "7", "8", "9...

2019-09-28 08:52:42 112

翻译 0036

class Solution: def isValidSudoku(self, board): """ :type board: List[List[str]] :rtype: bool """ # check every row valid or not for row in board:...

2019-09-28 08:48:56 470

翻译 0035

class Solution: def searchInsert(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ le = len(nums) if le == 0...

2019-09-27 16:14:12 82

翻译 1190 反转括号子串

class Solution(object): def reverseParentheses(self, s): """ :type s: str :rtype: str """ if not s or ")" not in s: return s stack = []...

2019-09-27 16:13:02 190

翻译 0034

class Solution: def searchRange(self, nums, target): """ :type nums: List[int] :type target: int :rtype: List[int] """ le = len(nums) if le ...

2019-09-27 16:12:09 52

翻译 0033

# _*_ coding: utf-8 _*_class Solution(object): def search(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ if no...

2019-09-27 16:09:16 194

翻译 0032

class Solution: def longestValidParentheses(self, s): """ :type s: str :rtype: int """ dp = [] lens = len(s) if lens < 2: r...

2019-09-27 13:56:15 109

翻译 0031 下一个排列

class Solution: def nextPermutation(self, nums): """ :type nums: List[int] :rtype: void Do not return anything, modify nums in-place instead. """ numr = sor...

2019-09-27 10:37:57 58

原创 0029

class Solution: def divide(self, dividend, divisor): """ :type dividend: int :type divisor: int :rtype: """ res = 0 if dividend == 0: ...

2019-09-27 10:05:29 184

原创 0028

class Solution: def strStr(self, haystack, needle): """ :type haystack: str :type needle: str :rtype: int """ if haystack == needle: re...

2019-09-27 08:57:17 105

原创 0026

class Solution: def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ if len(nums) == 0 or len(nums) == 1: return len(nums...

2019-09-27 08:53:37 77

原创 0023

# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def mergeKLists(self, lists): """ ...

2019-09-27 08:52:16 299

原创 0027

class Solution(object): def removeElement(self, nums, val): """ :type nums: List[int] :type val: int :rtype: int """ if len(nums) == 0: ...

2019-09-27 08:51:02 144

原创 0075 着色问题

class Solution: def sortColors(self, nums): zero = -1 i = 0 two = len(nums) while i < two: if nums[i] == 1: i += 1 elif ...

2019-09-26 14:05:29 91

翻译 题目分类

ArrayRemove Duplicates from Sorted ArrayRemove ElementNext PermutationFirst Missing PositiveSpiral MatrixMerge IntervalsInsert IntervalSpiral Matrix IISet M...

2019-09-26 14:03:55 203

原创 0022括号生成

class Solution(object): def generateParenthesis(self, n): ans = [] def backtrack(S = '', left = 0, right = 0): if len(S) == 2 * n: ans.append(S) ...

2019-09-26 13:08:58 106

原创 redis 命令总结

1.键值相关的命令keys返回满足给定pattern的所有key表达式* 代表取出所有的keyredis 127.0.0.1:6379> keys *“myzset2”“myzset3”“mylist”“myset2”“myset3”“myset4”“k_zs_1”keys prefix_* // 查看前缀为"prefix_"的所有keysexists...

2019-09-26 10:09:10 81

原创 0026

class Solution(object): def removeDuplicates(self, nums): """ :type nums: List[int] :rtype: int """ # 删除列表中的重复项,返回操作后的长度 # [1,1,1,2,3,4,4,4,5] ->...

2019-09-26 08:55:13 99

翻译 0021 合并两个有序列表

# Definition for singly-linked list.# class ListNode:# def __init__(self, x):# self.val = x# self.next = Noneclass Solution: def mergeTwoLists(self, l1, l2): """...

2019-09-26 08:54:03 69

原创 0020 有效的括号

class Solution: def isValid(self, s): """ :type s: str :rtype: bool """ # s with odd length is not valid l = len(s) if l & 1 != 0: ...

2019-09-25 17:51:15 67

翻译 0019

class Solution: def removeNthFromEnd(self, head, n): """ :type head: ListNode :type n: int :rtype: ListNode """ head0 = ListNode(0) head0.ne...

2019-09-25 17:29:30 72

原创 0017

class Solution: def letterCombinations(self, digits): """ :type digits: str :rtype: List[str] """ if not digits: return [] type_dic = ...

2019-09-25 16:45:00 83

原创 0016 最接近的三数之和

class Solution: def threeSumClosest(self, nums, target): """ :type nums: List[int] :type target: int :rtype: int """ # 如果只有3个数,那直接返回这三个数的和 i...

2019-09-25 16:42:44 59

空空如也

空空如也

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

TA关注的人

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