Leetcode笔记(整理中.......)
1、树的层序遍历
使用两个List 数组 或者 两个queue队列,交替进行,将遍历到的一层放在第一个里面,之后再将遍历到的第二层放在第二个里面。
2、将一个无符号整数的二进制表示形式逆向输出
需要将int n(每次向右移一位)的每一位从右向左与1相与(int 1每次向左移动一位),存储结果每次向左移动一位(若 n的当前位为1,则将answer与1相或),直到n的每一位都被遍历到。
3、求一个无符号整数的二进制表示中,1的个数
可以利用2中的方法,每次将整数n的当前位与1相与,若结果为1,则count+1,直到n的所有位都被遍历到为止。
java中移位运算符就是在二进制的基础上对数字进行平移。按照平移的方向和填充数字的规则分为三种:<<(左移)、>>(带符号右移)和>>>(无符号右移)。
4、对于一个整型数组 int[] nums,求其所有数字连接成为一个整数字符串后,得到的字符串结果的最大值
利用java中自带的 Arrays.sort() 方法,对字符串数组进行排序(将整型数组转换为字符串数组),由于这种排序不是简单的比较大小,而是比较出两个字符串连接后的排序结果使得两者的连接字符串最大。因此,需要改写 compare方法, Comparator<String> comp=new Comparator<String>(){重写compare方法}; 最后将排序得到的字符串数组从高位到低位进行连接后输出。
5、List<T> list=new ArrayList<T>(); Queue<T> queue=new LinkedList<T>(); 在java中,List和Queue都是容器
Leetcode笔记(整理中.......)的更多相关文章
- log4j 使用笔记整理中
Log4j由三个重要的组件构成:日志信息的优先级,日志信息的输出目的地,日志信息的输出格式. 日志信息的常用的优先级从高到低有ERROR.WARN. INFO.DEBUG,分别用来指定这条日志信息的重 ...
- Leetcode 笔记 36 - Sudoku Solver
题目链接:Sudoku Solver | LeetCode OJ Write a program to solve a Sudoku puzzle by filling the empty cells ...
- Leetcode 笔记 35 - Valid Soduko
题目链接:Valid Sudoku | LeetCode OJ Determine if a Sudoku is valid, according to: Sudoku Puzzles - The R ...
- Linux学习历程(持续更新整理中)
1.文件目录操作命令 (1) ls 显示文件和目录列表 a ls -l 显示文件的详细信息 b ls -a 列出当前目录的所有文件,包含隐藏文件. c stat '目录/文件' 显示指定目录 ...
- Leetcode 笔记 113 - Path Sum II
题目链接:Path Sum II | LeetCode OJ Given a binary tree and a sum, find all root-to-leaf paths where each ...
- Leetcode 笔记 112 - Path Sum
题目链接:Path Sum | LeetCode OJ Given a binary tree and a sum, determine if the tree has a root-to-leaf ...
- Leetcode 笔记 110 - Balanced Binary Tree
题目链接:Balanced Binary Tree | LeetCode OJ Given a binary tree, determine if it is height-balanced. For ...
- Leetcode 笔记 100 - Same Tree
题目链接:Same Tree | LeetCode OJ Given two binary trees, write a function to check if they are equal or ...
- Leetcode 笔记 99 - Recover Binary Search Tree
题目链接:Recover Binary Search Tree | LeetCode OJ Two elements of a binary search tree (BST) are swapped ...
- Leetcode 笔记 98 - Validate Binary Search Tree
题目链接:Validate Binary Search Tree | LeetCode OJ Given a binary tree, determine if it is a valid binar ...
随机推荐
- 【Java----创建多级文件夹】
File类中的mkdir()和mkdirs(): mkdir():只能创建一层目录. mkdirs():可以创建多层目录 代码:path可以是带文件名称的全路径 //路径 String path = ...
- 比赛总结——atcoder beginner contest 109
第一次AK的ABC 虽然题非常简单 但是值得纪念一下 T1 一道很水的题 不存在做法 纯粹乱跑 但是我把Yes打成YES了,哭唧唧 #include <cstdio> #include & ...
- ES6数字操作
数字判断和转换 数字验证Number.isFinite( xx ) 可以使用Number.isFinite( )来进行数字验证,只要是数字,不论是浮点型还是整形都会返回true,其他时候会返回fals ...
- 配置httpd支持https
1.首先为192.168.108.159创建私有CA #cd /etc/pki/CA # (umask 077;openssl genrsa -out private/cakey.pem 2048) ...
- 51nod 1405 树的距离之和(dfs)
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1405 题意: 思路: 先求出所有点到根节点的距离,需要维护每棵子树的大小 ...
- web开发测试注意点
1.用户操作多页面情况 如果用session来获取当前页面情况时要特别注意,操作时出现另一个页面的情况,会出现传参数混乱 解决:后台可以获取并比对判断当前页面某些参数值
- PyEngine3D
git clone https://github.com/ubuntunux/PyEngine3D cd PyEngine3D pip install -r requirements.txt pyth ...
- System.arraycopy和arrays.copyOf
public static native void arraycopy(Object src, int srcPos, Object dest, int destPos, int length); 这 ...
- Springboot:没有src/main/resources目录(引入图片时(或静态资源时)发现没有该目录)
今天想在Springboot项目想引进静态资源时,发现自己的项目里没有教程里面的 src/main/resources这个目录,目录如下 我的项目目录结构是这样的,但是还不是很清楚下面的那个src目录 ...
- AD中设置PCB线间距
Design->Rules->Electrical->Clearance->Clearance