leetcode 387. 字符串中的第一個唯一字符(hash)

給定一個字符串,找到它的第一個不重復的字符,并返回它的索引。如果不存在,則返回 -1。

示例:

s = “leetcode”
返回 0

s = “loveleetcode”
返回 2
class Solution {
public int firstUniqChar(String s) {

int[][] temp=new int[26][2];
int n=s.length();
for(int i=0;i<n;i++){//記錄字母出現的次數喝最后一次出現位置temp[s.charAt(i)-'a'][0]++;temp[s.charAt(i)-'a'][1]=i;
}
int res=Integer.MAX_VALUE;
for(int i=0;i<26;i++)if(temp[i][0]==1)//找出只出現一次的字母中,最小的位置{res= Math.min(temp[i][1],res);}
return res==Integer.MAX_VALUE?-1:res;
}

}

本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/392443.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/392443.shtml
英文地址,請注明出處:http://en.pswp.cn/news/392443.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

marlin 三角洲_三角洲湖泊和數據湖泊-入門

marlin 三角洲Data lakes are becoming adopted in more and more companies seeking for efficient storage of their assets. The theory behind it is quite simple, in contrast to the industry standard data warehouse. To conclude this this post explains the logica…

tomcat中設置Java 客戶端程序的http(https)訪問代理

1、假定http/https代理服務器為 127.0.0.1 端口為8118 2、在tomcat/bin/catalina.sh腳本文件中設置JAVA_OPTS&#xff0c;如下圖&#xff1a; 保存后重啟tomcat就能生效。轉載于:https://www.cnblogs.com/zhangmingcheng/p/11211776.html

java界面中顯示圖片_java中怎樣在界面中顯示圖片?

方法一&#xff1a;JLabel helloLabel new JLabel("New label");helloLabel.setIcon(new ImageIcon("E:\\javaSE\u4EE3\u7801\\TimeManager\\asset\\hello.gif"));helloLabel.setBackground(Color.BLACK);helloLabel.setBounds(0, 0, 105, 50);contentPan…

one-of-k 編碼算法_我們如何教K-12學生如何編碼

one-of-k 編碼算法by Christopher George克里斯托弗喬治(Christopher George) 我們如何教K-12學生如何編碼 (How we’re teaching K-12 students how to code) Hello World! (Sorry, I couldn’t resist.) My name is Christopher George and I am currently a Junior at Carn…

knime簡介_KNIME簡介

knime簡介Data Science is abounding. It considers different realms of the data world including its preparation, cleaning, modeling, and whatnot. To be precise, it is massive in terms of the span it covers and the opportunities it offers. Needless to say, th…

hadoop2.x HDFS快照介紹

說明&#xff1a;由于近期正好在研究hadoop的快照機制。看官網上的文檔講的非常仔細。就順手翻譯了。也沒有去深究一些名詞的標準譯法&#xff0c;所以可能有些翻譯和使用方法不是非常正確&#xff0c;莫要介意~~ 原文地址&#xff1a;&#xff08;Apache hadoop的官方文檔&…

MQTT服務器搭建--Mosquitto用戶名密碼配置

前言&#xff1a; 基于Mosquitto服務器已經搭建成功&#xff0c;大部分都是采用默認的是允許匿名用戶登錄模式&#xff0c;正式上線的系統需要進行用戶認證。 1.用戶參數說明 Mosquitto服務器的配置文件為/etc/mosquitto/mosquitto.conf&#xff0c;關于用戶認證的方式和讀取的…

java number string_java基礎系列(一):Number,Character和String類及操作

這篇文章總結了Java中最基礎的類以及常用的方法&#xff0c;主要有&#xff1a;Number&#xff0c;Character&#xff0c;String。1、Number類在實際開發的過程中&#xff0c;常常會用到需要使用對象而不是內置的數據類型的情形。所以&#xff0c;java語言為每個內置數據類型都…

誰參加了JavaScript 2018狀況調查?

by Sacha Greif由Sacha Greif 誰參加了JavaScript 2018狀況調查&#xff1f; (Who Took the State of JavaScript 2018 Survey?) 我們如何努力使調查更具代表性 (How we’re working to make the survey more representative) I was recently listening to a podcast episode…

