leetcode

LeetCode:Plus One

為{幸葍}努か 提交于 2020-03-01 21:07:19
1、题目名称 Plus One(数字加一) 2、题目地址 https://leetcode.com/problems/plus-one 3、题目内容 英文:Given a non-negative number represented as an array of digits, plus one to the number. The digits are stored such that the most significant digit is at the head of the list. 中文:给出一个由整型数组表示的非负数字,将这个数字加一。数组中的各元素表示该数字的各位,越靠前的元素权越大。 4、解题方法 本题的解题思路,就是模拟现实中做加法的方式,在个位加一,并考虑进位的情况。Java代码如下: /** * 功能说明:LeetCode 66 - Plus One * 开发人员:Tsybius2014 * 开发时间:2015年9月17日 */ public class Solution { /** * 数字加1 * @param digits 数字 * @return 数字加一后的值 */ public int[] plusOne(int[] digits) { //数字加一 boolean carryFlag = false; digits[digits

Beta 冲刺(5/7)

瘦欲@ 提交于 2020-03-01 18:18:23
目录 摘要 团队部分 个人部分 摘要 队名:小白吃 组长博客: hjj 作业博客: beta冲刺(5/7) 团队部分 后敬甲(组长) 过去两天完成了哪些任务 ppt制作中 数据集标注 接下来的计划 制作ppt 准备答辩 还剩下哪些任务 答辩准备 有哪些困难 考试增多,时间紧张 有哪些收获和疑问 收获:ppt制作+数据制作 疑问:没了 黄靖茹 过去两天完成了哪些任务 -数据周报相关内容的整合 接下来的计划 html js 数据是怎么传输的搞清楚 改前面的代码 还剩下哪些任务 猜你喜欢网页编写 有哪些困难 加各种各样的功能总会出现各种各样的问题 有哪些收获和疑问 收获:大把大把的头发 疑问:整合之前的代码为什么莫名其妙不能用了 葛亮 过去两天完成了哪些任务 我的界面优化 接下来的计划 完善学生端 还剩下哪些任务 商家端的完成 学生端界面美画 有哪些困难 按照原型抠细节 有哪些收获和疑问 收获:wxml和css升华 疑问:暂无 黄泽 过去两天完成了哪些任务 修改了商家端的部分界面样式 接下来的计划 完成商家端基本样式 完成菜品上传功能 还剩下哪些任务 商家端基本功能 有哪些困难 东西太多感觉做不完 后续制作需要更多的小程序技术,能力不足 有哪些收获和疑问 收获:编写js与wxml代码的技术越来越娴熟了 疑问:暂无 蔡文斌 过去两天完成了哪些任务 完善推荐算法,根据要求重新生成推荐

LeetCode | 1365. How Many Numbers Are Smaller Than the Current Number有多少小于当前数字的数字【Python】

断了今生、忘了曾经 提交于 2020-03-01 16:34:46
LeetCode 1365. How Many Numbers Are Smaller Than the Current Number有多少小于当前数字的数字【Easy】【Python】【暴力】 Problem LeetCode Given the array nums , for each nums[i] find out how many numbers in the array are smaller than it. That is, for each nums[i] you have to count the number of valid j's such that j != i and nums[j] < nums[i] . Return the answer in an array. Example 1: Input: nums = [8,1,2,2,3] Output: [4,0,1,1,3] Explanation: For nums[0]=8 there exist four smaller numbers than it (1, 2, 2 and 3). For nums[1]=1 does not exist any smaller number than it. For nums[2]=2 there exist one smaller number

[leetcode] Integer to Roman

喜夏-厌秋 提交于 2020-03-01 12:06:10
Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. https://oj.leetcode.com/problems/integer-to-roman/ 思路1:构造法,每一位构造然后拼接。每一位表示的字母虽然不同,但是规则是一样的,所以考虑每一位上0-9的表现形式,然后拼接起来。(详见参考1) 思路2:采用贪心策略,每次选择能表示的最大的值,把对应的字符串连接起来,代码及其简洁。 贪心: public class Solution { public String intToRoman(int num) { String[] str = new String[] { "M", "CM", "D", "CD", "C", "XC", "L", "XL", "X", "IX", "V", "IV", "I" }; int[] val = new int[] { 1000, 900, 500, 400, 100, 90, 50, 40, 10, 9, 5, 4, 1 }; StringBuilder sb = new StringBuilder(); for (int i = 0; num > 0; i++) { while

【LeetCode】 23. Merge k Sorted Lists 合并K个排序链表(Hard)(JAVA)

烈酒焚心 提交于 2020-03-01 11:35:33
【LeetCode】 23. Merge k Sorted Lists 合并K个排序链表(Hard)(JAVA) 题目地址: https://leetcode.com/problems/merge-k-sorted-lists/ 题目描述: Merge k sorted linked lists and return it as one sorted list. Analyze and describe its complexity. Example: Input: [ 1->4->5, 1->3->4, 2->6 ] Output: 1->1->2->3->4->4->5->6 题目大意 合并 k 个排序链表,返回合并后的排序链表。请分析和描述算法的复杂度。 解题方法 直接判断每一个链表的最小值 较耗时,直接可以想到 /** * Definition for singly-linked list. * public class ListNode { * int val; * ListNode next; * ListNode(int x) { val = x; } * } */ class Solution { public ListNode mergeKLists(ListNode[] lists) { ListNode res = new ListNode(0);

[leetcode] Roman to Integer

