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 ...
随机推荐
- hihoCoder week6 01背包
01背包 题目链接 https://hihocoder.com/contest/hiho6/problem/1 #include <bits/stdc++.h> using namespa ...
- JavaI/O(输入/输出)
File类 通过File类可以在程序中操作文件和目录,File能新建.删除.重命名文件和目录,但是不能访问文件内容本身. 理解I/O流 流(stream)是从起源(source)到接收(sink)的有 ...
- (zhuan) How to Train Neural Networks With Backpropagation
this blog from: http://blog.demofox.org/2017/03/09/how-to-train-neural-networks-with-backpropagation ...
- [HDU 1215] 七夕节(求因子,不超时)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1215 //注意怎么处理不超时 #include<iostream> #include< ...
- Kubernetes工作流之Pods一
This page provides an overview of Pod, the smallest deployable object in the Kubernetes object model ...
- pyqt笔记1模块 信号和插槽
资料 PyQt5图形界面编程 PyQt5指南 模块 PyQt5本身拥有超过620个类和6000函数及方法. QtCore模块涵盖了包的核心的非GUI功能,此模块被用于处理程序中涉及到的 time.文件 ...
- HDU 1512 Monkey King(左偏树模板题)
http://acm.hdu.edu.cn/showproblem.php?pid=1512 题意: 有n只猴子,每只猴子一开始有个力量值,并且互相不认识,现有每次有两只猴子要决斗,如果认识,就不打了 ...
- SPOJ 839 Optimal Marks(最小割的应用)
https://vjudge.net/problem/SPOJ-OPTM 题意: 给出一个无向图G,每个点 v 以一个有界非负整数 lv 作为标号,每条边e=(u,v)的权w定义为该边的两个端点的标号 ...
- Codeforces Round #135 (Div. 2) D. Choosing Capital for Treeland dfs
D. Choosing Capital for Treeland time limit per test 3 seconds memory limit per test 256 megabytes i ...
- [原][粒子特效][spark]调节器modifier
深入浅出spark粒子特效连接:https://www.cnblogs.com/lyggqm/p/9956344.html group添加modifier的方式: modifier An abstra ...