首页 > 其他分享 >leetcode-744-easy

leetcode-744-easy

时间:2023-03-31 20:14:35浏览次数:36  
标签:letters target character lexicographically char easy 744 leetcode greater

Find Smallest Letter Greater Than Target

You are given an array of characters letters that is sorted in non-decreasing order, and a character target. There are at least two different characters in letters.

Return the smallest character in letters that is lexicographically greater than target. If such a character does not exist, return the first character in letters.

Example 1:

Input: letters = ["c","f","j"], target = "a"
Output: "c"
Explanation: The smallest character that is lexicographically greater than 'a' in letters is 'c'.
Example 2:

Input: letters = ["c","f","j"], target = "c"
Output: "f"
Explanation: The smallest character that is lexicographically greater than 'c' in letters is 'f'.
Example 3:

Input: letters = ["x","x","y","y"], target = "z"
Output: "x"
Explanation: There are no characters in letters that is lexicographically greater than 'z' so we return letters[0].
Constraints:

2 <= letters.length <= 104
letters[i] is a lowercase English letter.
letters is sorted in non-decreasing order.
letters contains at least two different characters.
target is a lowercase English letter.
Related Topics
数组
二分查找

思路一:直接遍历

    public char nextGreatestLetter(char[] letters, char target) {
        for (char letter : letters) {
            if (letter > target) {
                return letter;
            }
        }

        return letters[0];
    }

标签:letters,target,character,lexicographically,char,easy,744,leetcode,greater
From: https://www.cnblogs.com/iyiluo/p/17277356.html

相关文章

  • leetcode-762-easy
    PrimeNumberofSetBitsinBinaryRepresentationGiventwointegersleftandright,returnthecountofnumbersintheinclusiverange[left,right]havingaprimenumberofsetbitsintheirbinaryrepresentation.Recallthatthenumberofsetbitsan......
  • Leetcode Practice --- 栈和队列
    目录155.最小栈思路解析20.有效的括号思路解析1047.删除字符串中的所有相邻重复项思路解析1209.删除字符串中的所有相邻重复项II思路解析删除字符串中出现次数>=2次的相邻字符剑指Offer09.用两个栈实现队列239.滑动窗口最大值思路解析155.最小栈设计一个支持push......
  • LeetCode 100 相同的树
    LeetCode|100.相同的树给你两棵二叉树的根节点p和q,编写一个函数来检验这两棵树是否相同。如果两个树在结构上相同,并且节点具有相同的值,则认为它们是相同的。示例1:输入:p=[1,2,3],q=[1,2,3]输出:true示例2:输入:p=[1,2],q=[1,null,2]输出:false示例3:输入:p......
  • LeetCode 94 二叉树的中序遍历
    LeetCode|94.二叉树的中序遍历给定一个二叉树的根节点root,返回它的中序 遍历。示例1:输入:root=[1,null,2,3]输出:[1,3,2]示例2:输入:root=[]输出:[]示例3:输入:root=[1]输出:[1]提示:树中节点数目在范围[0,100]内-100<=Node.val<=100迭代实现:......
  • 双网卡设备通过HIKSDK接入EasyCVR平台显示离线是什么原因?
    EasyCVR视频融合平台基于云边端协同架构,具有强大的数据接入、处理及分发能力,平台支持海量视频汇聚管理,可支持多协议接入,包括市场主流标准协议与厂家私有协议及SDK,如:国标GB28181、RTMP、RTSP/Onvif、海康Ehome、海康SDK、宇视SDK等(具体见下图)。平台能在复杂的网络环境中,将分散的各......
  • 华为NVR设备接入EasyCVR视频融合平台后不显示摄像头的问题排查与解决
    在上期的文章中,我们和大家分享了关于EasyCVR平台与华为IVS3800平台的对接相关经验分享,感兴趣的用户可以翻阅我们往期的文章进行查看。今天我们来分享一下华为NVR设备接入平台后不显示摄像头的问题排查与解决。在EasyCVR对接华为NVR设备的过程中,通常是使用国标GB28181协议,但是有......
  • AI视频智能分析平台EasyCVR设备录像功能细节优化
    EasyCVR视频融合平台基于云边端一体化架构,具有强大的数据接入、处理及分发能力,平台支持海量视频汇聚管理,可支持多协议接入,包括市场主流标准协议与厂家私有协议及SDK,如:国标GB28181、RTMP、RTSP/Onvif、海康Ehome、海康SDK、宇视SDK等(具体见下图)。平台丰富的视频能力包括:视频监控直......
  • 反转链表-leetcode92
    给你单链表的头指针head和两个整数left和right,其中left<=right。请你反转从位置left到位置right的链表节点,返回反转后的链表。示例1:输入:head=[1,2,3,4,5],left=2,right=4输出:[1,4,3,2,5]示例2:输入:head=[5],left=1,right=1输出:[5]//leet......
  • Java中使用EasyExcel生成Excel文件
    使用Spring框架中的@ExcelProperty注解生成Excel文件需要借助于第三方库,比如EasyExcel或ApachePOI等。首先定义实体类,例如publicclassUser{@ExcelProperty(value="姓名",index=0)privateStringname;@ExcelProperty(value="年龄",index=1)priva......
  • Leetcode19. 删除链表的倒数第 N 个结点
     19. 删除链表的倒数第N个结点自己纯手写第一题,递归有点冗杂,开辟了虚拟头节点,而且要特别注意边界条件(当倒数第n个正好是头节点时)。***Definitionforsingly-linkedlist.*structListNode{*intval;*ListNode*next;*ListNode():val(0),n......