楼主: ttgao
跳转到指定楼层
上一主题 下一主题
收起左侧

立贴!从今天开始刷题。

🔗
 楼主| ttgao 2019-7-3 13:22:14 | 只看该作者
全局:
53. Maximum Subarray

Given an integer array nums, find the contiguous subarray (containing at least one number) which has the largest sum and return its sum.

Example:

Input: [-2,1,-3,4,-1,2,1,-5,4],
Output: 6
Explanation: [4,-1,2,1] has the largest sum = 6.
Follow up:

If you have figured out the O(n) solution, try coding another solution using the divide and conquer approach, which is more subtle.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-3 13:22:51 | 只看该作者
全局:
这是一道DP题目。

            if(i==0) {
                dp[i] = nums[i];
            }else{
                if(dp[i-1]>0){
                    dp[i] = dp[i-1]+nums[i];
                }else{
                    dp[i] = nums[i];
                }
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-3 13:29:11 | 只看该作者
全局:
7. Reverse Integer

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 the 32-bit signed integer range: [−231,  231 − 1]. For the purpose of this problem, assume that your function returns 0 when the reversed integer overflows.

回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-3 13:29:26 | 只看该作者
全局:
这题没啥说头,就是要小心越界。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-4 03:47:17 | 只看该作者
全局:
Palindrome Number
Category        Difficulty        Likes        Dislikes
algorithms        Easy (43.81%)        1487        1323
Tags
Companies
Determine whether an integer is a palindrome. An integer is a palindrome when it reads the same backward as forward.

Example 1:

Input: 121
Output: true
Example 2:

Input: -121
Output: false
Explanation: From left to right, it reads -121. From right to left, it becomes 121-. Therefore it is not a palindrome.
Example 3:

Input: 10
Output: false
Explanation: Reads 01 from right to left. Therefore it is not a palindrome.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-4 03:47:51 | 只看该作者
全局:
除十取余,没啥特别复杂的。
回复

使用道具 举报

🔗
drmn68 2019-7-4 03:57:53 | 只看该作者
全局:
late is better than never
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-4 05:46:32 | 只看该作者
全局:
Remove Duplicates from Sorted Array
Category        Difficulty        Likes        Dislikes
algorithms        Easy (41.06%)        1580        3394
Tags
Companies
Given a sorted array nums, remove the duplicates in-place such that each element appear only once and return the new length.

Do not allocate extra space for another array, you must do this by modifying the input array in-place with O(1) extra memory.

Example 1:

Given nums = [1,1,2],

Your function should return length = 2, with the first two elements of nums being 1 and 2 respectively.

It doesn't matter what you leave beyond the returned length.
Example 2:

Given nums = [0,0,1,1,1,2,2,3,3,4],

Your function should return length = 5, with the first five elements of nums being modified to 0, 1, 2, 3, and 4 respectively.

It doesn't matter what values are set beyond the returned length.
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-4 05:47:02 | 只看该作者
全局:
这题比较奇葩,居然是在现有数组上面修改。
回复

使用道具 举报

🔗
 楼主| ttgao 2019-7-4 14:06:37 | 只看该作者
全局:
6. ZigZag Conversion

The string "PAYPALISHIRING" is written in a zigzag pattern on a given number of rows like this: (you may want to display this pattern in a fixed font for better legibility)

P   A   H   N
A P L S I I G
Y   I   R
And then read line by line: "PAHNAPLSIIGYIR"

Write the code that will take a string and make this conversion given a number of rows:

string convert(string s, int numRows);
Example 1:

Input: s = "PAYPALISHIRING", numRows = 3
Output: "PAHNAPLSIIGYIR"
Example 2:

Input: s = "PAYPALISHIRING", numRows = 4
Output: "PINALSIGYAHRPI"
Explanation:

P     I    N
A   L S  I G
Y A   H R
P     I
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 注册账号
隐私提醒:
  • ☑ 禁止发布广告,拉群,贴个人联系方式:找人请去🔗同学同事飞友,拉群请去🔗拉群结伴,广告请去🔗跳蚤市场,和 🔗租房广告|找室友
  • ☑ 论坛内容在发帖 30 分钟内可以编辑,过后则不能删帖。为防止被骚扰甚至人肉,不要公开留微信等联系方式,如有需求请以论坛私信方式发送。
  • ☑ 干货版块可免费使用 🔗超级匿名:面经(美国面经、中国面经、数科面经、PM面经),抖包袱(美国、中国)和录取汇报、定位选校版
  • ☑ 查阅全站 🔗各种匿名方法

本版积分规则

>
快速回复 返回顶部 返回列表