機器學習 建立模型_建立生產的機器學習系統

機器學習 建立模型When businesses plan to start incorporating machine learning to enhance their solutions, they more often than not think that it is mostly about algorithms and analytics. Most of the blogs/training on the matter also only talk about taking …

CDH使用秘籍(一):Cloudera Manager和Managed Service的數據庫

背景從業務發展需求&#xff0c;大數據平臺須要使用spark作為機器學習、數據挖掘、實時計算等工作&#xff0c;所以決定使用Cloudera Manager5.2.0版本號和CDH5。曾經搭建過Cloudera Manager4.8.2和CDH4&#xff0c;在搭建Cloudera Manager5.2.0版本號的時候&#xff0c;發現對…

leetcode 455. 分發餅干(貪心算法)

假設你是一位很棒的家長&#xff0c;想要給你的孩子們一些小餅干。但是&#xff0c;每個孩子最多只能給一塊餅干。 對每個孩子 i&#xff0c;都有一個胃口值 g[i]&#xff0c;這是能讓孩子們滿足胃口的餅干的最小尺寸&#xff1b;并且每塊餅干 j&#xff0c;都有一個尺寸 s[j]…

壓縮/批量壓縮/合并js文件

寫在前面 如果文件少的話&#xff0c;直接去網站轉化一下就行。 http://tool.oschina.net/jscompress?type3 1.壓縮單個js文件 cnpm install uglify-js -g 安裝 1>壓縮單個js文件打開cmd,目錄引到當前文件夾&#xff0c;cduglifyjs inet.js -o inet-min.js 或者 uglifyjs i…

angular依賴注入_Angular依賴注入簡介

angular依賴注入by Neeraj Dana由Neeraj Dana In this article, we will see how the dependency injection of Angular works internally. Suppose we have a component named appcomponent which has a basic and simple structure as follows:在本文中&#xff0c;我們將看…

leetcode 85. 最大矩形(dp)

給定一個僅包含 0 和 1 、大小為 rows x cols 的二維二進制矩陣&#xff0c;找出只包含 1 的最大矩形&#xff0c;并返回其面積。 示例 1&#xff1a; 輸入&#xff1a;matrix [[“1”,“0”,“1”,“0”,“0”],[“1”,“0”,“1”,“1”,“1”],[“1”,“1”,“1”,“1”,“…

如何查看系統版本

1. winR,輸入cmd&#xff0c;確定&#xff0c;打開命令窗口&#xff0c;輸入msinfo32&#xff0c;注意要在英文狀態下輸入&#xff0c;回車。然后在彈出的窗口中就可以看到系統的具體版本號了。 2.winR,輸入cmd&#xff0c;確定&#xff0c;打開命令窗口&#xff0c;輸入ver&am…

java activemq jmx_通過JMX 獲取Activemq 隊列信息

首先在 activemq.xml 中新增以下屬性在broker 節點新增屬性 useJmx"true"在managementContext 節點配置斷開與訪問服務iP配置成功后啟動下面來看測試代碼/*** Title: ActivemqTest.java* Package activemq* Description: TODO(用一句話描述該文件做什么)* author LYL…

風能matlab仿真_發現潛力:使用計算機視覺對可再生風能發電場的主要區域進行分類(第1部分)

風能matlab仿真Github Repo: https://github.com/codeamt/WindFarmSpotterGithub回購&#xff1a; https : //github.com/codeamt/WindFarmSpotter This is a series:這是一個系列&#xff1a; Part 1: A Brief Introduction on Leveraging Edge Devices and Embedded AI to …

【Leetcode_easy】821. Shortest Distance to a Character

problem 821. Shortest Distance to a Character 參考 1. Leetcode_easy_821. Shortest Distance to a Character; 完轉載于:https://www.cnblogs.com/happyamyhope/p/11214805.html

tdd測試驅動開發課程介紹_測試驅動開發的實用介紹

tdd測試驅動開發課程介紹by Luca Piccinelli通過盧卡皮奇內利 測試驅動開發很難&#xff01; 這是不為人知的事實。 (Test Driven Development is hard! This is the untold truth about it.) These days you read a ton of articles about all the advantages of doing Test …