Leetcode
one 大白(●—●)
你一定能够成为你想成为的人
展开
-
【每日一题】leetcode 二叉树层序遍历 - 介绍
层序遍历遍历顺序为:F B G A D I C E H一层一层遍历代码import java.util.ArrayList;import java.util.LinkedList;import java.util.List;import java.util.Queue;// 层次遍历class Solution { public List<List<Integer>> levelOrder(TreeNode root) {原创 2021-11-26 19:01:11 · 402 阅读 · 0 评论 -
【每日一题】Leetcode 刷题 二叉树-树的遍历 介绍
二叉树-树的遍历前序遍历 (根 左 右)中序遍历 (左 根 右)后序遍历 (左 右 根)代码实现前序遍历中序遍历后序遍历前序遍历 (根 左 右)遍历顺序分别为: F B A D C E G I H中序遍历 (左 根 右)中序遍历顺序分别为:A B C D E F G H I后序遍历 (左 右 根)后序遍历顺序分别为:A C E D B H I G F代码实现原创 2021-11-25 19:17:13 · 345 阅读 · 0 评论 -
剑指 Offer 06. 从尾到头打印链表-力扣
题目要求力扣题解代码#include <vector>#include <iostream>using namespace std;struct ListNode { int val; ListNode *next; ListNode(int x) : val(x), next(NULL) {}};class Solution1{public: Solution1(); ~Solution1(); vector<int&g.原创 2021-03-18 16:53:47 · 84 阅读 · 0 评论 -
力扣-图解算法数据结构-剑指 Offer 05. 替换空格
题目要求力扣题解代码/** * @program: mydemo * @description: 剑指 Offer 05. 替换空格 * @author: Mr.zeng * @create: 2021-03-05 11:04 **/public class Solution1 { public String replaceSpace(String s) { if(s==null||"".equals(s)){ return "".原创 2021-03-05 11:50:50 · 128 阅读 · 2 评论 -
力扣-图解算法数据结构
常见的数据结构可分为「线性数据结构」与「非线性数据结构」,具体为:「数组」、「链表」、「栈」、「队列」、「树」、「图」、「散列表」、「堆」。数组数组是将相同类型的元素存储于连续内存空间的数据结构,其长度不可变。如下图所示,构建此数组需要在初始化时给定长度,并对数组每个索引元素赋值,代码如下:public static void array() { // 初始化一个长度为5的数组 array int[] array=new int[5]; //元素赋值转载 2021-03-04 13:48:26 · 1040 阅读 · 2 评论 -
每天Leetcode 刷题 初级算法篇-缺失数字
题目要求:缺失数字力扣题解:代码import java.util.Arrays;/** * @program: mydemo * @description: 缺失数字 * @author: Mr.zeng * @create: 2021-03-03 09:49 **/public class Solution41 { public int missingNumber(int[] nums) { Arrays.sort(nums); .原创 2021-03-03 10:05:45 · 198 阅读 · 1 评论 -
每天Leetcode 刷题 初级算法篇-有效的括号
题目要求:力扣题解:代码import java.util.Deque;import java.util.HashMap;import java.util.LinkedList;import java.util.Map;/** * @program: mydemo * @description: 有效的括号 * @author: Mr.zeng * @create: 2021-03-02 09:49 **/public class Solution40 { .原创 2021-03-02 10:10:01 · 113 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-杨辉三角
题目要求:力扣题解:代码import java.util.ArrayList;import java.util.List;/** * @program: mydemo * @description: this is a class * @author: Mr.zeng * @create: 2021-03-01 10:09 **/public class Solution39 { public List<List<Integer>> g.原创 2021-03-01 10:23:40 · 90 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-颠倒二进制位
题目要求:力扣题解:代码/** * @program: test * @description: * @author: Long Ao Tian * @create: 2021-02-27 15:15 **/public class Solution38 { // you need treat n as an unsigned value public int reverseBits(int n) { int result=0; .原创 2021-02-27 15:22:37 · 108 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-汉明距离
题目要求:力扣题解:循环和位移动代码/** * @program: mydemo * @description: 汉明距离 * @author: Mr.zeng * @create: 2021-02-26 09:50 **/public class Solution37 { public int hammingDistance(int x, int y) { return Integer.bitCount(x ^ y); .原创 2021-02-26 09:56:08 · 66 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-位1的个数
题目要求:力扣题解:循环和位移动代码/** * @program: mydemo * @description: 位1的个数 * @author: Mr.zeng * @create: 2021-02-25 09:44 **/public class Solution36 { // you need to treat n as an unsigned value public int hammingWeight(int n) { int bi.原创 2021-02-25 09:52:57 · 249 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-数学问题-罗马数字转整数
题目要求:力扣题解:代码/** * @program: mydemo * @description: 罗马数字转整数 * @author: Mr.zeng * @create: 2021-02-24 09:37 **/public class Solution35 { public int romanToInt(String s){ int sum=0; int preNum=getValue(s.charAt(0)); .原创 2021-02-24 09:46:56 · 85 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-数学问题-3的幂
题目要求:力扣题解:循环迭代代码/** * @program: mydemo * @description: 判断一个数是不是3的幂 * @author: Mr.zeng * @create: 2021-02-23 09:45 **/public class Solution34 { public boolean isPowerOfThree(int n) { if (n < 1) { return false; .原创 2021-02-23 10:05:31 · 83 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-数学问题-计数质数
题目要求:力扣题解:代码import java.util.Arrays;/** * @program: mydemo * @description: 力扣-数学-计数质数 * @author: Mr.zeng * @create: 2021-02-22 09:47 **/public class Solution33 { public int countPrimes(int n){ int[] isPrime=new int[n]; .原创 2021-02-22 10:50:27 · 100 阅读 · 0 评论 -
每天Leetcode 刷题 初级算法篇-数学问题-Fizz Buzz
题目要求:力扣题解:代码/** * @program: mydemo * @description: 数学-Fizz Buzz * @author: Mr.zeng * @create: 2021-02-20 12:03 **/public class Solution32 { public List<String> fizzBuzz(int n){ List<String> ans=new ArrayList<>.原创 2021-02-20 12:16:10 · 95 阅读 · 0 评论