leetCode in Java (一)】的更多相关文章

leetcode的java代码提供的main函数中,往往有关于json的依赖...我找了许久才找到他们用的是这个json实现 <dependency> <groupId>com.eclipsesource.minimal-json</groupId> <artifactId>minimal-json</artifactId> <version>0.9.5</version> </dependency>…
二叉树的非递归前序遍历,大抵是很多人信手拈来.不屑一顾的题目罢.然而因为本人记性不好.基础太差的缘故,做这道题的时候居然自己琢磨出了一种解法,虽然谈不上创新,但简单一搜也未发现雷同,权且记录,希望于人于己皆有帮助. 估计能看到这里的读者,都是见过题目的,但还是链接原题在此:Binary Tree Preorder Traversal 二话不说,直接上代码: /** * Definition for binary tree * public class TreeNode { * int val;…
前言    感觉写博客是一个很耗心力的东西T_T,简单的写了似乎没什么用,复杂的三言两语也只能讲个大概,呸呸...怎么能有这些消极思想呢QAQ!那想来想去,先开一个leetcode的坑,虽然已经工作了,但是每天拿一两道题打发打发也不错嘛,不仅能锻炼思维,还能复习一些算法思想,又不怎么耗费时间撰写...还能骗博客数...,额好像又说了啥内心的真实想法:)... Go 两数相加 Two Sum Given an array of integers, return indices of the two…
今天发现LintCode页面刷新不出来了,所以就转战LeetCode.还是像以前一样,做题顺序:难度从低到高,每天至少一题. Given a pattern and a string str, find if str follows the same pattern. Here follow means a full match, such that there is a bijection between a letter in pattern and a non-empty word in …
题目: Given two numbers represented as strings, return multiplication of the numbers as a string. Note: The numbers can be arbitrarily large and are non-negative. 给两个用字符串表示的数字,求它们的乘积. 注意:数字非负,且可以无限大 ———————————————————————— 之前未考虑数字可以无限大的情况,采用的方法是 将字符串转…
public class TreeNode { int val; TreeNode left; TreeNode right; TreeNode(int x) { val = x; } } import java.util.LinkedList; import java.util.Queue; public class Wrapper { public static String treeNodeToString(TreeNode root) { if (root == null) { retu…
什么是 Interface Java接口(Interface)是一系列方法的声明,是一些方法特征的集合,一个接口只有方法的特征没有方法的实现,因此这些方法可以在不同的地方被不同的类实现,而这些实现可以具有不同的行为.打一个比方,接口好比一个戏中的角色,这个角色有一些特定的属性和操作,然后实现接口的类就好比扮演这个角色的人,一个角色可以由不同的人来扮演,而不同的演员之间除了扮演一个共同的角色之外,并不要求其它的共同之处. 有哪些面试常用的 Interface Set 注重独一无二,该体系集合可以知…
86 class Solution { public ListNode partition(ListNode head, int x) { ListNode lowheader=new ListNode(0); ListNode low=lowheader; ListNode highheader=new ListNode(0); ListNode high=highheader; while(head!=null){ if(head.val<x){ low.next=head; head=he…
Given a binary search tree (BST) with duplicates, find all the mode(s) (the most frequently occurred element) in the given BST. Assume a BST is defined as follows: The left subtree of a node contains only nodes with keys less than or equal to the nod…
Given a 32-bit signed integer, reverse digits of an integer. Example 1: Input: 123 Output: 321 Example 2: Input: -123 Output: -321 Example 3: Input: 120 Output: 21 Note:Assume we are dealing with an environment which could only store integers within…
题目: Given a linked list, return the node where the cycle begins. If there is no cycle, return null. Follow up: Can you solve it without using extra space? 题解: 这个连同I都是很经典的题啦,刷CC150时候就折磨了半天. 其实就推几个递推公式就好..首先看图(图引用自CC150): 从链表起始处到环入口长度为:a,从环入口到Faster和Sl…
Design and implement a data structure for Least Recently Used (LRU) cache. It should support the following operations: get and set. get(key) - Get the value (will always be positive) of the key if the key exists in the cache, otherwise return -1. set…
   一.问题描述 Evaluate the value of an arithmetic expression in Reverse Polish Notation. Valid operators are +, -, *, /. Each operand may be an integer or another expression. Some examples: ["2", "1", "+", "3", "*&…
Given a string S and a string T, count the number of distinct subsequences of T in S. A subsequence of a string is a new string which is formed from the original string by deleting some (can be none) of the characters without disturbing the relative…
For example, Given height = [2,1,5,6,2,3], return 10. 解题思路: 参考Problem H: Largest Rectangle in a Histogram第四种思路,或者翻译版Largest Rectangle in Histogram@LeetCode,JAVA实现如下: public int largestRectangleArea(int[] height) { Stack<Integer> stk = new Stack<I…
Given a string s and a dictionary of words dict, add spaces in s to construct a sentence where each word is a valid dictionary word. Return all such possible sentences. For example, givens = "catsanddog",dict = ["cat", "cats"…
题目一: Longest Substring Without Repeating Characters Given a string, find the length of the longest substring without repeating characters. For example, the longest substring without repeating letters for "abcabcbb" is "abc", which the…
Follow up for N-Queens problem. Now, instead outputting board configurations, return the total number of distinct solutions. 原题链接:https://oj.leetcode.com/problems/n-queens-ii/ 题目:求有多少个独立的解决方式. 与上题一致,仅仅要每次成功后记录一下次数就可以. package leetcode; import java.ut…
本文描述了LeetCode 148题 sort-list 的解法. 题目描述如下: Sort a linked list in O(n log n) time using constant space complexity. 题目要求我们在O(n log n)时间复杂度下完成对单链表的排序,我们知道平均时间复杂度为O(n log n)的排序方法有快速排序.归并排序和堆排序.而一般是用数组来实现二叉堆,当然可以用二叉树来实现,但是这么做太麻烦,还得花费额外的空间构建二叉树,于是不采用堆排序. 故本…
实 验 报 告 ( 2017 / 2018学年 第2学期) 课程名称 JAVA语言程序设计 实验名称 Java集成开发环境的安装与使用. Java变量.表达式与控制结构 实验时间 2018 年 4 月 11 日 指导单位 计算机学院软件教学中心 指导教师 许棣华 学生姓名 王利国 班级学号 B160209 学院(系) 电子与光学工程学院,微电子学院 专    业 微电子科学与工程 实验名称 方法.数组和类 指导教师 许棣华 实验类型 上机 实验学时 2 实验时间 2017.4.11 三.实验内容…
这是悦乐书的第148次更新,第150篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第7题(顺位题号是21).合并两个已排序的链表并将其作为新链表返回. 新链表应该通过拼接前两个链表的节点来完成.例如: 链表L1包含三个节点,为1,2,4 链表L2包含三个节点,为1,3,4 将L1和L2合并后的新链表包含6个节点,为1,1,2,3,4,4 本次解题使用的开发工具是eclipse,jdk使用的版本是1.8,环境是win7 64位系统,使用Java语言编写和测试. 02…
I try to do a testing for HashTable Sychronized behavior today. As an Sychronized Object, HashTable already an Sychronized at put and get function. I wanna to know more about the iterator behaviors on multi-threading. package leetcode; import java.ut…
问题表示提供一个整数数组nums,以及一个目标target,要找到两个下标i与j,使得nums[i] + nums[j] = target. 最简单的思路是两次循环: for a in nums for b in nums if a + b = target then return [a.index, b.index] 这样的代码的时间复杂度是O(n^2),其中n表示nums的长度.当n为1e4时,执行时间高达?e8,其中?是一个有上界的数值. 可以利用排序和二分查找优化这一过程: sort(n…
title: 406-根据身高重建队列 date: 2019-04-15 21:13:06 categories: LeetCode tags: Java容器 比较器 贪心思想 题目描述 假设有打乱顺序的一群人站成一个队列. 每个人由一个整数对(h, k)表示,其中h是这个人的身高,k是排在这个人前面且身高大于或等于h的人数. 编写一个算法来重建这个队列. 注意: 总人数少于1100人. 示例 输入: [[7,0], [4,4], [7,1], [5,0], [6,1], [5,2]] 输出:…
JavaGuide([Java学习+面试指南] 一份涵盖大部分Java程序员所需要掌握的核心知识):https://github.com/Snailclimb/JavaGuide. 人生总有各种各样的巧合发生.在1年多前,换句话说就是我还是大三的一名学生的时候.我开源了 JavaGuide ,直接到今天 JavaGuide 已经达到现在 60.5 k+ Star ,目前在所有仓库中排名29位, 我觉得这也算是我眼中的一种巧合. JavaGuide 由来 大三上学期的时候,自己真正开始准备秋招面试…
题目描述: 有 n 个城市通过一些航班连接.给你一个数组 flights ,其中 flights[i] = [fromi, toi, pricei] ,表示该航班都从城市 fromi 开始,以价格 pricei 抵达 toi. 现在给定所有的城市和航班,以及出发城市 src 和目的地 dst,你的任务是找到出一条最多经过 k 站中转的路线,使得从 src 到 dst 的 价格最便宜 ,并返回该价格. 如果不存在这样的路线,则输出 -1. 来源:力扣(LeetCode)链接:https://lee…
Given an integer array of size n, find all elements that appear more than ⌊ n/3 ⌋ times. The algorithm should run in linear time and in O(1) space. 方法很笨,其实时间复杂度差不多是O(n²). package leetcode; import java.util.ArrayList; import java.util.HashSet; import…
https://wiki.mozilla.org/Fingerprinting Fingerprinting   Contents 1 Overview 2 Data 2.1 Plugins 2.2 Fonts 2.3 User Agent 2.4 HTTP ACCEPT 2.5 Screen resolution 2.6 Timezone 2.7 Supercookies 2.8 Cookies enabled 3 Extra credit 3.1 Other data acquired vi…
正在学习这篇文章: http://blog.csdn.net/ymh198816/article/details/51998085 和工作中接触的电商.订单.分析,可以结合起来. 开宗明义,这幅图片: Strom是一个非常快的实时计算框架,至于快到什么程度呢? 官网首页给出的数据是每一个Storm集群上的节点每一秒能处理一百万条数据.相比Hadoop的"Mapreduce"计算框架,Storm使用的是"Topology":Mapreduce程序在计算完成后最终会停下…
aaarticlea/png;base64,iVBORw0KGgoAAAANSUhEUgAAA+4AAAC5CAIAAAA55fI7AAAZa0lEQVR4nO3dPW7bQIMG4L2MT6B7+A…