六月ゝ 毕业季﹏ 提交于 2020-03-01 10:39:23
Given a roman numeral, convert it to an integer. Input is guaranteed to be within the range from 1 to 3999. https://oj.leetcode.com/problems/roman-to-integer/ 思路1:从前向后遍历罗马数字,如果某个数比前一个数小,则加上该数。反之,减去前一个数的两倍然后加上该数。 public class Solution { public int romanToInt(String s) { char[] symbol = { 'I', 'V', 'X', 'L', 'C', 'D', 'M' }; int[] val = { 1, 5, 10, 50, 100, 500, 1000 }; Map<Character, Integer> map = new HashMap<Character, Integer>(); for (int i = 0; i < symbol.length; i++) map.put(symbol[i], val[i]); int len = s.length(); int res = 0; res += map.get(s.charAt(0)); for (int i = 1; i < len; i++) {

LeetCode:Integer to Roman

吃可爱长大的小学妹 提交于 2020-03-01 10:14:56
1、题目名称 Integer to Roman (阿拉伯数字到罗马数字的转换) 2、题目地址 https://leetcode.com/problems/integer-to-roman 3、题目内容 英文:Given an integer, convert it to a roman numeral. Input is guaranteed to be within the range from 1 to 3999. 中文:给出一个整数,将它转换成罗马数字。输入在1-3999之间。 4、题目分析 将阿拉伯数字转换为罗马数字,首先需要了解一下罗马数字的生成规则。罗马数字共有7个,即I(1)、V(5)、X(10)、L(50)、C(100)、D(500)和M(1000),它的生成规则较为复杂,具体可以参考维基百科条目:罗马数字( 中文 | 英文 )。虽然写罗马数字是件比较繁琐的事情,但将十进制数字转换为罗马数字,却有一个简单的规律,可以从下面这张表中看到: 可以看到,与十进制数字相比,虽然在个位、十位、百位、千位这些数位上罗马数字的写法各不相同,但却都有着共同规律。从纵向比较看,每一个数位的写法只和该数位对应的一倍、五倍、十倍对应的字母有关。如8的罗马数字是VIII(5+1+1+1),80是LXXX(50+10+10+10),800是DCCC(500+100+100+100)

Leetcode 165.比较版本号(Compare Version Numbers)

◇◆丶佛笑我妖孽 提交于 2020-03-01 10:09:56
Leetcode 165.比较版本号 1 题目描述( Leetcode题目链接 )   比较两个版本号 version1 和 version2。如果 version1 > version2 返回 1,如果 version1 < version2 返回 -1, 除此之外返回 0。 你可以假设版本字符串非空,并且只包含数字和 . 字符。 . 字符不代表小数点,而是用于分隔数字序列。例如,2.5 不是“两个半”,也不是“差一半到三”,而是第二版中的第五个小版本。 你可以假设版本号的每一级的默认修订版号为 0。例如,版本号 3.4 的第一级(大版本)和第二级(小版本)修订号分别为 3 和 4。其第三级和第四级修订号均为 0。 输入 : version1 = "0.1" , version2 = "1.1" 输出 : - 1 输入 : version1 = "1.0.1" , version2 = "1" 输出 : 1 输入 : version1 = "7.5.2.4" , version2 = "7.5.3" 输出 : - 1 输入:version1 = "1.01" , version2 = "1.001" 输出: 0 解释:忽略前导零,“ 01 ” 和 “ 001 ” 表示相同的数字 “ 1 ”。 提示: 版本字符串由以点 (.) 分隔的数字字符串组成。这个数字字符串可能有前导零。

【LeetCode】383 Ransom Note(java)

纵饮孤独 提交于 2020-03-01 04:06:34
原题 Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 all 
the 
magazines,
 write 
a 
function 
that 
will 
return 
true 
if 
the 
ransom 
 note 
can 
be 
constructed 
from 
the 
magazines ; 
otherwise, 
it 
will 
return 
false. 

 Each 
letter
 in
 the
 magazine 
string 
can
 only 
be
 used 
once
 in
 your 
ransom
 note. Note: You may assume that both strings contain only lowercase letters. canConstruct("a", "b") -> false canConstruct("aa", "ab") -> false canConstruct("aa", "aab") -> true 题目要求 题目叫做Ransom Note,勒索信,刚开始我还没理解这个题目的意思,尤其这个标题,和magazine有啥关系呢

表达式求值(from leetcode 241)

北战南征 提交于 2020-02-29 17:48:22
给定一个正确的表达式(不用担心不规范的输入),比如 2-1-1, 通过在不同位置添加左右括号,改变求值的优先级顺序,求出所有的这些值; Example 1 Input: "2-1-1" . ((2-1)-1) = 0 (2-(1-1)) = 2 Output: [0, 2] Example 2 Input: "2*3-4*5" (2*(3-(4*5))) = -34 ((2*3)-(4*5)) = -14 ((2*(3-4))*5) = -10 (2*((3-4)*5)) = -10 (((2*3)-4)*5) = 10 Output: [-34, -14, -10, -10, 10] 这个题目应该没有便捷的解法,只能全部的都尝试一遍;当然仅仅需要暴力的枚举一遍,也没有什么有趣的地方,我觉得有趣的地方体现在下面两点: 1. 这个题目可以用递归的方法求解,因为,假设遇到某个操作符,如果知道了左边的结果,再计算出右边的结果,那么只要把左右两边的结果合并起来,就可以了; 2. 当然如果直接按照递归去做,会出现一个问题,(大概会超时,我没有提交这样的代码);假设在得到了某个操作符两边的结果后,到了下一个操作符,递归计算的时候,任然会需要前面一个操作符(左边的)的结果,所以必须要把已经计算过的结果要cache起来; 最后的代码如下: private final static long