leetcode - 6. ZigZag Conversion with Java

题目地址 这道题涉及到String, StringBuffer, StringBuilder的知识点 String在拼接时需要new新的String对象, 而它除了hash之外都是final属性, 分配空间会造成时间损耗. 所以String不适合大量拼接. 使用String可是耗时18ms呢 StringBuffer解决了这个问题, 它提升了速度, 是线程安全. 而StringBuilder 和StringBuffer类似, 但它是线程不安全, 这也使得它比StringBuffer拼接更快. 本题只需3ms 有没有更快的呢, 当然有, 还就是它了 char[], 只需2ms(笑) import java.lang.reflect.Method; import java.util.*; class Solution { public String convert(String s, int numRows) { int N = s.length(); // StringBuilder res = new StringBuilder(); char res[] = new char[N]; int cycle = (numRows-1)*2; int index = 0; if(numRows==1){ return s; } for(int row=0;row<numRows;row++){ /* row 0 6 1 4 2 2 2 4 3 0 */ for(int i=row;i<N;i+=cycle){ /* 一个锯齿*/ // res....

SuCicada

leetcode - 7. Reverse Integer with Java

where is problem 搞笑的空间复杂度 使用long,最后进行比较会更小,不知道为什么 class Solution { public int reverse(int x) { boolean minus = x<0; x *= minus?-1:1; int res = 0; while(x>0){ if(res*10/10 != res){ return 0; } res = res*10 + x%10; x = x/10; } return res * (minus?-1:1); } }

SuCicada

leetcode - 8. String to Integer (atoi) with Java

题目 class Solution { public int myAtoi(String str) { int N = str.length(); int minus = 0; long res = 0; for(int i=0;i<N;i++){ char ch = str.charAt(i); System.out.println(ch+" "+minus); if((ch == '-' || ch == '+') && minus == 0){ minus = ch=='+'?1:-1; }else if(ch ==' ' && minus==0){ }else if(ch <='9' && ch>='0'){ if(minus == 0){ minus = 1; } res = res*10 + ch-'0'; if(res != (int)res){ return minus==1?...

SuCicada

leetcode - 9. Palindrome Number with Java

题目 class Solution { public boolean isPalindrome(int x) { if(x<0){ return false; } int a = 0; int b = x; while(x>0){ a = a * 10 + x%10; x = x/10; } return a==b; } }

SuCicada

linux 通过 openconnect 来连接学校内网

参考 http://xingda1989.iteye.com/blog/1969908 https://blog.csdn.net/edin_blackpoint/article/details/70860101 sudo apt install openconnect 在/etc/vpc/目录下新建vpnc-script 文件 文件内容可以到此处拷贝 http://git.infradead.org/users/dwmw2/vpnc-scripts.git/blob_plain/HEAD:/vpnc-script sudo openconnect --juniper -u [你的学号] --script /etc/vpnc/vpnc-script [你学校的提供的vpn的url]

SuCicada

Linux Mint 使用 VNC Server (x11vnc) 进行远程屏幕

https://community.linuxmint.com/tutorial/view/2334 This tutorial was adapted from here. Remove the default Vino server: sudo apt-get -y remove vino Install x11vnc: sudo apt-get -y install x11vnc Create the directory for the password file: sudo mkdir /etc/x11vnc Create the encrypted password file: sudo x11vnc --storepasswd /etc/x11vnc/vncpwd You will be asked to enter and verify the password. Then press Y to save the password file. Create the systemd service file for the x11vnc service: sudo xed /lib/systemd/system/x11vnc....

SuCicada

linux mint系统 cinnamon桌面 发大镜功能

让我来告诉迷途中的你cinnamon桌面一个好用的功能. 选择设置 选择窗口 -> 选择行为 看那个窗口移动和调整大小的特殊键 Alt 好了按住alt在滑动滑轮 世界不一样了 对于小屏幕高分辨率电脑极为友好

SuCicada

linux remmina 使用rdp协议连接windows显示Failed to startup SSH session:connection refused解决

https://cn.aliyun.com/jiaocheng/165641.html 删除~/.freerdp/known_hosts 但是我找不见这个文件 尝试删除~/.remmina/remmina.pref 文件 成功

SuCicada

linux 下安装 Cisco Packet Tracer 7.11以及一些注意(辛酸史)

https://blog.csdn.net/qq_35882901/article/details/77652571 https://linux.cn/article-5576-1.html 开启登录问题 https://blog.csdn.net/u012321131/article/details/78587383 到软件的根目录下 执行以下脚本 sudo ./set_ptenv.sh sudo ./set_qtenv.sh **一定按步骤走 ** 安装在默认的/opt/pt 如果因为安装在家目录而导致闪退 就重新安装在默认路径下 一些依赖库 sudo apt install libqt5scripttools5 sudo apt-get install libqt5multimedia5-plugins 2018/9/18 因为3560的三层交换机的端口信息不显示,忍不了linux的bug,下了6版本的linux版本. 安装失败, 换回7版本,(核心已转储)…..made? 一个晚上的尝试,发现只是在当前的这个用户下运行不了,…..放弃了, 那么用wine吧 满心欢喜的安装好了,然后打算慢慢的把7版本的实验在6版本上重打一遍, 但是,cpu占用28,温度81…….耗不起 那么赞颂我们伟大的虚拟机吧 virtualbox的无缝模式太强大了,wine什么的掰掰吧,

SuCicada

linux 下的torrent下载器qBitTorrent

BT下载利器–Qbittorrent完全攻 Ubuntu使用命令安装qBittorrent的方法 源码下载

SuCicada

mysql workbench闪退解决办法

感谢google,感谢csdn linux下: rm -rf .mysql/workbench/ windows下: 删除C:\Users\Administrator\AppData\Roaming\MySQL\Workbench 这个问题没有社区的帮助,我就真的没辙了

SuCicada

mysql数据库连接以及执行的java类

应该使用json等配置文件来保存要连接的数据库信息,密码等. 先存一下,以后再说 DB_connection.java /* * To change this license header, choose License Headers in Project Properties. * To change this template file, choose Tools | Templates * and open the template in the editor. */ package com; import java.sql.Connection; import java.sql.DriverManager; import java.sql.ResultSet; import java.sql.SQLException; import java.sql.Statement; /** * * @author peng */ public class DB_connection { // JDBC 驱动名及数据库 URL String JDBC_DRIVER = "com.mysql.jdbc.Driver"; String DB_URL = "jdbc:mysql://localhost:3306/javabbs?useUnicode=true&characterEncoding=UTF-8"; // 数据库的用户名与密码,需要根据自己的设置 String USER = "root"; String PASS = "mysql"; Connection conn = null; // private static DB_connection dB_connection =null; // public static DB_connection getInstance(){ // if(DB_connection == null){ // DB_connection = new DB_connection; // } // return DB_connection; // } public Connection connect(){ try{ Class....

SuCicada

NYOJ-1204 魔法少女

http://nyoj.top/problem/1204 #include<iostream> using namespace std; int h[10006]; int d[10006][2]; // 每一 //int fun(int a,int b){ // if(a<0) // return 0; // if(b==0){ // if(d[a-1][0]<d[a-1][1]){ // cout<<d[a-1][0]<<" "<<a-1<<" "<<0<<endl; // fun(a-1,0); // }else{ // cout<<d[a-1][1]<<" "<<a-1<<" "<<1<<endl; // fun(a-1,1); // } // }else{ // if(d[a-1][0] < d[a-2][0]){ // cout<<d[a-1][0]<<" "<<a-1<<" "<<0<<endl; // fun(a-1,0); // }else{ // cout<<d[a-2][0]<<" "<<a-2<<" "<<0<<endl; // fun(a-2,0); // } // } //} int main(){ int n; while(cin>>n){ for(int i=0;i<n;i++){ cin>>h[i]; } // 0 not // 1 do d[0][0] = h[0]; d[0][1] = 0; d[1][0] = h[1]; d[1][1] = 0; for(int i=2;i<n;i++){ d[i][0] = min(d[i-1][1], d[i-1][0]) + h[i]; d[i][1] = min(d[i-1][0], d[i-2][0]); // 这一层飞了的时间数,和上一层没有飞,以及上上一层没有飞花费的时间数是一样的 } // for(int j=0;j<2;j++){ // for(int i=0;i<n;i++){ // cout<< d[i][j]<<" "; // } // cout<<endl; // } // // if((d[n-1][0]<d[n-1][1])){ // cout<<d[n-1][0]<<" "<<n-1<<" "<<0<<endl; // fun(n-1,0); // }else{ // cout<<d[n-1][1]<<" "<<n-1<<" "<<1<<endl; // fun(n-1,1); // } cout<< min(d[n-1][0],d[n-1][1]) <<endl; } } 伟大的动态规划,我真是愚蠢

SuCicada

Phaser 引擎 中TiledMap 的 json地图配置文件的格式

官方推荐Tiled 地图编辑器, https://www.mapeditor.org/ 所以查看地图格式直接看Tiled 的官方帮助文档 http://doc.mapeditor.org/en/stable/reference/json-map-format/

SuCicada

phaser 按键表 keyboard keycode

https://photonstorm.github.io/phaser-ce/Phaser.KeyCode.html 帮助文档里都有,但就是没人说

SuCicada

PhaserCE 使用 create.texture 出错 Phaser.Cache.addImage: Image "xx" is not complete 并且图形没有显示

首先参看官网文档的写法 https://photonstorm.github.io/phaser-ce/Phaser.Create.html#texture var game = new Phaser.Game(800, 600, Phaser.CANVAS, 'game', { preload: preload, create: create, }); function preload(){ var data = [ ' 333 ', ' 777 ', 'E333E', ' 333 ', ' 3 3 ']; game.create.texture('bob', data); } function create() { game.add.sprite(0, 0, 'bob'); } 控制台警告 Phaser.Cache.addImage: Image "xx" is not complete 改为 ...... game.create.texture('bob', data,100,10,0,true,function(f){}); ...... 警告 Phaser.Cache.getImage: Key "xx" not found in Cache. 查找资料无果,实验之后发现 使用 game.load.imageFromTexture('bob',data,100,1); 替换...

SuCicada

pyhton 下 使用getch(), 输入字符无需回车

#原代码来自 https://code.activestate.com/recipes/134892-getch-like-unbuffered-character-reading-from-stdin/ 同时支持windows和unix平台 class _Getch: """Gets a single character from standard input. Does not echo to the screen.""" def __init__(self): try: self.impl = _GetchWindows() except ImportError: self.impl = _GetchUnix() def __call__(self): return self.impl() class _GetchUnix: def __init__(self): import tty, sys def __call__(self): import sys, tty, termios fd = sys.stdin.fileno() old_settings = termios.tcgetattr(fd) try: tty.setraw(sys.stdin.fileno()) ch = sys.stdin.read(1) finally: termios.tcsetattr(fd, termios.TCSADRAIN, old_settings) return ch class _GetchWindows: def __init__(self): import msvcrt def __call__(self): import msvcrt return msvcrt....

SuCicada

python matplotlibmat 包mplot3d工具 三维视图透视取消

https://stackoverflow.com/questions/23840756/how-to-disable-perspective-in-mplot3d 简单的解决方法是 ax = fig.add_subplot(111, projection='3d', proj_type='ortho') 注意111 和 proj_type=‘ortho’ 辛亏在打算转用Mayavi 前找到了解决方法

SuCicada

python pip安装不成功 在windows下

我用的是windows。你可以试试以管理员模式运行终端。 我在用python安装第三方库时,使用如下方式 pip install xxxx.whl 但是无论如何都只显示到 Installing collected packages: xxxx 然后就没了,和网上说的出来什么success提示完全不,然后我通过import来验证,也是没有安装上的。 一定要出现 Successful installed xxxx 才算成功。 如果你的问题不是这样的,请查查看别的家的博客。 花了一个晚上都没有安上pygame。 于是第二天在整整一个下午琢磨了两个小时为什么。重启电脑,将python卸载再安装,卸载再安装,卸载再安装。删除easy_install 重装ez。删除pip,重装pip。重装wheel,但是如上面那样也失败了。然后我终于发现问题所在了。 我把powershell当成了是默认的管理员模式,于是我就一直处于安装不成功的地步。 所以说,如果你也安装不上,试试管理员模式运行终端。 真的是气,那些三步安装库的人根本不说。

SuCicada

python Tkinter 的 Text 保持焦点在行尾

https://bbs.csdn.net/topics/390712532 text.see(END)

SuCicada