MX space


  • 首页

  • 标签

  • 分类

  • 归档

  • 日程表

  • 搜索

两学一做背诵材料

发表于 2016-12-04 | 更新于 2016-12-18 | 阅读次数:
本文字数: 1.5k | 阅读时长 ≈ 1 分钟

基本概念

两学一做

学党章党规、学系列讲话、做合格党员

四讲四有

讲政治,有信念;讲规矩,有纪律;讲道德,有品行;讲风险,有作为

四个全面

全面建成小康社会、全面深化改革、全面依法治国、全面从严治党。

阅读全文 »

Number of Segments in a String

发表于 2016-12-04 | 更新于 2019-05-03 | 分类于 Leetcode | 阅读次数:
本文字数: 1.3k | 阅读时长 ≈ 1 分钟

题目出处

源自于leetcode

题目描述

Count the number of segments in a string, where a segment is defined to be a contiguous sequence of non-space characters.

For example,

Input: "Hello, my name is John"

Output: 5

解读

计算给定字符串的片段数,片段由空白字符分割。
如给定:"Hello, my name is John", 输出5(五个片段,分别为"Hello,", "my", "name", "is", "John"

阅读全文 »

Median of Two Sorted Arrays

发表于 2016-12-03 | 更新于 2019-05-03 | 分类于 Leetcode | 阅读次数:
本文字数: 842 | 阅读时长 ≈ 1 分钟

题目出处

源自于leetcode

题目描述

There are two sorted arrays nums1 and nums2 of size m and n respectively.

Find the median of the two sorted arrays. The overall run time complexity should be O(log (m+n)).

Example 1:

1
2
3
4
nums1 = [1, 3]
nums2 = [2]

The median is 2.0

1
2
3
4
5
Example 2:
nums1 = [1, 2]
nums2 = [3, 4]

The median is (2 + 3)/2 = 2.5

解读

给定两个有序数组,长度分别为m和n,找到两个数组的中位数。时间复杂度应该为O(log(m+n))

阅读全文 »

Elixir Introduction 2

发表于 2016-12-01 | 更新于 2019-05-03 | 分类于 Elixir | 阅读次数:
本文字数: 2.4k | 阅读时长 ≈ 2 分钟

不可变性

Elixir中,所有的值都是不可变的。

基础

原子

院子是常量,用于表示某些东西的名字,以冒号(:)开头

元组

元组被创建就无法修改,如:{1, 2}
用于模式匹配

1
2
3
4
5
6
7
8
9
iex(4)> {status, count, action} = {:ok, 42, "next"}
{:ok, 42, "next"}
iex(5)> status
:ok
iex(6)> count
42
iex(7)> action
"next"
iex(8)>

散列表

1
2
3
4
5
6
7
8
iex(9)> states = %{"AL" => "Alabama", "WI" => "Wisconsin"}
%{"AL" => "Alabama", "WI" => "Wisconsin"}
iex(10)> states["AL"]
"Alabama"
iex(11)> colors = %{ red: 0xff0000 }
%{red: 16711680}
iex(12)> colors.red
16711680

匿名函数

函数定义

  1. 匿名函数用fn关键字创建;
  2. 函数定义中可以省略圆括号;
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
iex(1)> sum = fn (a, b) -> a + b end
#Function<12.52032458/2 in :erl_eval.expr/5>
iex(2)> sum.(1, 2)
3
iex(3)> greet = fn -> IO.puts "Hello" end
#Function<20.52032458/0 in :erl_eval.expr/5>
iex(4)> greet.()
Hello
:ok
iex(5)> f1 = fn a, b -> a * b end
#Function<12.52032458/2 in :erl_eval.expr/5>
iex(6)> f1.(5, 6)
30
iex(7)> f2 = fn -> 99 end
#Function<20.52032458/0 in :erl_eval.expr/5>
iex(8)> f2.()
99
iex(9)> swap = fn {a, b} -> {b, a} end
#Function<6.52032458/1 in :erl_eval.expr/5>
iex(10)> swap.({6, 8})
{8, 6}
iex(11)> list_concat = fn l1, l2 -> l1 ++ l2 end
#Function<12.52032458/2 in :erl_eval.expr/5>
iex(12)> list_concat.([:a, :b], [:c, :d])
[:a, :b, :c, :d]
iex(13)> sum = fn a, b, c -> a + b + c end
#Function<18.52032458/3 in :erl_eval.expr/5>
iex(14)> sum.(1, 2, 3)
6
iex(15)> pair_tuple_to_list = fn {a, b} -> [a, b] end
#Function<6.52032458/1 in :erl_eval.expr/5>
iex(16)> pair_tuple_to_list.({1234, 5678})
[1234, 5678]

函数重载

函数重载取决于传入的参数类型和内容,通过模式匹配来选择要运行的子句

1
2
3
4
5
6
7
8
9
10
iex(1)> handle_open = fn
...(1)> {:ok, file} -> "Read data: #{IO.read(file, :line)}"
...(1)> {_, error} -> "Error: #{:file.format_error(error)}"
...(1)> end
#Function<6.52032458/1 in :erl_eval.expr/5>
iex(2)> handle_open.(File.open('donotexistfile'))
"Error: no such file or directory"
iex(3)> handle_open.(File.open('/tmp/test.py'))
"Read data: #!/usr/bin/env python\n"
iex(4)> handle_open.(File.open('/tmp/test.py'))

Longest Substring Without Repeating Characters

发表于 2016-12-01 | 更新于 2019-05-03 | 分类于 Leetcode | 阅读次数:
本文字数: 2.1k | 阅读时长 ≈ 2 分钟

题目出处

源自于leetcode

题目描述

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 length of 1.
Given "pwwkew", the answer is "wke", with the length of 3. Note that the answer must be a substring, "pwke" is a subsequence and not a substring.

解读

给定一个字串,返回最长不包含重复字符的子串。如"abcabcbb"的最长不包含重复字符的子串为“abc”,“bca”`等,长度都为3

阅读全文 »

Add Two Numbers

发表于 2016-11-30 | 更新于 2018-07-17 | 分类于 leetcode | 阅读次数:
本文字数: 3k | 阅读时长 ≈ 3 分钟

题目出处

来自于leetcode

题目描述

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 linked list.

1
2
Input: (2 -> 4 -> 3) + (5 -> 6 -> 4)
Output: 7 -> 0 -> 8
阅读全文 »

Two Sum

发表于 2016-11-28 | 更新于 2019-05-03 | 分类于 Leetcode | 阅读次数:
本文字数: 1.6k | 阅读时长 ≈ 1 分钟

description

题目出处:leetcode

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.

Example:

1
2
3
4
Given nums = [2, 7, 11, 15], target = 9,

Because nums[0] + nums[1] = 2 + 7 = 9,
return [0, 1].

阅读全文 »

Autopep8

发表于 2016-11-28 | 更新于 2019-05-03 | 分类于 Python | 阅读次数:
本文字数: 1.3k | 阅读时长 ≈ 1 分钟

Introduction

Autopep8是一个将Python代码自动排版为PEP8风格的小工具。
它使用pep8工具来决定代码中的哪部分需要被排版。
Autopep8可以修复大部分pep8工具中报告的排版问题。

阅读全文 »

Rails 下载文件

发表于 2016-11-28 | 更新于 2019-05-03 | 阅读次数:
本文字数: 363 | 阅读时长 ≈ 1 分钟
  1. 根据request的format参数来确定返回值类型,代码如下:

    1
    2
    3
    4
    5
    6
    7
    respond_to do |format|
    format.html
    format.csv do
    headers['Content-Disposition'] = "attachment; filename='filename.csv'"
    headers['Content-Type'] ||= 'text/csv'
    end
    end
  2. 链接地址:

    1
    <%= link_to('Download Link', {:action => :download, :format => :csv}) %>
  3. 添加CSV模板文件,命名为<action_name>.csv.erb

Python 字符编码理解

发表于 2016-11-28 | 更新于 2019-05-03 | 分类于 Python | 阅读次数:
本文字数: 1.5k | 阅读时长 ≈ 1 分钟

base: https://segmentfault.com/a/1190000007594453#articleHeader6

阅读全文 »
1…192021
Yarving Liu

Yarving Liu

206 日志
55 分类
110 标签
RSS
GitHub E-Mail
© 2020 Yarving Liu | 275k | 4:10
由 Hexo 强力驱动 v3.9.0
|
主题 — NexT.Mist v6.2.0
0%