LeetCode
lesliefish
不要停歇、不回头
展开
-
力扣 21. 合并两个有序链表 JavaScript
代码如下//Definition for singly-linked list.function ListNode(val, next) { this.val = (val === undefined ? 0 : val) this.next = (next === undefined ? null : next)}/** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNode} */var原创 2021-03-12 22:22:20 · 455 阅读 · 0 评论 -
力扣 14.最长公共前缀 JavaScript
代码如下/** * @param {string[]} strs * @return {string} */var longestCommonPrefix = function (strs) { console.log(strs); if (strs.length === 0) { return ''; } let commonStr = "" let curPos = 0; while (true) { let th原创 2021-03-11 23:20:42 · 326 阅读 · 0 评论 -
力扣 9.回文数 JavaScript
解答/** * 方法1 翻转字符串看是否相等 * @param {number} x * @return {boolean} */var isPalindrome = function (x) { let xStr = x + ''; let revStr = xStr.split('').reverse().join(''); return xStr === revStr;};// 方法2 通过字符串前后一一对比判断var isPalindrome2 = fun原创 2021-03-11 17:33:14 · 349 阅读 · 0 评论 -
力扣 3. 无重复字符的最长子串 JavaScript
代码如下/** * @param {string} s * @return {number} */var lengthOfLongestSubstring = function (s) { let maxLongStr = ''; for (let index = 0; index < s.length; index++) { let subStr = s.substr(index, s.length); let tempSubStr = ge原创 2021-03-10 22:14:41 · 361 阅读 · 0 评论 -
力扣 2. 两数相加 JavaScript
// 结点定义function ListNode(val, next) { this.val = (val === undefined ? 0 : val) this.next = (next === undefined ? null : next)}/** * @param {ListNode} l1 * @param {ListNode} l2 * @return {ListNode} */var addTwoNumbers = function (l1, l2) {原创 2021-03-10 12:54:59 · 567 阅读 · 0 评论 -
力扣 1.两数之和 javascript
两数之和给定一个整数数组 nums 和一个整数目标值 target,请你在该数组中找出 和为目标值 的那 两个 整数,并返回它们的数组下标。你可以假设每种输入只会对应一个答案。但是,数组中同一个元素不能使用两遍。你可以按任意顺序返回答案。题解:/** * @param {number[]} nums * @param {number} target * @return {number[]} */var twoSum = function (nums, target) { let原创 2021-03-08 22:02:58 · 404 阅读 · 0 评论 -
[LeetCode] 两数相加
英文描述You are given two non-empty linked lists representing two non-negative integers. The digits are stored in reverse order and each of their nodes contain a single digit. Add the two numbers and re...原创 2018-03-29 09:59:58 · 322 阅读 · 0 评论 -
[LeetCode] 两数之和
英文描述Given an array of integers, return indices of the two numbers such that they add up to a specific target. You may assume that each input would have exactly one solution, and you may not use the...原创 2018-03-29 22:28:30 · 670 阅读 · 1 评论 -
[LeetCode] 无重复字符的最长子串
无重复字符的最长子串英文描述Given a string, find the length of the longest substring without repeating characters.Examples: Given “abcabcbb”, the answer is “abc”, which the length is 3. Given “bbbbb”, the...原创 2018-04-03 00:18:45 · 1072 阅读 · 0 评论 -
[LeetCode] 颠倒整数
颠倒整数英文描述Given a 32-bit signed integer, reverse digits of an integer.Example 1: Input: 123 Output: 321Example 2: Input: -123 Output: -321Example 3: Input: 120 Output: 21Note: ...原创 2018-04-03 22:57:46 · 356 阅读 · 0 评论 -
[LeetCode] 回文数
判断回文数英文描述Determine whether an integer is a palindrome. Do this without extra space.Some hints: Could negative integers be palindromes? (ie, -1)If you are thinking of converting the intege...原创 2018-04-05 22:33:44 · 576 阅读 · 1 评论