This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
public class QueueFromSevenStack<Item> { | |
private boolean isRevert = false; // 是否在反转 Stack. | |
private boolean isConcat = false; // 是否在拼接 Stack. | |
private Stack<Item> T = new Stack<>(); // 队列尾部,用于 enqueue 入队操作. | |
private Stack<Item> H = new Stack<>(); // 队列头部, 用于 dequeue 出队操作. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; My answer. | |
#| | |
keypoints: | |
* cache tail node. | |
* call set-cdr! | |
ref: | |
* tips: cons build pairs, not lists. cons build pairs, not lists. ref: https://stackoverflow.com/a/5741668 | |
* https://medium.com/@aleksandrasays/my-other-car-is-a-cdr-3058e6743c15 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import codecs | |
import os | |
import shutil | |
import glob | |
def convert(file_path: str, from_encoding: str, to_encoding: str): | |
utf16_path = file_path | |
utf8_tmp_path = utf16_path + ".tmp" | |
try: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# step3.1 | |
# check timedatectl | |
timedatectl | |
# change server timezone | |
sudo timedatectl set-timezone $timezone_you_need | |
# step3.2 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@task(alias='bot_p') | |
def bot_pomodoro(): | |
token = $your_robot_token | |
chat_id = $robot_chat_id_with_you | |
now = datetime.datetime.now() | |
minute = now.minute | |
tip = 'unknown error' | |
if minute == 0: |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
// 1.3.10 衍生 中缀转前缀 | |
public class InfixToPrefix { | |
/// 自动补全 左括号 . 反向推导表达式的原始形式. | |
/// 核心思路, 也即: 双栈表达式的精髓在于: 使用同一个栈, 同时存储 操作数 和 中间运算结果. | |
static String transform(String exp) { | |
Stack<String> ops = new Stack<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
/// for 1.3.10 中缀 转 后缀. 和 1.3.9 类似的思路 | |
public class InfixToPostfix { | |
/// 自动补全 左括号 . 反向推导表达式的原始形式. | |
/// 核心思路, 也即: 双栈表达式的精髓在于: 使用同一个栈, 同时存储 操作数 和 中间运算结果. | |
static String transform(String exp) { | |
Stack<String> ops = new Stack<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
// for 1.3.9 | |
public class AutoCompleteParentheses { | |
/// from 1.3.1.7 Dijkstra 的双栈表达式求值算法 | |
static double evaluate(String exp) { | |
Stack<String> ops = new Stack<>(); | |
Stack<Double> vals = new Stack<>(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
// for 1.3.5 | |
public class StackPrintCase { | |
public static void printCase(Integer N, int base) { | |
Stack<Integer> stack = new Stack<>(); | |
while (N > 0) { | |
stack.push(N % base); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package life.yanfeng.study.algorithm; | |
import edu.princeton.cs.algs4.StdOut; | |
// for 1.3.4 | |
public class Parentheses<Item> { | |
private Bracket<Item>[] brackets; | |
Parentheses(Bracket<Item>[] brackets) { | |
this.brackets = brackets; |
NewerOlder